Deciding to switch to C++

Started by
8 comments, last by Ravyne 9 years, 10 months ago

I've been programming in Java since grade 11 in highschool(Just finished first year university) and I've made some really good progress with the language. I've made a few simple games like the ones recommended on this site. I'm currently working on a 2d RPG in Java using LibGDX and it's going fairly well.

My concen is that there really isn't that much support for Java game development... I mean, for the level of programming I'm doing the performance difference is negligible so that really isn't a factor. But it seems that there are WAY more good APIs and engines for C++ than you can find for Java. 99% of the gamedev books I see written are intended for C++. I'm sure the concepts transfer, but it would be better to just have a book in a langauge that you'd know.

Another thing I've conisdered is that I'll have to learn C++ eventually anyways if I want to become a professional gamedev after school. Not many AAA games use Java, even runescape has left it for HTML5.

Ranting aside, what do you guys think I should do? I was considering ordering C++ Primer, then maybe Game Coding Complete and seeing where that takes me.

Any suggestions would be greatly appreciated.

Thanks,

Stein102

Advertisement

Well, good on you for having learned another language first.

As for switching to C++... well, its going to take time. A lot of it. You will find the tools for C++, at least in relation to refactoring and such, to be a lot more primitive than the Java/C# versions. You will also find the language is a lot less friendly, and the standard library is quite a bit slimmer. This means you will spend a lot more time either investigating libraries to augment functionality, or implementing boilerplates.

As for resources: C++ Primer is a good start, especially if you get the latest edition which covers C++11 features. Do be warned though that many C++11 features are not yet supported by all compilers. The C++ Programming Language is also a good one to get. Then there are other books that are good reads, such as Effective C++.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

What exactly do you mean that the tools in relation to refactoring and such are more primivite

Would you say it's worth the time in learning C++ and dealing with all the learning pitfalls so I can work with better game APIs and have more support? I feel like my main issue is just that it's really hard to find a good game programming book in Java.

Also, I'm not sure whether or not I should finish my current game(It's going to take a ton of time to finish) or just switch now.

Thanks

What exactly do you mean that the tools in relation to refactoring and such are more primivite?


To perform refactoring, tools have to be able to accurately parse the source code and determine what everything means. It's much harder to do this accurately with C++ source code than it is with Java source code.

It depends on the project, but C++ refactoring tools have a tendency to get confused and miss things or discover false positives when doing this.

The preprocessor plays a big part in making life hell for static analysis of C++.
Would you say it's worth the time in learning C++ and dealing with all the learning pitfalls so I can work with better game APIs and have more support? I feel like my main issue is just that it's really hard to find a good game programming book in Java.

Well, the ultimate goal of every programmer is to ignore language and focus on concepts, ideas and their respective solutions. Not that Java is a bad language for game development, although I'm sure you already know that.

You will mostly be doing the same things in C++ as you are doing in Java, except everything takes more time and you have alot more room to express yourself in the code. Which can be a good thing and a bad thing depending on the alignment of certain planets.

If you think finishing your current game is going to teach you alot (it probably is, if its a complex game), then don't. If it's just alot of boilerplate programming, like adding a menu or replacing assets with better ones, then just consider it complete. There can be alot of value in finishing things you start with, especially more complex projects. I made a legend of zelda game engine once upon a time, and I learned the most at the very end of the project. I had no books, and no one to teach me what to do, since this was before the age of the Intergoogle. I realized that I don't have to draw all the tiles that I can currently see on camera if I just combine them on a bigger texture that fits inside the screen (and slightly outside to make transitions look smooth). I learned to sort sprites by Z/depth, even if the algorithm was really shitty. I learned how to blend a layer of clouds and a shitty sunshaft animation on top of the screen to make a cool effect that I didn't really like. And I also learned a little bit of C to create effects like snow-flakes falling down, or sand blowing in the wind. In other words, there's always something more you can do, and it can really just go on forever if you're like me.

In the end, I regretted not learning c++ sooner. Just make sure if you do go the C++ route to REALLY investigate what the absolute easiest route to getting started is. And make sure your setup is not a hinder. Download free MSVC++ for windows, or Codelite for Windows/Linux. With Microsoft VC++ you get the (locked-in) compiler, but the IDE is the best around. Codelite isn't the worst, and with it you can use the GNU compiler suite (mingw64 / TDM-GCC-64 on windows) and on linux it's just a "sudo apt-get install g++" away. I recommend Microsofts IDE btw. as it sets things up for you and "it just works."

Churn through some tutorials to get the basics of the language, make sure you READ THE RESPECTIVE C++ Reference on each and every little thing you do, since it's actually very informative. And there are occasional examples. For example, C++ strings: http://www.cplusplus.com/reference/string/string/

After that, consider using SDL2 (or later) or SFML for graphics programming. Note that SDL is a complete framework that includes sound/streams, networking and all that fancy stuff.

The cplusplus.com tutorial section: (not sure how good it really is)

http://www.cplusplus.com/doc/tutorial/

If you want to (or feel you need to) learn C++ then go for it - it's that simple. It is (as you noted) a very valuable language for a would-be game developer to know, and whilst it's common to recommend beginners learn another language first C++ certainly isn't a language that's impossible (or even overly difficult with the right attitude) to learn.


Regarding your current project, I believe you missed a third possibility; split your time and continue to develop your project using Java, whilst at the same time learning C++. As the little girl in the ads says, "why not both?"

Otherwise, if you feel that splitting your time and attention over the two languages is too difficult or not something you want to take on, you'll need to decide what's more important to you personally; would you rather invest more time into learning C++ (and probably starting a new project) immediately, or would you rather complete the existing project (which may be a good thing for a resume and/or portfolio).


