Sign in to follow this  
CrazyRobotStudios

Should I learn c++ for game dev?

Recommended Posts

Just go for C++ if you are choosing because it opens more road in the game development.

You can also mix C++ and a little Java if you are looking for a Mobile solution, you can then be cross platform Mobile/Desktop.

Edited by Alundra

Share this post


Link to post
Share on other sites

If you want a career as a programmer, then learn C++ at some point in time, because it's what many game-dev companies use, more importantly because it's a hard-to-use, overly-complex, low-level systems-programming language that is a rite of passage for any experienced programmer. You should also learn C at some point in time.

Share this post


Link to post
Share on other sites

If you're not happy with Java, then learn something else. C++ is a pretty reasonable option for that 'something else.' What more reason do you need? What sort of reasons are you looking for? You can make games in just about any language.

Share this post


Link to post
Share on other sites

In today's world deciding which language to use soley on language comparison is like trying to buy a painting when you're blind.

 

What you really need to do is find a tool set that allows you to make what you want to make. Here's why, say you pick c++, well great but what api are you going to use to draw? How will you even design your scenes without an editor? What about asset management and loading? ECT...

 

The reality is you need a tool set, not just a language.

 

That said there are a few good tool sets out there right now.

 

if you really want to stick with c++ then look into Unreal Engine. However I think your best bet as a beginner game developer and Java programmer is Unity with C#. Java and c# are similar in a lot of ways including GCing.

Edited by EddieV223

Share this post


Link to post
Share on other sites

Outside low latency and high performance things, the big deal with learning C/C++ is that you are forced to deal with proper memory management, which is a little(a lot?) opaque with languages like Java (or completely hidden in "esoteric" languages like ML or other functional mass destruction weapons) . In my opinion proper memory management is a must-have requirement of every programmer and software developer, doesn't matter it the tools you manage at works doesn't involve explicitly pointers or not.

Edited by Alessio1989

Share this post


Link to post
Share on other sites
Do you want to work on a AAA development team making games for consoles and/or PC? You have to learn C++. No other language is supported on all three consoles plus PC. And the other languages typically have additional overhead that most AAA developers don't want to pay.

Working on your own game or in a small indie group? Write in whatever language you like, within platform and performance restrictions you set yourself (i.e. you're probably going to have to write Java at some point for an Android game, and Objective-C for an iOS game, assuming you don't use some sort of wrapping library). Minecraft is written in Java. Most Unity-based games are written in C#. Even Python has a set of libraries for game development.

Learning C++ is still beneficial however, as it does not hide nearly as much of the computer from you. Edited by SmkViper

Share this post


Link to post
Share on other sites


you are forced to deal with proper memory management

Yes, traditional c++ encourages manual memory management. 

 

In most large modern projects though manual memory management is discouraged. For example in unreal engine, the example given above, a lot of stuff has pointers managed for you and reference counted and deletions strictly marshalled to ensure that you don't delete something that another part of the engine still holds a reference or pointer to. Very rarely do you find yourself calling new or delete.

 

My advice if you're starting out in C++ is avoid as much dynamic memory management as possible. Allocate on the stack and let the runtime library deal with freeing when things go out of scope. Only use raw pointers when you really must. Once you start on C++ you will know what all this means.

 

As for should you start on C++ at all, definitely you should and sooner rather than later, as a programmer it's one of the most useful things to know and it's understanding opens the door to many other programming languages and libraries. 

 

Good luck and have fun!

Share this post


Link to post
Share on other sites
 

 


you are forced to deal with proper memory management

Yes, traditional c++ encourages manual memory management. 

 

In most large modern projects though manual memory management is discouraged. For example in unreal engine, the example given above, a lot of stuff has pointers managed for you and reference counted and deletions strictly marshalled to ensure that you don't delete something that another part of the engine still holds a reference or pointer to. Very rarely do you find yourself calling new or delete.

 

My advice if you're starting out in C++ is avoid as much dynamic memory management as possible. Allocate on the stack and let the runtime library deal with freeing when things go out of scope. Only use raw pointers when you really must. Once you start on C++ you will know what all this means.

 

Yes, modern C++ and big projects doesn't have a lot of manual memory allocations and alignments. In modern C++ and big project you build you own allocators, your own reference counter smart pointers, your own pools, etc... But to proper understand or even more to proper build your own "automatic" memory management system you need to know how to deals with pointers, pointer arithmetic, alignments, proper deallocation and of course leaks thrown from exceptions (mainly from constructors). Otherwise it's better to go with C# or Java if you do not understand the tool you are using.

Of course using STL containers on beginning is a good to start. But when you need to build your own system, you must understand all the annoying and traditional/C_with_classish things.

Edited by Alessio1989

Share this post


