Sign in to follow this  
KappaG3

What are the most important things that should make me consider moving to C++?

Recommended Posts

Hello, new user here.

I started to program in C# about a year ago, after having some random general knowledge. Well, things change over time and now I'm pretty confident about my amateur-ish skills in C#.
Lately, though, I'm considering moving to C++. Being used to VisualC# I downloaded its counterpart, Visual C++. Which is good, simple and powerful. Lacks intellisense, but I guess I can deal with it.

Anyway, what really made me consider this option was seeing actual C++ source code. All those "shortcut symbols", pointers and more control over the code were what caught my eye. I'm not entirely [i]sure[/i] about what I saw and am trying to code, and this is why I started the thread. Is C++ a viable (and better) option for amateur programmers or is it only useful to more experienced users?

On a related note, what would be a good library to make games in? I'm used to XNA, I think I can shift to something else though. I've heard that it all boils down to OpenGL vs DirectX.

Share this post


Link to post
Share on other sites
Thanks vertex, your answer pretty much covers all my questions.
Speaking of the resources you posted, thanks again. I'll surely look into SDL as I need to get familiar with 2D programming, but is it good if I need to use some 3D models? There's a project I want to realize with a friend (who is in the same situation as me, migrating from a managed language to c++) and it could work in 2D, but I was thinking of making it 3D to learn some more while performing almost every calculation on a 2D grid (Tower defense says enough?). Edited by KappaG3

Share this post


Link to post
Share on other sites
[quote]Speaking of the resources you posted, thanks again. I'll surely look into SDL as I need to get familiar with 2D programming, but is it good if I need to use some 3D models?[/quote]

SDL essentially wraps OpenGL to provide its graphics functionality so you could definitely mix the two. There's a sub set of calls in SDL that allow you to operate directly on the OpenGL context should you need to.

[quote]There's a project I want to realize with a friend (who is in the same situation as me, migrating from a managed language to c++) and it could work in 2D, but I was thinking of making it 3D to learn some more while performing almost every calculation on a 2D grid (Tower defense says enough?).[/quote]

I should warn you that adding a dimension sometimes complicates things severely. Instead of using sprite sheets for characters, for example, you're now skinning animated skeletons, applying textures to them, etc. If you're new to game programming in general, consider taking smaller steps first. If not, by all means, 2D is - mathematically - a subset of 3D so anything expressible in the lower-order dimension is expressible in the higher.

My opinion on the whole 2D/3D argument is that you should consider carefully what you're getting out of using the extra dimension versus what you're adding to your workload to pay for it. If the benefits are clearly there, then that's enough of an argument for. If not, that's enough of an argument against. In your case, I'm not sure you're going to get anything beyond the "cool" factor. Maybe I'm way off on that, but consider it in any case.

Share this post


Link to post
Share on other sites
Quick addendum: you might want to check out [url="http://sfml-dev.org/index.php"]SFML[/url] over SDL, I just stumbled across another thread where they were talking about it and it appears to be an object-oriented cousin of SDL.

Share this post


Link to post
Share on other sites
Yeah, it would be strictly related to the 'cool' factor, while being essentially a 2D game under most aspects. That's why I tought that making it 3D wouldn't be such a big deal, but I'll take my time to see and consider what I can do.