Hope that helps! :)

- Jason Astle-Adams

Also, I'm not sure whether or not I should finish my current game(It's going to take a ton of time to finish) or just switch now.

Absolutely finish your game.

You can, as jbadams suggests, learn C++ at the same time. But the ability to finish a game project is a compelling one for a potential employer; the sooner you start on that habit the better.


Absolutely finish your game.

In principle, I agree, but since OP alludes to it taking a ton of time it *might* be worthwhile to port the game to C++ and complete it there, especially if OP feels that the lack of gaming support in Java is a hindrance.

I would say if you are less than 40% of the way through, or if you're more than 9 months from completion, then consider re-writing what you have in C++ and finish the game. Otherwise, stick it out with Java. Josh is absolutely right that a completed game in any language is way more valuable than numerous half-finished ones. A bird in hand is worth two in the bush, and all that.

However, be aware that you will certainly find C++ to be more slow-going. C++ has a great many points in its favor, but productivity is never counted among them -- even moreso for a beginner. You will not have good tools for rapid refactoring, error messages are often arcane, and your programs will leak memory gleefully if you fail to apply proper management patterns.

Modern, idiomatic use of C++11 better arms you against those sorts of problems than C++ ever has in the past, but its road is simply not as well-paved as languages like Java or C#. Since you have the benefit of starting now, in the age of C++11, I would recommend you against using dated resources for learning. Many of the core books -- Lippman's C++ Primer, Stroustrup's The C++ Programming Language, and Josutti's The C++ Standard Library -- are up-to-date with C++ 11 in their latest editions, try to learn from those. Stroustrup's A Tour of C++ is a great introductory text as well, short, but inexpensive. Meyer's is writing an updated Effective C++ as well, but its not ready yet, that one looks like it will cover both C++11 and C++14, which is being voted as a final standard soon (I wouldn't wait for texts to be updated for C++14, the changes between it an C++11 are less radical/fundamental than between C++11 and what came before it.)

throw table_exception("(? ???)? ? ???");

Absolutely finish your game.


In principle, I agree, but since OP alludes to it taking a ton of time it *might* be worthwhile to port the game to C++ and complete it there, especially if OP feels that the lack of gaming support in Java is a hindrance.

I would say if you are less than 40% of the way through, or if you're more than 9 months from completion, then consider re-writing what you have in C++ and finish the game. Otherwise, stick it out with Java. Josh is absolutely right that a completed game in any language is way more valuable than numerous half-finished ones. A bird in hand is worth two in the bush, and all that.

However, be aware that you will certainly find C++ to be more slow-going. C++ has a great many points in its favor, but productivity is never counted among them -- even moreso for a beginner. You will not have good tools for rapid refactoring, error messages are often arcane, and your programs will leak memory gleefully if you fail to apply proper management patterns.

Modern, idiomatic use of C++11 better arms you against those sorts of problems than C++ ever has in the past, but its road is simply not as well-paved as languages like Java or C#. Since you have the benefit of starting now, in the age of C++11, I would recommend you against using dated resources for learning. Many of the core books -- Lippman's C++ Primer, Stroustrup's The C++ Programming Language, and Josutti's The C++ Standard Library -- are up-to-date with C++ 11 in their latest editions, try to learn from those. Stroustrup's A Tour of C++ is a great introductory text as well, short, but inexpensive. Meyer's is writing an updated Effective C++ as well, but its not ready yet, that one looks like it will cover both C++11 and C++14, which is being voted as a final standard soon (I wouldn't wait for texts to be updated for C++14, the changes between it an C++11 are less radical/fundamental than between C++11 and what came before it.)

Yes, getting the C++11 versions of the books (which I linked) is definitely important. It is important to note though that most compilers do not fully implement the C++11 standard yet, usually its either parts of the standard library missing (such as regex) or its language things like constexpr.

Effective C++ is a great book regardless of C++11 or not, but since he'll be spending his time learning, its not a necessary book to have in the near future... So... he can wait to pick that up until the 2014 edition is out.

As far as the project goes... honestly, its nice seeing projects in multiple languages. It shows a level of flexibility that many junior programmers do not have. So if this project is too far in the future, it would be good to do up another project that simpler in Java.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.


Yes, getting the C++11 versions of the books (which I linked) is definitely important. It is important to note though that most compilers do not fully implement the C++11 standard yet, usually its either parts of the standard library missing (such as regex) or its language things like constexpr.

Many of the compilers are more than good enough to basically ignore outmoded techniques and idioms though.

Notably, Microsoft's compiler is furthest behind -- they plan on delivering a sort of mishmash of C++11 and C++ 14 features going forward, until around the time that everyone ought to be delivering C++14, when they'll achieve rough parity. If you've read any of the blogs, they've stated several times that the simple fact is that their compiler internals had been quite dated, and they're having to refactor great swaths of it concurrently to implementing new language features -- I mean, the compiler didn't even have an intermediate representation before.

Still, even today on any mainstream compiler including Microsoft's, you get things like auto, trailing return types, lambdas, variadic templates, parameter packs, shared_ptr/weak_ptr/unique_ptr, make_shared, chrono and random, range-based for-loops, rvalue references and move semantics. initializer lists, decltype, defaulted and deleted member functions, default template arguments for template functions, delegating constructors, atomics. The most useful stuff is widely available (with the notable exception of constexpr), the stuff that really impacts the way you architect and write your code.

throw table_exception("(? ???)? ? ???");

This topic is closed to new replies.

Advertisement