Which should I learn: C, C++, or C#?

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 45256 Views - Last Post: 14 December 2012 - 02:47 AM

#1 xor-logic  Icon User is offline

  • HAL9000 was an Apple product
  • member icon

Reputation: 128
  • View blog
  • Posts: 764
  • Joined: 04-February 10

Which should I learn: C, C++, or C#?

Posted 17 May 2012 - 08:41 AM

I am considering a switch from programming in Java to either C, C++ or C#.

Originally, I learned Java due to the whole portability idea - write once, run anywhere and whatnot.

But as time goes on, I realize that this is largely meaningless for me, since my programs really never get run anywhere but on my own machine. So I'm wondering if I wouldn't be better programming with a language that gives me more direct (low-level) control over the things that my machine specifically can do.

I looked at C#, but I'm not sure it's not as abstracted as Java.

Is C# just the new C++ (I'm guessing not, but the similarity in names gives me pause)? Or is it another language altogether?

Which language would you recommend, knowing that my goal is to have expanded control over the specifics of my system and machine, coming from Java?

Is This A Good Question/Topic? 0
  • +

Replies To: Which should I learn: C, C++, or C#?

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7561
  • View blog
  • Posts: 12,678
  • Joined: 19-March 11

Re: Which should I learn: C, C++, or C#?

Posted 17 May 2012 - 08:49 AM

C or C++ would give you more direct control of the machine. C# targets a virtual machine, like Java, so I think it's not really what you're looking for.

Your requirements are pretty vague, though, so you're not going to get much more than vague answers (and some spurious precision, ie, "You should absolutely use my favorite language, because it's the awesomest!")

The two pieces of advice I'd give you: First, start in on straight C, without any of the C++ extensions, and learn that before adding in the C++ part. Get the meat before you get the (syntactic) sugar.

Second: expand your goals. Writing programs to just run on your machine seems awfully limiting. Wouldn't it be a little bit fun to write stuff that other people could use?
Was This Post Helpful? 1
  • +
  • -

#3 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2085
  • View blog
  • Posts: 3,170
  • Joined: 21-June 11

Re: Which should I learn: C, C++, or C#?

Posted 17 May 2012 - 08:49 AM

What kind of direct control are you looking for? I'm not entirely sure what you mean by that.

Regarding the link between C# and C++: C# is not the new C++. It's an entirely new language that is somewhat inspired by C++ (just like Java). In terms of abstraction it's not very different from Java. C#'s design goal is basically to be the better Java. So if you want to go lower level, C# wouldn't be the way to go.
Was This Post Helpful? 1
  • +
  • -

#4 xor-logic  Icon User is offline

  • HAL9000 was an Apple product
  • member icon

Reputation: 128
  • View blog
  • Posts: 764
  • Joined: 04-February 10

Re: Which should I learn: C, C++, or C#?

Posted 17 May 2012 - 09:38 AM

View Postjon.kiparsky, on 17 May 2012 - 03:49 PM, said:

C# targets a virtual machine, like Java, so I think it's not really what you're looking for.

Your requirements are pretty vague, though, so you're not going to get much more than vague answers (and some spurious precision, ie, "You should absolutely use my favorite language, because it's the awesomest!")

Thanks. I'm trying to get away from interpreted languages, so you're right that that wouldn't be what I'm looking for.

View Postjon.kiparsky, on 17 May 2012 - 03:49 PM, said:

Second: expand your goals. Writing programs to just run on your machine seems awfully limiting. Wouldn't it be a little bit fun to write stuff that other people could use?

It would be. I wrote a full-fledged study program once that got reviewed at 5/5, but no one ever used it.

But nowadays, the odds that I would have the inspiration, the capabilities, or the time to write anything for mass consumption that would be best served in anything but a web browser are so tiny that it really shouldn't enter into my considerations.

Quote

C#'s design goal is basically to be the better Java.

Ok, I'm officially not considering C# anymore. :D
Was This Post Helpful? 0
  • +
  • -

#5 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2085
  • View blog
  • Posts: 3,170
  • Joined: 21-June 11

Re: Which should I learn: C, C++, or C#?

Posted 17 May 2012 - 09:53 AM

