Go for video game programming?

Started by
18 comments, last by larsbutler 9 years, 11 months ago

I was watching a presentation on Go and I started wondering if it would be more efficient than C++ for my game engine? I mean obviously multithreading can be done in C++ but it would appear that Go would streamline the process. So really my question is does Go have any down side? Like for example even though a language like C# or Visual Basic is easier to use, grabage collection amoung other things tends to make it run much slower than a program written in C++. So is there anything simular to that with Go?

Advertisement
Go is garbage collected, but whether or not that's a problem depends a lot on what you're trying to use it for.

Library support for things like game development is a little constrained right now, but the selection is growing.

In general, though, you shouldn't pick the language just because it sounds "more efficient." Use it because of the language and its characteristics. What helps you be productive is far more important than a few billionths of a second.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

I agree with ApochPiQ. I just want to add that the presentation you looked at was probably from some party that's a fan of Go, so maybe you should try to search for a list of disadvantages too?

I was watching a presentation on Go and I started wondering if it would be more efficient than C++ for my game engine? I mean obviously multithreading can be done in C++ but it would appear that Go would streamline the process. So really my question is does Go have any down side? Like for example even though a language like C# or Visual Basic is easier to use, grabage collection amoung other things tends to make it run much slower than a program written in C++. So is there anything simular to that with Go?


A close friend who is a huge Go proponent and has written a game engine in Go, has have a number of other people. While I personally have a number of things I dislike about Go, the question of whether it can work for games is a clear "yes." Game engines have also been written in Haskell and any number of other "games unfriendly" languages.

Garbage collection does _not_ make Go run "much slower" than C++. The number of C# games (including most Unity titles) should illustrate that it is entirely possible to make a real game with garbage collection. What garbage collection does is add an unpredictable spike in processing time, which can result in missed frames and general jankiness (if you aren't very careful). You need to be highly aware of the GC, what triggers it (allocations, generally), and what code to avoid running during the game loop (many features in languages like C# or Go don't _look_ like they're allocating memory but actually are, and you need to know what those are and how to avoid using them); then you can avoid most of the problems of GC.

The biggest problem you're liking to run into with Go is the lack of generics (templates in C++ lingo) and the unnecessary boxing (memory allocations) that containers require. Note that due to JVM limitations, Java also has this problem despite having generics. C# and Rust however support "real" generics that don't have this problem. C in a way _does_ have this problem, in that you either have to use some kind of generalized container that must box values or you have to reimplement your containers (or use macros) for each type, which is a very big real-world case where C++ (or Rust) is more efficient both in terms of performance and development than C is thanks to templates.

If you can't completely eliminate invocations of the GC, you're going to have a problem making games that use up all available CPU time for meaningful processing, as there simply won't be any place for a GC to run without causing frame skips. Unless you're DICE or Rocksteady or some other AAA developer, though, it is exceedingly unlikely that you are going to be in such a situation.

I'm personally of the opinion that Go is simply not the best fit for games. If you're looking for Go's niceties over C++ (cleaner non-C-poisoned syntax, simple and efficient threading model, etc.) you should instead look at Rust. Again, that is just opinion. I stick with C++ since I find it easy enough to build Go-like or Rust-like threading libraries in C++, and C++ has a number of other benefits over everything else (wide industry support being a big one). If you're interested in exploring Rust, this page has some useful links on it for Rust game development.

Sean Middleditch – Game Systems Engineer – Join my team!

There's nothing intrinsically wrong with it, but I personally don't like Go's hardline stance against generics. It's a painful productivity miss.

Of all the "C/C++ esque" languages that have cropped up in recent years, D honestly seems to have the best basis along with Go (though Rust is certainly interesting). That's probably the only language out there where you can write code and say "...did I just accidentally do template metaprogramming?" It's liberating.


Of all the "C/C++ esque" languages that have cropped up in recent years, D honestly seems to have the best basis

My core problem with D in this respect is that it *is* just a C++ clone with some (but far from all) rough edges rounded off.

Sure it makes template metaprogramming simpler than C++, but it doesn't really add/enable a whole lot else. No native support for high concurrency, no attempt at a new memory model, no attempt to simplify or improve the basic programming model, and so forth...

Rust is very interesting on a variety of fronts: coroutines/fibers without shared mutable state is a proven model for massive concurrency, explicit region support is the first attempt we've seen in a long time to sidestep the whole reference counting vs garbage collection debacle entirely, and the system of traits/implementations/structs might finally get us out of the many holes that inheritance-based OOP has dug (the dreaded diamond inheritance in C++, implementation vs interface inheritance, etc).

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I am using Go for a pet 3D project and I also use it in production for the server side of my latest game... here's my recap:

PRO

- Build system.. it's pure awesomeness: no makefiles, super fast compile times, good package managing with Git integration out of the box

- Fast and getting faster for code written in Go at every release.. for most common task it's almost with C++ at least from my benchmarks.

- Easy to interface C libraries. C++ interface exist but I haven't tried it yet

- Very simple to learn.. it's a very small language

- Duck typing.

- Great support for massive concurrency

- Gofmt.. forces an unique style of code formatting: the Go style. All Go code on the planet is formatted the same way.. this hugely improves readability.