@Addendum: Even better, thanks again (again [img]http://public.gamedev.net//public/style_emoticons/default/ph34r.png[/img] )! Edited by KappaG3

Share this post


Link to post
Share on other sites
I won't comment on whether the move to C++ is wise or not ([size=2]I'm not experienced enough in multiple languages to make that call, I mostly just use C++ myself - it's the only language I know in-depth[/size]), but if you do make the move to C++, I'd suggest [url="http://sfml-dev.org/"]SFML[/url] as a good 2D library... and you can use it with OpenGL if you are going to make the move to 3D. SFML will setup the window and handle input, if you want to use OpenGL (OpenGL doesn't handle that stuff for you).

However, DirectX may be a better option overall - I'm not versed enough in the OpenGL vs DirectX debate... but I am familiar with the SDL vs SFML choice (being very experienced in both), and I'd recommend [url="http://sfml-dev.org/"]SFML[/url], but either one is a viable option.

Share this post


Link to post
Share on other sites
[quote name='apatriarca' timestamp='1347547594' post='4979735']
What are your objectives? Why do you want to move to the C++ language?
[/quote]
That's what I'm asking in this thread.
Why [i]should [/i]I move to it?

Anyway, I've already got enough replies to think that I'll just move to it. I prefer the syntax and it's good to know that I can do more than before, even if maybe I'll need those functions rarely. Edited by KappaG3

Share this post


Link to post
Share on other sites
[quote name='KappaG3' timestamp='1347554976' post='4979770']
That's what I'm asking in this thread.
Why should I move to it?
[/quote]

Do you have a bunch of existing code in C++ that's easy to reuse?
Is your team a pile of experienced C++ developers without much exposure to other things?
Does your target platform only support C++, but that's where the money is?
Did your boss/class demand you use it?

These are really the only reasons, given the headaches the language puts on you to use it.

Share this post


Link to post
Share on other sites
[quote name='KappaG3' timestamp='1347554976' post='4979770']
Why [i]should [/i]I move to it?

Anyway, I've already got enough replies to think that I'll just move to it. I prefer the syntax and it's good to know that I can do more than before, even if maybe I'll need those functions rarely.
[/quote]
First off, you shouldn't move to any language, add languages to your toolbox, change your favourite language but never leave a language behind.
As for reasons to learn C++ there is only 2 good ones in my opinion:

1) Because you have to. I.E it is the only language that can do what you need to do. (This mostly applies to embedded systems or consoles where the language options and system resources can be fairly limited (Allthough C++ is not an option on all platforms, it is however fairly commonly available)).
2) Because you want to learn the language. (It is a fairly good language to know simply because of how widely used it is, (The same goes for C#, Java, Python and a bunch of other languages).

In general it is better to learn languages before you are forced to learn them. (The game industry have fairly good control over their language choices though but if you end up as a consultant maintaining old custom systems for clients things can get very interesting)

Share this post


Link to post
Share on other sites
[quote]These are really the only reasons, given the headaches the language puts on you to use it.[/quote]

I don't know that "headaches" is the best word for it. C++ simply does things differently than C#. At the end of the day it's all the same to the machine, but sometimes it's worth getting closer to said machine to learn a little more about how it works. I'm pretty emphatic about the fact that my experience with C++ has made me a better developer in other languages. If the ultimate goal here is to learn something new, that should be plenty reason to consider C++, or Java, or Haskell, or any other language really.

Share this post


Link to post
Share on other sites
I'd agree with Telastyn, except for maybe adding "just for the sake of learning it" to the list. Keep in mind that going from C# to C++ you will generally see a massive reduction in productivity. This is even ignoring the time it will take to pick up C++. The only time I have seriously gone back to use C++ in the last 6 or so years is when someone paid me to - and they paid me by the hour.

Going from XNA to DirectX, you will see yet another massive reduction in productivity. This is not meant to discourage, but keep this in mind if your goal is to get a specific project finished, you will need to choose for yourself depending on what your goals are.

Share this post


Link to post
Share on other sites
[quote name='Telastyn' timestamp='1347561104' post='4979799']
[quote name='KappaG3' timestamp='1347554976' post='4979770']
That's what I'm asking in this thread.
Why should I move to it?
[/quote]

Do you have a bunch of existing code in C++ that's easy to reuse?
Is your team a pile of experienced C++ developers without much exposure to other things?
Does your target platform only support C++, but that's where the money is?
Did your boss/class demand you use it?

These are really the only reasons, given the headaches the language puts on you to use it.
[/quote]
Quote for truth.

Learning isn't a valid excuse to switch to C++, you can learn C++ on the side in the years to come (and it will take years).

Share this post


Link to post
Share on other sites
[quote name='Telastyn' timestamp='1347561104' post='4979799']
[quote name='KappaG3' timestamp='1347554976' post='4979770']
That's what I'm asking in this thread.
Why should I move to it?
[/quote]

Do you have a bunch of existing code in C++ that's easy to reuse?
Is your team a pile of experienced C++ developers without much exposure to other things?
Does your target platform only support C++, but that's where the money is?
Did your boss/class demand you use it?

These are really the only reasons, given the headaches the language puts on you to use it.
[/quote]

Pretty much this.

There are a few edge cases, but those are exactly that.

I would also be curious to know what C# prevented you from doing. I came to C# from C++ and rarely if ever found myself unable to express certain code adequately. There have been a handful of times I had to pInvoke native code, but interop is certainly one of C#'s strengths ( especially compared to JNI). There are certainly things you do differently between languages, but there are few things I can think of that you can't do in C# that you can in C++. Hell, you can even get remarkably implicit with memory management if for some bizarre reason you really want to.

I will say this... when moving back to C++ there are certainly things I miss. Linq, beautiful link, perhaps being one of the biggest. Although a sensible class library is certainly high up that list.

Share this post


Link to post
Share on other sites
If you wish to learn C++ go for it, dont abandon C# though, both languages work very nicely together. No one can tell you 'why' you need to learn C++ though, only you can decide on that.

I went from XNA to SlimDX / SharpDX and I didnt regret my decision, sure the learning curve is greater than say an engine or other libraries but honestly after the initial few weeks every problem became fun and a game itself, however I should state my end game was purely to learn with and open schedule on when to stop. This may not be the best advice for you, but if your aim is to learn and you have a generous amount of free time (im talking months to years too) then a lower level graphics library may not be a bad idea.

Share this post


Link to post
Share on other sites
[quote]Then use C. Then use Assembly. Go write a compiler.[/quote]

Sure, all of these have plenty to teach. I understand the ultimate logical conclusion here: if you [i]really[/i] want to learn how a computer works start building switches. This would also be valuable, but is so far removed from making games it's not worth pursuing in order to make one. In my opinion, C++ is not a bad candidate for making games [i]and [/i]learning some things higher-level languages might give you very little to no exposure to. Sure, these languages exist for exactly the reasons you describe: they absolutely make life easier if you're looking to get something done quickly, focus on game play, etc. There is definitely value in that.

[quote]There are better ways to get this sort of knowledge without the gotchas inherent in the language's design.[/quote]

To what are you referring here?

Share this post


Link to post
Share on other sites
[quote name='greenvertex' timestamp='1347567880' post='4979821']

[quote]There are better ways to get this sort of knowledge without the gotchas inherent in the language's design.[/quote]

To what are you referring here?
[/quote]

I am not speaking for him, but I would answer:

- C legacy cruft... ( malloc, stdio, etc )
- the shitastic link process
- the precompiler
- byzantine inheritance rules
- pre-STL C++

Those are the warts that leap immediately to mind, but only really scratch the surface. There are little niggling things too, like scoping rules in for loops or the ++ gotchas.

Share this post


Link to post
Share on other sites
[quote name='greenvertex' timestamp='1347567880' post='4979821']
In my opinion, C++ is not a bad candidate for making games and learning some things higher-level languages might give you very little to no exposure to.
[/quote]

And I respectfully disagree.

Well, not so much about the second half of that. I agree that you'll learn things that higher level languages give little exposure to; I just think that they're insignificant.

[quote]
To what are you referring here?
[/quote]

I have about 6 years of history on the forums detailing pitfalls (and a few years before extolling its virtues). [url="https://www.google.com/#hl=en&q=site%3Agamedev.net+Telastyn+C%2B%2B+pitfall&oq=site:gamedev.net+Telastyn+C%2B%2B+pitfall"]Easy enough to find. [/url]

I should just write it up one day and link to it.

Share this post


Link to post
Share on other sites
Oh, wow. Just have to go away some hours to find the exact opposite of what I got told yesterday.

I want to learn C++ mainly because I never worked with low-level languages, and because I'm sure it'd be a great learning experience.
I also tought that its libraries would make life as easy as it is with XNA, but I think I'm wrong after seeing all those replies.

I have the solution: I'll keep studying C++ as a hobby, while continuing my C# projects.

Share this post


Link to post
Share on other sites
It boils down to whatever you want to do... You want to be productive now - stick with what you've got, as long as it works for you. You want to learn a lower-level language and have the determination to feel stupid again without giving up (because switching will, at times, make you feel that way), then go ahead onto C++. What C++ has for you ... it's the de-facto standard for any "serious" (read consoles + PC/MAC) game dev company (I should know, I've been working for one for 6.5 years). If you want to code an xbox game (short of little XNA games), you will do it in C++ at least at some level, because the sdk they offer is for C++; want to code something for PS3... yep, C++ sdk as well... So, just define your goal: productivity now or study_now_reap_benefits_later. If you're determined and willing, I see NO reason not to go into some C++ programing. Have fun!

Share this post


Link to post
Share on other sites
[quote name='KappaG3' timestamp='1347573275' post='4979854']
Oh, wow. Just have to go away some hours to find the exact opposite of what I got told yesterday.

I want to learn C++ mainly because I never worked with low-level languages, and because I'm sure it'd be a great learning experience.
I also tought that its libraries would make life as easy as it is with XNA, but I think I'm wrong after seeing all those replies.

I have the solution: I'll keep studying C++ as a hobby, while continuing my C# projects.
[/quote]

Define low level language. From my perspective, C++ is not a low level language, even C has a sufficiently nice set of abstractions on it that help to remove some of the more machine level concepts. If you really want to learn about low level programming you need to get into micro-architectures. Things like the [url="http://www.parallax.com/tabid/407/Default.aspx"]propeller[/url] can be a great introduction to low level/embedded coding and are cheap enough and simple enough to get into on a budget.

As far as learning C++ goes, Telastyn's list of reasons are pretty much the main ones you should concern yourself with as a guide to determining when you should "switch" to C++. But I've got a few hints for you:[list=1]
[*]You'll never "switch" to another language. You may one day end up using one language more than another, but the more languages you know the more doors you open. Both for solving problems and for job opportunities.
[*]Every language has a set of problems its good at solving, do not blind yourself to other languages just because you have a preference for one. This bites many a beginner on the butt many a time. If you need to ping a target and check the error result then you can do all that in a batch file, you don't have to write a C++ or C# application.
[*]You don't have to abandon a language to learn another. You can learn two languages side by side, or practice your main language while you learn a secondary. In fact, this can be an easy way of learning the differences between two languages and how they apply their respective idioms. It can also help you in understanding how the "implementation" of something actually works.
[/list]

Share this post


Link to post
Share on other sites
C++ allows for very detailed control over the operation of your programs. It provides you with numerous tools to express yourself in many paradigms; if you want you can mix various styles of coding in a single project. Don't underestimate the amount of stuff that is provided, and realise that many c++ features are really different approaches to doing things.

However, some of the coding style options that are provided are not exactly the safest way to program. The language generally requires you to know what you're doing and doesn't really do a lot of hand-holding. I guess the most obvious thing you'll notice when you come from a C# background is the manual, very explicit resource management. That and a relatively small standard library.

For me, the main reasons for choosing C++ are:
- Detailed, explicit control over your application
- Freedom of expression
- Large set of (domain-specific) libraries
- Code will compile to just about any platform
- Language will remain stable for many (~10) years

Reasons against:
- Complicated compilation/linking rules
- Difficult to read compilation error messages (and a steep learning curve because of it)
- Limited managed resource access (many ways to mess up, correct usage requires discipline)
- Smallish standard library (when compared to C# or Java)
- Slow to adapt to programming language trends

If you want to learn C++, might I suggest you don't bother with legacy stuff and jump straight to C++11. The improvements to the language are beneficial to beginners and veterans alike.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this