Freigeben über


C++ or C# to get started?

TexBlog reader Gordon writes:
"I just got VS 2005 C++ Express. I have been looking for comprehensive examples of C++ code and it seems to me there are a great many more C# examples. This is making me wonder if C# isn't a better choice for someone getting started."

Thanks for downloading the Express Editions!

Setting the issue of examples aside for a moment, which language you want to get started with depends mostly on what kinds of software you wish to write.  If you want to write native code Windows apps, platform-neutral native code, learn the Win32 API, or learn how to interop between native and managed code, then C++ is your best choice.  If you want to write managed code applications or want to take the most productive path to writing Windows programs and learning .NET, then C# is probably a better choice.  These recommendations assume, of course, that you don't have a particular language affinity; if you are already familiar with and enjoy one language or the other, or if you really want to learn one language or the other, then that should factor into your decision as well.

Now, about samples...  The samples "in the box" are but a small, small portion of the total samples available to you.  For example, you'll find a lot of C++-based native Windows examples in the Platform SDK.  We also have some VC++ 2003 samples available for download (although these may require a little tweaking to get working with VC++ 2005).  For C#, you'll find a number of examples (although I think they're for .NET 1.1 and could possibly need a bit of tweaking) on MSDN and sites like GotDotNet.  You'll also find a ton of example by simply surfing the web and doing keyword searches for whatever kind of examples you'd like to see.

So, in a nutshell, what I'm trying to say is that there are plenty of examples out there for all languages, so don't let "in the box" examples be your primary determining factor for what language you choose.

Comments

  • Anonymous
    November 16, 2005
    The comment has been removed
  • Anonymous
    November 16, 2005
    >> If you want to write managed code applications or want to take the most productive path to writing Windows programs and learning .NET, then C# is probably a better choice. <<

    I personally believe that C++/CLI is a First class CLI language, and can be used to write pure managed applications with as much (if not more) effectiveness as any other CLI language; so it's a little disappointing to hear the Director of Partner Strategy for VC++ say that C# is a better choice!
  • Anonymous
    November 16, 2005
    Thanks for the comments, all.

    Travis: I purposely limited the discussion to C++ or C#, since that was the question at hand. I also kind of assumed that the original question was posed by a professional developer so that I didn't have delve into the various educational trade-offs of languages that are such a big issue in the academic world. Regarding multi-platform code, note that I said "platform neutral native code," for which there are few options better than C/C++.

    Nishant: I wholeheartedly agree that C++/CLI is indeed a first class .NET language. However, unless you're already an experienced C++ developer, I believe C# has a shallower learning curve for new .NET developers. Based on Gordon's original question, I made the (arguable) assumption that he wasn't already a C++ expert. C# is a much simpler language, and the solution set for a given problem tends to be much smaller in C# since there tend to be many more way to "skin the cat" in C++. VC++ is more powerful, supports multiple programming paradigms, usually produces faster executing code, has brilliant native-managed interop, but - we have to be honest here - it's more complicated than C#.

    I appreciate your honesty in expressing your disappointment that the Director of Partner Strategy for VC++ would recommend other languages in certain scenarios. I can understand that, but I also hope you will appreciate that I'm a pragmatic person. My blog is about expressing my honest opinions, and I'm not here to "spin" anyone. And you won't catch me engaged in programming language holy wars. All languages have their strengths and weaknesses.

    Heck, even Bjarne Stroustrup said last week that his desire was for C++ to be second best at everything. Indeed, C++ is the best general purpose programming language on the planet, but it's not always the best language for solving any one specific problem.
  • Anonymous
    November 16, 2005
    Good points, Steve. I do agree with your "C# is probably easier to learn for a new developer than C++" stance.

    What I disagree with is your "want to write managed code applications" stance. For an experienced C++ developer, there is no real reason to use C# or any other language to write purely managed apps.

    Again, I really appreciate the fact that you intend to be honest here rather than give us the usual my-company-is-best-our-products-rock propaganda :-)

    Regards,
    Nish
  • Anonymous
    November 17, 2005
    I keep hearing that C++/CLI is a first-class CLI language, but does it in fact occupy the same elevated status for .NET development as the C#/VB.NET language (which I count as one, since it's largely the same language with 2 different syntaxes)? For instance, to work with the Visual Studio Tools for Office you will have to use C#/VB. What about Web Forms, Indigo/WCF, etc.?

    The original question was about sample code - just check out all the MSDN documentation for .NET (version 1, as well as Vista's pre-beta eye-candy) and see how many examples are given in C++ vs. how many in C#/VB. Go to the MS Press site and see what books are coming out on .NET v2, WPF, WCF, etc. (to say nothing of the books about the languages themselves!) and see what MS authors expect .NET programmers to use.

    For all the talk about .NET's being language-neutral, it appears that some languages' CLR is more equal than others. C++ is still treated mainly as an interop tool with .COM rather than a truly first-rate vehicle for building pure .NET apps, it seems to me. Or am I missing something? I surely hope so, because using the same language for both managed and unmanaged code is certainly an appealing prospect.

    Sorry for the rant!
  • Anonymous
    April 21, 2006
    To get started, obviously I'd prefer C#. VB .NET code isn't that different as you couldn't learn from it, so I got a couple of VB books that I use for C# stuff and a couple of C#, C++, Java books that I use for VB stuff. But at some point, it goes down to unmanaged C++. I simply don't have the courage to tell users to download a 20-something runtime to be able to run a 1-meg program. This is the biggest nuisance about .NET. You can't run it just like that on other operating systems, which is a pain in the %¨&*. But apart from that, .NET is okay - but not that okay that I could leave the C++ world anytime soon.
  • Anonymous
    June 26, 2006
    Guys, C# is easier for absolute beginners. I know because I am an absolute beginner. The immensity of C++ and the stupid stupid new old ancient classifications and standardizations just make it so hard for me to decide to start with C++. C# is very easy, and very human eye friendly, not to mention the great tutorials and videos from learnvisualstudio.com provided free on the Easy to Learn on the C# express edition. If you are simply a hobbyist who would like to know how to simply and easily develope small applications C# is obviously the choice. I tried learning C++ I really did, but ultimately I gave up because it was such a heavy language to learn on my spare time, mind you I program for FUN not for productivity or business applications. I am changing my major to Computer Science, so I'm sure I'll end up using both, but I know that C# will always be my choice for my personal hobby programming. I like C# they did a good job on it, yeah its "limited" compared to C++ but you guys are speaking from the point of "lifetime" developers who have been there while it was evolving. If Gordon wants to make it a hobby and wants to learn just for fun, C# is his choice in my opinion, because like Visual Basic there seems to be a huge ammount of "For absolute beginners" type tutorials and learning resources. You have to remember your audience. It's like saying, would you recomend to someone who wants to be bilingual in any spoken language asap, would you pick latin, or spanish? I'd definately recomend spanish, as there is a heck of a lot more learning resources geared to learn Spanish quickly. Yes I just contrasted a relatively new language with an ancient language, and yes I am infering C# is new and easy and C++ is ancient and difficult ;) deal with it.
  • Anonymous
    August 07, 2006
    To tell you the truth, I knew some what knowledge of C++ and I have to say that it is kind of difficult to switch. I just can't seem to adapt, and I am also wondering, to stick with C++ or move over to C#.