Link to post
Share on other sites
Even reference counting is a hell of a lot more manual than garbage collection though.
Ref-counting still forces you to think about strong vs weak pointers, circular references (which become leaks in Ref-counting, but are solved with GC), interactions with raw-pointers, thread-safety of destructors, etc...

One of the reasons we use C++ is that it lets us choose which (mostly automated) memory management system to use, and also lets us still micro-optimize memory placements and locality of reference.
e.g. on more than one engine that I've worked with, there's been no global new/malloc heap -- instead, when new'ing an object, you have to manually specify which specific heap/pool/stack it will be placed in.

C++ also lets us create multiple objects within a single contiguous allocation - a pattern I've seen in multiple engines is two-pass-initialization. Fisrt a system "dummy allocates" all its required objects, which just increments a counter to measure the memory requirements. Secondly it actually allocates one single large block of that size, and performs the same logic except this time it actually creates all its required objects within that allocation.

Share this post


Link to post
Share on other sites

C++ is a standard. It's the most commonly used language in Programming simply because you have control over EVERYTHING. That's what makes it so fast and effective. But it's also incredibly complicated when you go into detail. However, I recommend starting with something easier if you are new to programming in general. Or... you are a wide eyed hopeful person. It's not really an easy language to learn, and a LOT of game programming is based on technical, scientific, and mathematical knowledge. Less so if you are just a scripter.

 

I'd recommend starting with Lua and the LOVE game framework first. Lua is easy to learn, newbie friendly, and would be a great introduction point. There are also some really good tutorials from PacktPub, and around the net to help you get started.

Once you feel comfortable, and like programming, move onto C++... starting at ground zero. You need to learn the language, and basic algorithms before you can really do anything amazing with it.

Edited by Tangletail

Share this post


Link to post
Share on other sites
Lua is easy, but it is also VERY minimalistic.
- Only one container type, learning about using the right data structure for the job goes out the window.
- It does not have some common statements like "continue" (mailinglist ends with a loop+break to emulate "continue" http://lua-users.org/lists/lua-l/2006-12/msg00440.html I wouldn't dare explaining that to a new programmer)
- Language is 1-based rather than 0-based. You need the latter for easy 'div' (integer /) and 'mod' (often %) operations.
- 0 is not false:
$ lua
  > if 0 then print("true") end
  true
- No classes (out of the box), but metatables for inventing your own notion of classes.

These language design decisions make Lua less useful as first language to learn, imho. New users pick up the first language as reference point. You better start with a language that is closer to the usual languages. Edited by Alberth

Share this post


Link to post
Share on other sites

Mm, I said Lua, because you can learn how loops and stacks work without being constrained to types. When the OP feels comfortable, he/she can then move on to C++ which is a statically typed languge.

With a foundation in how loops work, it's easier to understand how types function without worrying about some other more critical foundation. And then with types, to classes, then polymorphism, algorithms, then patterns.

 

This is just going on a whim of simplification. I don't know the OPs capacity, and I learned C++ as a first language with minimum problems.

Edited by Tangletail

Share this post


Link to post
Share on other sites

If you want a career as a programmer, then learn C++ at some point in time, because it's what many game-dev companies use, more importantly because it's a hard-to-use, overly-complex, low-level systems-programming language that is a rite of passage for any experienced programmer. You should also learn C at some point in time.


I agree, except the C part. Not really sure what value learning C really brings to the table in this day and age. If you get a job in embedded systems or hardware I suppose, but for most programmers, even game programmers, Im not really sure what they'd get out of it?

Share this post


Link to post
Share on other sites


Im not really sure what they'd get out of it?

 

Learning C teaches a deeper understanding of pointer arithmetic, as nothing is abstracted away as standard. There is no operator overloading, no references, no string types. You are forced to learn basic data structures of computer science such as linked lists, binary trees, and how strings are represented as arrays of characters. 

 

I'd definitely recommend it as it makes you a better C++ programmer IMHO.

Share this post


Link to post
Share on other sites
As well as the above (getting rid of C++ niceties), it's a completely different paradigm than C++.

C is generally used in a procedural paradigm, whereas C++ is generally used in an OO paradigm. Programmers should also learn JavaScript to appreciate the prototype paradigm and a functional language too.

e.g. lots of people struggle to write large, manageable, flexible shader codebases in HLSL/GLSL because they're not well practiced in the procedural sytle.
C++ is multi-paradigm, so there'll be times where you'll need to write very C-style code in C++.

Back to what braindigitalis was saying though, it can be used to demonstrate a deep understanding of C++, due to it's simplicity. e.g. It's one thing to be able to use virtual function calls in C++, but it's another to be able to demonstrate how they'd be implemented in C code. If an interview candidate can past that test, then I've got a whole lot more trust that they truely understand what they're doing :)
Likewise, at the last company I worked for, they write all their game code in Lua. However, they require all the gameplay programmers to know C++, as it ensures that they'll truely understand the impact of the Lua code that they write.

For a super-technical position -- e.g. programmer in charge of the game engine, I'd probably want them to be able to read assembly code, not just C :)

Share this post


Link to post
Share on other sites

but for most programmers, even game programmers, Im not really sure what they'd get out of it?

Classes are nothing more than a bunch of struct with function pointers and a "this" first formal parameter?  smile.png

 

More seriously, I find that using pointers/references to design smart data structures is a quickly dying art.

 

I once had the problem of storing an automaton in Java. It has states and directed edges with an event name.
You must be able to walk forward and backward from state to state, over the edges (using the event name as a filter which edges to consider).
There are a LOT of states, several 100,000 at least, preferably 1,000,000 or more. Branching factor is about 3-6 (each state has only a few outgoing edges). Once created, the structure is quite stable, removal of states and edges must be possible but doesn't need to be fast. Walking over states and edges (both forward and backward) must be very fast.

Now if you solve this in normal Java or modern C++, you'll end up with a List<Edge> outgoing edges from each state, and a List<Edge> incoming edges into each state. So for each state which is otherwise empty, you have two lists. For each edge which has a pointer to the successor state and one to the predecessor state, and an event name, you add two list elements (one in the outgoing list of the predecessor state, and one in the incoming list of the successor state). For N states and M edges, you thus get 2N lists, and 2M list elements. In other words, 2/3 of the objects in memory is list administration. Since states and edges are very small, I am throwing away 2/3rd of my memory here.

(Note: Realizing this implies you understand how List<Edge> works!!)

 

In addition, iterating over edges to find eg successor states means you iterate over the outgoing list elements, dereference to the edge, and then use the successor pointer of the edge to find the next state. That's two dereferences for each edge traversal.

Now the C-ish variant:

struct State {
    Edge *outgoing; // Head of a single linked list to outgoing edges
    Edge *incoming; // Head of a single linked list to incoming edges
};

struct Edge {
    Event *name; // Event name

    State *successor;   // Successor state
    State *predecessor; // Predecessor state
    Edge *next_outgoing; // Single linked list to next outgoing edge of the predecessor state
    Edge *next_incoming; // Single linked list to next incoming edge of the successor state
};

I literally iterate over the edges from a state through a single linked list. I kill all List<Edge> objects, and all list elements in them, at the cost of two pointers to next edges in each Edge. This gives me almost 3 times as much space for my states and edges. I save one dereference (from list element to the edge object), making iterating twice as fast.

I would say, this are significant savings that you can achieve. Anyone who hasn't used single linked lists or double linked lists at the level of C (adding pointers in the struct himself) is never going to find such a solution.

 

I agree this is an extreme example and you don't need these things every day, but experiencing C can open your eyes to better solutions.

Edited by Alberth

Share this post


Link to post
Share on other sites

As well as the above (getting rid of C++ niceties), it's a completely different paradigm than C++.

C is generally used in a procedural paradigm, whereas C++ is generally used in an OO paradigm. Programmers should also learn JavaScript to appreciate the prototype paradigm and a functional language too.

e.g. lots of people struggle to write large, manageable, flexible shader codebases in HLSL/GLSL because they're not well practiced in the procedural sytle.
C++ is multi-paradigm, so there'll be times where you'll need to write very C-style code in C++.

Back to what braindigitalis was saying though, it can be used to demonstrate a deep understanding of C++, due to it's simplicity. e.g. It's one thing to be able to use virtual function calls in C++, but it's another to be able to demonstrate how they'd be implemented in C code. If an interview candidate can past that test, then I've got a whole lot more trust that they truely understand what they're doing smile.png
Likewise, at the last company I worked for, they write all their game code in Lua. However, they require all the gameplay programmers to know C++, as it ensures that they'll truely understand the impact of the Lua code that they write.

For a super-technical position -- e.g. programmer in charge of the game engine, I'd probably want them to be able to read assembly code, not just C smile.png

 

You are a monster!
 

Anyways...

 

C++ and C (Increment of C, or C with Objects) is still widely used in a lot of industries. Not just Embedded systems. C++ is used in real time simulations, games, rendering software, Networking protocols and communication (C was created in Bell Laboratories for Unix. Originally intended to help drive their servers... it just basically became the go to language for everything), operating systems, drivers, games, robotics, the list goes on.

The language is so wide spread, that most new languages are derivatives and supersets of it. And normally built with C++ or C. Imagine that.

 

Also... gameplay programmers whom program in scripting languages... will need to learn C. It's annoying as heck. But most scripting languages are usually procedural. And you'll need to learn how to dance around that limitation.

Edited by Tangletail

Share this post


Link to post
Share on other sites
I would say that learning C should be done, but not the focus. The average programmer is only going to run into C when dealing with various APIs due to the defined binary layout C has that lets software compiled with multiple compilers and languages talk to each other. So you should at least understand enough C to communicate with external libraries and wrap your own stuff.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this