- Good IDE support. I use LiteIDE ( https://code.google.com/p/liteide/ ) It's designed exclusively for Go and it's awesome. There are Go "modes" for Emacs, Vi, Eclipse, Sublime Text and a lot more.. and, because of go "no makefiles" "no project files" approach, it's one of the few languages you can really use without and IDE. Although I really suggest LiteIDE.

CONS

- No operator overloading. 3D math code looks ugly

- No function overloading.. need to use suffixes a-la OpenGL

- Calling C is somehow expensive.. there are ways to go around the problem but it is something to keep in mind when doing 3D work... every API call comes with an attached cost. Due to the language current architecture this cost doesn't seem to be likely to go away.

- Only supports "desktop" environments (Win, Linux, Mac) no Android yet (but there are somethings moving there and the presence of Google might do good things) or other mobile, no consoles support.

I don't take sides on the great "Go generics" war on the internet.. I find I can happily live without, but I wouldn't mind them either IF they can be implemented without bloating the language.

All in all, it's a joy to use Go although its minimalist approach often translates in a LOT of code repetition.. but it's beautiful code nevertheless. It's also a language that "trusts" the programmer.. it's a different philosophy of design.. where other languages seem to push programmers into writing in a way as to defend themselves from an horde of maniacs by having constructors, lots of level of encapsulation and so on.. Go's is much more permissive and it relies more on common sense and code documentation.

It's a programmers' for programmers language.. more practical and pragmatic than theoretically fit.

I agree with people suggesting Rust as another possible future language for game development.. it offers several advantages compared to Go but it comes with a much steeper learning curve (closer to C++ and D) with a less clear syntax compared to Go... plus while Rust is still highly volatile and constantly changing, Go has been ready and used for production for a couple of years.

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni


My core problem with D in this respect is that it *is* just a C++ clone with some (but far from all) rough edges rounded off.

Hah! In fact, that's what I love about it. C++ with all the C warts removed is already a fantastic language. Throw in all the range and slicing stuffs and array manipulation gets as easy as python. Stuff like Static If actually realizes some of the benefits over generics for people who aren't experts at the C++ labyrinth. IMO the biggest problem with D is that the GC is basically required if you want to use the standard library.

I need to clarify a bit, probably. While I don't like Rust for a variety of reasons, or Go because of generics, all three are head over heels better than most current "low level languages" out there. Libraries are a bit lacking for all of them, but if you want something different you can't go wrong with any of them.


- Build system.. it's pure awesomeness: no makefiles, super fast compile times, good package managing with Git integration out of the box

D has something like this as well (and they even made rdmd as a sort of "joke repl" because of how fast it compiles), though you need dub for good package management. Not putting down Go or anything mind you, and Rust probably has something similar. Going away from the C compilation model is the best thing that can happen to a language, and I'm glad to see its finally happening.

D has something like this as well (and they even made rdmd as a sort of "joke repl" because of how fast it compiles), though you need dub for good package management. Not putting down Go or anything mind you, and Rust probably has something similar. Going away from the C compilation model is the best thing that can happen to a language, and I'm glad to see its finally happening.

My only experiences with D were using Visual D, so I was somehow isolated from the build process. I tried Rust some days ago and ya.. it was able to figure out what files needed to be included in the build process... but I only tried with 2 files so I am not able to confirm how it works for bigger projects.

From what I see D has a lot of "nice little things" here and there.. its main attraction is metaprogramming which is way over the head of most devs, people don't really care... it doesn't really have a WoW factor in there and the community looks small and not very vocal nor active, it suffers the fact that it's not saying anything new or interesting.. it looks to me almost as a native C#. Plus it has a bad name that is almost a joke and the docs are not really up there with the competition.

Rust (talking about bad names :P what were they thinking? ) also seems to miss the commercial Wow factor.. the slogans are mostly about safety here and there.. a lot of good promises but mostly found in other languages. We'll see what happens when they go v1.0.. but I have a feeling that as of today, if programmers have to face something too complicate they'll just stick with what they have: C++ . The nice bullet in Rust's gun is their potential killer application: Servo.. the new Mozilla browser.. if that will ever come true.

Go and the Go community on the other hand, are doing a much better job IMO in promoting the language.. the Go tour is fantastic and there are very interesting tutorials and how-to popping up very often.. plus, the fact that Go has so many controversial features (or lack of) it never fails to generate discussion.. it's a language with a big attitude and I think that is also helping in building a following... it's pushing the right concurrency button. The language seems to be such a perfect fit for something coming out of Google.. it's a big association in people's minds... and, most important thing: once you give it a try, it's hard not to be hooked.

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni

Rust (talking about bad names tongue.png what were they thinking? ) also seems to miss the commercial Wow factor.. the slogans are mostly about safety here and there.

But that's exactly what developers *should* want. The hard problems in software development aren't addressed by cute little syntactic tricks like C++ template metaprogramming. The hard problems are in highly-concurrent distributed systems requiring high availability and having a low tolerance for failure.

It's precisely this sort of thing that Rust's feature set targets. Unique ownership semantics and implicit/explicit region control allows you to achieve near-automatic memory management without the non-deterministic pauses caused by garbage collectors. Lightweight cooperative multitasking with task-local state is the best know model for highly concurrent systems, especially distributed systems. Tasks also provide a coarse-grained alternative to exception handling, which side-steps the issues of stack annotation and unwinding, and allows you to reboot the entire task on demand in response to failure.

Now, Rust does not actually tick all these boxes at the present moment. For example, their support for async network communication is still pretty much non-existant. But they have a vision here that can drastically improve the process of writing reliable, distributed software. With the obvious caveat that most of the world will go on using whatever technology they currently use, unless it proves a real competitive advantage for companies which embrace it...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement