C# to C++ Migration Difficulty?  
Author Message
mts2325





PostPosted: Visual C# Language, C# to C++ Migration Difficulty? Top

I am currently learning C# mainly for the interests of learning an object orientated language early (I'm only 15), but also since the announcement that XNA games can be made for the Xbox 360 I'm interested in that as well. Since the games industry uses C++ in their games and I'm aiming for a career in either video game programming or just programming in general, how easy is it to adapt to C++ from C#, Or are there no significant changes in structure, syntax etc


Visual C#15  
 
 
Mark Benningfield





PostPosted: Visual C# Language, C# to C++ Migration Difficulty? Top

Hello All.

mts2325:

Well, the short answer is : Not nearly as easy as going the other way!

Going from C++ to C#, there are quite a few things that you don't have to worry about anymore. Conversely, going from C# to C++, there are a lot of things that you have to worry about that you didn't have to before, mainly concerning memory and resource management.

The best advice I can give you is to learn the right way to do it, and then stick with it. Don't try and get cute, because it will usually work often enough to lead you into a briar patch.

Now, having said that, C++ coding can be very satisfying, because when it's clean, concise, and well-managed, it really smokes! Depending on which compiler you use, the "well-managed" part can be the tricky part. Hence the advent of managed code.

From the standpoint of structure / syntax, -- again, depending on the compiler -- you can do a few more things in C++ than in C#. You can do a lot of useful things with a stick of dynamite, too. Whether the situtation calls for that particular tool or not is a much more relevant question.

I say, have no fear, but plenty of respect.

HTH.



 
 
Dennis Stone - MSFT





PostPosted: Visual C# Language, C# to C++ Migration Difficulty? Top

I learned them in that order, C# then C++, (not that I'm an expert C++ programmer at this point by any means) and I have to say that in my experience the most difficult part was dealing with strings in general. Especially in the win32 api, every time I needed to use a function for the first time it seemed it took yet another string type that I hadn't seen before. Figuring out how to convert between the string types, and what to use in each situation was fairly painful. But, I can't really say that learning pain was necessarily caused by the fact that I learned C# first, I think you'll experience it either way, although it was probably a bit more painful just knowing that if I was doing the same thing in C# I would have a single string type to deal with.

Dealing with memory management was the other most difficult part of the transition for me, but again, I don't think this was necessarily made more difficult by the fact that I learned C# first.

If you're ultimate goal is to learn C++ then there's no time like the present. It's a difficult language to master and will take just about anyone a significant amount of time spent programming in it to claim any kind of expertise, so you might as well get started now rather than going to C# first. On the other hand, if you're just a hobbyist looking to make a few small applications or games then you'll probably have more fun using C#.

Just my 2 cents, Dennis.



 
 
David Turner





PostPosted: Visual C# Language, C# to C++ Migration Difficulty? Top

It is possible to write idiomatic C# code in managed C++, however the reverse is not true. What's more, if you're going to write "C# code" in C++, you're wasting your time - C# is much better for that. Therefore, if you plan to learn C++, you must set about learning C++ idioms. Your C# knowledge will not help you there; if anything it will make the job a lot more difficult ("Oh, that doesn't work how I expected!").

My suggestion, then, is that you start off with non-managed C++. Buy anything written by Bjarne Stroustrup, Alexander Alexandrescu, Herb Sutter, or Scott Meyers. Do not attempt to read anything with a shiny cover or with "...for Dummies" written on the cover. Visit http://www.gotw.ca, http://www.boost.org . Learn to use and love the STL (standard template library). Pay careful attention to how auto_ptr and boost's shared_ptr work, it will teach you a huge amount about the language.

Learning C++ takes a long, long time. But it's worth it.