View Postxor-logic, on 17 May 2012 - 06:38 PM, said:

Thanks. I'm trying to get away from interpreted languages, so you're right that that wouldn't be what I'm looking for.


You still haven't explained why though. I'm not one to discourage people from leaving Java, but I still have no idea what you're missing in Java.

I mean, it's your business of course. I'm just wondering.

PS: There's a big difference between JIT compilation and interpretation.

This post has been edited by sepp2k: 17 May 2012 - 09:53 AM

Was This Post Helpful? 2
  • +
  • -

#6 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7561
  • View blog
  • Posts: 12,678
  • Joined: 19-March 11

Re: Which should I learn: C, C++, or C#?

Posted 17 May 2012 - 11:00 AM

View Postsepp2k, on 17 May 2012 - 11:53 AM, said:

PS: There's a big difference between JIT compilation and interpretation.


QFT.

Java is compiled, and runs on a virtual machine. This allows for all of the advantages of compilation, the only limitations are those of the virtual machine, which in terms of performance are minimal today. The ability to operate directly on the machine is limited in Java, but that's a good thing. We like high-level languages for applications programming.

It's good to learn new languages, and C is a good one to learn, but let's not hang on to old and outdated misconceptions about Java.
Was This Post Helpful? 1
  • +
  • -

#7 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Which should I learn: C, C++, or C#?

Posted 17 May 2012 - 05:31 PM

Quote

First, start in on straight C, without any of the C++ extensions, and learn that before adding in the C++ part. Get the meat before you get the (syntactic) sugar.


I'm pretty admittedly against that. C++ is SOOOOOOOOOO much more than sugar for C. pick C or C++ and learn it as its own language. I prefer C++, C makes me work too hard to do common tasks without gain.

if you're interested in learning a lower level languge, C and C++ are good choices. pick 1 or the other. if you pick both then treat them as separate languages.

jon: the performance difference between native and virtual machine code is only minimal becuase of JIT compiling(which converts virtual machine code to native code). also, why are you defending Java when no one attacked it?

This post has been edited by ishkabible: 17 May 2012 - 05:36 PM

Was This Post Helpful? 2
  • +
  • -

#8 xor-logic  Icon User is offline

  • HAL9000 was an Apple product
  • member icon

Reputation: 128
  • View blog
  • Posts: 764
  • Joined: 04-February 10

Re: Which should I learn: C, C++, or C#?

Posted 17 May 2012 - 11:34 PM

People seem to want me to enumerate all the specific benefits I expect to reap from a switch to a lower level language; the fact is I don't have anything but a vague conception of the benefits I'm looking for, the same as when I chose Java in the first place. In lieu of portability, which doesn't do much for me, I simply think I'd like more control.

I'm not dissing Java; I'm quite fond of it actually, as it's almost the first language I learned.

Technically the first was C++, but that was over a decade ago in a high school programming class, and by the end of the school year, the teacher hadn't taught us to make anything other than simply text-based, largely procedural programs that could be accomplished with a couple hundred lines, at the most. Since then, I've forgotten (I think) everything I knew about C++.

At the moment, after reading all the input here, I'm leaning towards learning C++. Would there be any benefit to learning C instead?
Was This Post Helpful? 0
  • +
  • -

#9 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,682
  • Joined: 13-March 10

Re: Which should I learn: C, C++, or C#?

Posted 18 May 2012 - 05:44 AM

No. Learn all of them. Not that hard if you know Java.
Was This Post Helpful? 0
  • +
  • -

#10 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: Which should I learn: C, C++, or C#?

Posted 18 May 2012 - 07:49 AM

Don't put C, C++ and C# in the same bag.
C# is more Java alike, except from some C# 'sauce' and all .NET stuff.

If you wanna really go low I suggest you to pick C/C++. I don't know if you should start with pure C then C++ or just C++ right away, put you definitely should know well their difference.
Was This Post Helpful? 0
  • +
  • -

#11 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2085
  • View blog
  • Posts: 3,170
  • Joined: 21-June 11

Re: Which should I learn: C, C++, or C#?

Posted 18 May 2012 - 08:17 AM

View Postxor-logic, on 18 May 2012 - 08:34 AM, said:

People seem to want me to enumerate all the specific benefits I expect to reap from a switch to a lower level language


One example would suffice.

Quote

the fact is I don't have anything but a vague conception of the benefits I'm looking for, the same as when I chose Java in the first place. In lieu of portability, which doesn't do much for me, I simply think I'd like more control.


Yes, but at least portability has a clear meaning. "more control" doesn't. It could mean many things and there's a very big chance that the control you get from low level languages isn't actually the kind of control you're looking for. It's not like I'm trying to attack your choice to go lower level or even dissuade you from doing so. I just want to make sure you aren't looking/hoping for something that you're not actually going to get from C++ (or that you could as well get from C#/C++).

You also should ask yourself whether the kind of control you want to have is lacking from Java because it's a high level language or because it eschews any form of platform specificity. For example if you want more control over where memory is allocated and when it will be freed, you need a lower level language like C or C++. However that isn't something that people want just because. Usually people want that kind of control because they worry about performance. If that's the case with you, you should first ask yourself whether Java (which really has quite decent performance for the majority of use cases (excluding any use case that requires quick start up times)) is really too slow for you and whether any slowness you encounter is really a result of the language.

If however the kind of control you seek has more to do with being to able to call system specific APIs without fuss, the high-level/low-level distinction is a bit of a red herring. You can get that kind of control easily from high-level languages like C# (after all .net has been designed primarily with Windows in mind).

Anyway that's the reason I wanted you to be more specific about what you're looking for.
Was This Post Helpful? 2
  • +
  • -

#12 xor-logic  Icon User is offline

  • HAL9000 was an Apple product
  • member icon

Reputation: 128
  • View blog
  • Posts: 764
  • Joined: 04-February 10

Re: Which should I learn: C, C++, or C#?

Posted 18 May 2012 - 01:19 PM

View Postsepp2k, on 18 May 2012 - 03:17 PM, said:

If however the kind of control you seek has more to do with being to able to call system specific APIs without fuss, the high-level/low-level distinction is a bit of a red herring. You can get that kind of control easily from high-level languages like C# (after all .net has been designed primarily with Windows in mind).


This is more the area that was tickling my fancy, though I couldn't give any specific details of what I would need to do in this arena, or why. Just feel like it would be nice to be able to. In this respect, is C# equal to C++?
Was This Post Helpful? 0
  • +
  • -

#13 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2085
  • View blog
  • Posts: 3,170
  • Joined: 21-June 11

Re: Which should I learn: C, C++, or C#?

Posted 18 May 2012 - 02:18 PM

Well, I'm probably the wrong person to answer questions about Windows-specific programming, but it is my understanding that the .Net API covers most features you'd need for Windows programming. For cases where that does not suffice, it's possible to call the native APIs from .NET applications. Unlike Java C# has certain C++-compatibility features (like pointers and pinning objects in memory), that should make this less painful than it is in Java. Though since I don't have any personal experience in that regard, I'm basically just talking out of my ass.
Was This Post Helpful? 0
  • +
  • -

#14 xor-logic  Icon User is offline

  • HAL9000 was an Apple product
  • member icon

Reputation: 128
  • View blog
  • Posts: 764
  • Joined: 04-February 10

Re: Which should I learn: C, C++, or C#?

Posted 23 May 2012 - 01:59 AM

Thanks everyone for your advice. I ended up going with C++, and I got my hands on a compiler and a copy of C++ For Dummies.

Made it through the first chapters very quickly (a char is a char, an int is an int, etc), wrote some basic programs, and am now to the first part that seems completely foreign to me: pointers. Should be fun.

I'll be back if (when) I have any questions. ;)
Was This Post Helpful? 0
  • +
  • -

#15 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 650
  • View blog
  • Posts: 2,223
  • Joined: 31-December 10

Re: Which should I learn: C, C++, or C#?

Posted 26 May 2012 - 07:42 AM

I would suggest ditching the "C++ for Dummies". Here is a free e-book that basically covers C and C++: Thinking in C++. IMO, it is an excellent book that covers a lot of material. Once you're comfortable with the language, I would suggest getting "The C++ Programming Language: Special Edition" by Bjarne Stroustrup, the original designer of C++.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2