C++ vs. C vs. C#

Pages: 12
I am new to programming, and before I go on I would like to know whether C, C++, or C# would be better for me to learn. Thanks for the help!
In all honesty, it really depends on what you want to do. I won't say don't learn C because both C++ and C# will always contain C, but there is no reason to learn an old language where two better languages have been built on top of them.

I believe you may want to learn more about the separate languages before you make your decision:
C: http://en.wikipedia.org/wiki/C_(programming_language)
C#: http://en.wikipedia.org/wiki/C_Sharp_(programming_language)
C++: http://en.wikipedia.org/wiki/C%2B%2B

I left C++ last so that you can see all of the differences between them and why I believe C++ is the better language. I feel it's an extremely powerful language, much like the other two, but the amount of support that is behind C++ isn't really there for the other two. I do not like much of Microsoft's developments, and C# is no exception to that. One of my friends is a programmer that knows C# and designs a lot of Window applications for clients, but if I'm not mistaking, C# is a Window's only language.

C# is not a bad idea for WIN32 API programs, but there is nothing that I know of that C# can do but C++ can't, and C++ always has the options of being portable, which, again, IIRC, C# can only make Windows applications.
but there is nothing that I know of that C# can do but C++ can't

What about events? Even in C++11, the closest thing to events are infinite loops in seprate threads! And I belive there are al ot more stuff that C# can, but c++ can't, mostly related to microsoft programming.
C# also has that whole LINQ sublanguage, which, I think, makes it worth learning even if you don't use it.
Last edited on
What about events?
As soon as I saw C# Events I saw it was using the Platform SDK's SetEvent/WaitForSingleObject calls. Good luck porting that to some other environment.

That's exactly the sort of thing that shouldn't be in C++. But I could say the same for threads, but they've manage to weasle their way into the new standard. Whatever happened to using libraries to do the heavy lifting?
Last edited on
I spend about 8 months learning C, and as soon as the awkwardness of C++'s classes disappeared (took about a week), I will never go back to C unless I decide to write the next microsoft kernel :)
Every language has its pros and cons and has was pointed out, it depends on what you are wanting to do with them.
C is Math.C# Is Graphics.C++ Has More Features Than C
C# can be used on Windows, Linux and Mac OS X, so don't listen to people who say it's only for Windows, they're wrong: http://mono-project.com/Main_Page

C# is almost always going to be slower than the other two, but it also has lots of high-level features missing from C++ and especially C, as well as a much more complete standard library. If the standard library doesn't do something, you can usually find a C# library for it, and if not, it takes all of five minutes to create a wrapper class for a C or C++ library. C# is a lot better suited to applications that need to be developed quickly and big projects where organisation is important (I find organising code easier in C#) but where performance is less of a concern.

That's not to say you can't write high-performance software in C#. The Sims 3, for example, is partly written in C#. The way to do it is to write all the performance-intensive functions (particularly rendering code) in C and use something called P/Invoke to call the native code from within C#. That does have some overhead (The Sims 3 doesn't perform as well as it probably would had it been written in C++), but unless you're rendering 3D graphics or doing a lot of maths, you probably won't notice it. I'd also like to mention that IMO algorithm choice and implementation is far more important than the language. Pick the wrong algorithm or implement it badly (or worse, both), and it will be slow in any language. Another thing I think is worth mentioning is that a programmer who knows his language inside out will certainly produce faster code than one who doesn't, regardless of the languages. A lot of it is common sense, like not using a sorted list in C# if you don't need it to be sorted, or not type-casting the same object twice, but sometimes it's more subtle, like whether to use structs or classes (in C++ it doesn't matter (they're the same) and in C you don't have a choice (there are no classes), but in C# struct and class are subtly different. That's the kind of thing that can make the difference between fast and slow code. As a final word on performance, while native code usually executes faster by virtue of being native code, the C# runtime compiler (C# is compiled to an "intermediate language" which is then re-compiled into native code when the program is run so that you can use the same executable on different platforms) has a lot more information about the platform, so it can make much better optimisations than a C or C++ compiler can, because they don't have the advantage of knowing what platform they're running on.

To summarise:
- C# is not Windows-only.
- C# has a more complete standard library and you can use practically any C library in C# (like I said, though, there is a bit of overhead).
- C# is a bigger language, but IMO it's better designed than C++, and it has a lot of useful features that C++ and C don't have, as well as cleaner syntax.
- Algorithm choice and implementation is going to have a more profound effect on performance than which language you choose.

As for your question, my advice is to learn all three.
Last edited on
Last I knew mono-project still was buggy in *nix though. Need to look into that more to be honest.
C is Math.C# Is Graphics.C++ Has More Features Than C


How does C have more math than C# or C++?
closed account (1yR4jE8b)
C# is not Windows-only.

Mono is definitely not mature enough to be considered a drop-in replacement for the real .Net Framework.
C for math and operating systems
C++ for C with abstract programming, templates, etc.
C# for C++ in a VM environment (i.e. Microsoft's Java)
I've never had a problem with Mono. MonoDevelop sure is buggy, but I've never had a problem with Mono itself.

C# is a lot more (and less) than C++ in a VM, it's a totally different language. C#'s generics are a lot different than C++'s templates (better, IMO, although perhaps not as powerful). C#'s references are totally different. C# discourages the use of pointers (you have to mark your code as unsafe; this is an improvement over Java which simply doesn't let you use pointers at all). C# has reference and value types. C# has a foreach loop. C# doesn't allow functions to be outside of classes (although you can use static functions, and it's basically the same). C# has no static method variables (you have to use class variables instead). In C#, this is a reference and not a pointer. Everything in C# is derived from System.Object. C# has built-in events and anonymous functions, built-in thread synchronisation and a built-in query language (LINQ).
Last edited on
@chrisname - Did you work on Sims 3?
Haha, no, I've just read about it after it displayed an error message with a class name which was something like TheSims3.SomeNamespace.Actor, and for some reason that made me wonder if it was written in C#, so I google'd it. It is definitely partly written in C++ because the crash logs make mention of being compiled by MSVC++, but I think it's just the performance-critical sections that are written in C++.

Which reminds me, according to Wikipedia, the Sims 3 actually used Mono: http://en.wikipedia.org/wiki/Mono_%28software%29#Software_developed_with_Mono
It's also mentioned on the Mono website (which is probably where the Wikipedia article got it from): http://mono-project.com/Companies_Using_Mono

I don't know to what extent it used Mono/C#. It might even have used managed C++ (although I don't see what the point in that would be, since the only performance increase would be from removing the things that make C# good, and even then it wouldn't be very significant).
Ah, I see. I've seen a few games related post from yourself. Thought you might have been a dev working for the evil EA overlords.
No, I'm just a guy who reads a lot.
closed account (1yR4jE8b)
Maybe my info is a bit out of date regarding Mono, I do still sometimes have graphical glitches running Winforms apps in Ubuntu and Fedora which don't happen when I use .Net on Windows so that kindof turns me off from using Mono.
I do still sometimes have graphical glitches running Winforms apps in Ubuntu and Fedora which don't happen when I use .Net on Windows so that kindof turns me off from using Mono.

Do you know if those apps are using pure .net or if they're directly invoking the windows API to tweak their appearance? You can't blame mono if the apps are using platform specific features.
Pages: 12