29 ms·
Why I Write Games in C
- sta11man 11y agotl;dr: I am old and retarded deepshit, so instead of choosing Go, which I like, I stay on plain C.
- RaitoBezarius 11y agoWhat about Rust?
- kodr 11y agomy thought. is there enough support for OpenGL? I know you can use stuff from C in Rust, so it could be a solution.
- mden 11y agoThere's also https://github.com/tomaka/glium https://github.com/tomaka/glium which seems very promising.
- pcwalton 11y ago> my thought. is there enough support for OpenGL? I know you can use stuff from C in Rust, so it could be a solution. glium is arguably the best idiomatic OpenGL binding in any language anywhere. I program in OpenGL with Rust every day as part of my job these days.
- alkonaut 11y agoExactly. Compilation times and young age might be an issue, but if the guy likes C and Go, then why not Rust? The reason people might want to avoid it can be the same as "Why not D". The answer to that is that it doesn't offer enough over C and C++, which is where Rust is different, and why I think Rust will be huge.
- pandaman 11y agoIs Rust available on consoles? (AFAIK, no) Is it going to be around? (Who can tell?)
- Manishearth 11y agohttps://twitter.com/rustlang/status/598945014824173569 https://twitter.com/rustlang/status/598945014824173569
- pandaman 11y agoAnd for any console other than PSX emulator you can place a SFF PC on a console and run Rust on it (as an added bonus you will get a better API than writing hex numbers into registers).
- douche 11y agoWho cares? Consoles are dead after this generation.
- s_kilk 11y agoWhy? Do you have any evidence to back up this claim? On the contrary, it seems both the Xbox One and PS4 are doing a roaring trade, with gaming overtaking Hollywood in terms of market size and revenue
- clouddrover 11y agoI'm not sure sure about a roaring trade. Games consoles are niche platforms. Look at the numbers: http://www.vgchartz.com/ http://www.vgchartz.com/ The global life to date figures are 12.4 million Wii Us sold since November, 2012. 19.2 million Xbox Ones and 35.3 million PS4 sold since November, 2013. Contrast that with PC shipments, where 70 million in one quarter is considered a bad result: http://betanews.com/2015/10/09/pc-shipments-decline-in-windows-10s-launch-quarter/ http://betanews.com/2015/10/09/pc-shipments-decline-in-windo... Or contrast it with the iPad's quarterly sales: http://www.statista.com/statistics/269915/global-apple-ipad-sales-since-q3-2010/ http://www.statista.com/statistics/269915/global-apple-ipad-... In FY2014 Apple sold 250 million iOS devices: http://www.geeky-gadgets.com/apple-to-sell-its-billionth-ios-device-this-quarter-22-10-2014/ http://www.geeky-gadgets.com/apple-to-sell-its-billionth-ios... Add in Android phones and tablets and the games consoles are dwarfed in comparison, even the 3DS which has sold the most of the current games console generation.
- AndyKelley 11y agoI like Rust, but sometimes it is pretty difficult to convince the compiler that one's code is safe. And this does not mean that the compiler is preventing unsafety; there are many safe programs that the compiler rejects. Also, the OP said that compile time was a priority, and compiling Rust code is closer to C++ speed than C.
- pdpi 11y agoThere are many valid programs that static typing rejects, too. Question is whether the trade off is worth it (and the answer isn't the same for everybody)
- Manishearth 11y ago> there are many safe programs that the compiler rejects It's often less about being safe currently and more about being resilient to breaking after further changes in code. I've worked with some C++ codebases that rely on complicated invariants to be safe (so the code looks safe now), and stuff breaks down when certain changes are made. Programming with a C++11 style greatly reduces but does not eliminate this. It takes a while to get a hang of this, but once you figure out the "Rust way" of moving data/references around you tend to hit these errors very rarely. Of course, this takes time to learn which you may not have :) But yes, there are things which Rust could improve upon here, like nonlexical scopes and SEME regions. Which may come soon.
- pcwalton 11y ago> And this does not mean that the compiler is preventing unsafety; there are many safe programs that the compiler rejects. Two nits: 1. The compiler does prevent safety problems. It just happens to rule out some safe programs while doing so. (Although I think this is a bit of a misconception, because with the aliasing rules being used for optimization many things that the Rust compiler rejects that people think are safe are actually not.) 2. You can describe any type system this way. That doesn't mean we don't like type systems.
- Jach 11y agoI think game programmers don't like type systems -- or rather, they prefer the minimal typing necessary for speed improvements and their ability to simplify basic static analysis (with tools or in their heads). I don't blame them, games are a lot of work even for relatively simple things, and to get anything done at a reasonable pace you just need to be able to churn out lots of code that compiles on the first try, and when it doesn't the mistakes should be easy to fix and minimize the time you're spending fighting with the type system (C++ templates come to mind as they're often avoided in games no small reason being the cryptic error messages they can produce). There might be an argument of familiarity, that eventually if they used Rust or Haskell enough it would all come to them as easy as C, but then well known Haskell promoters say things like "if you're using the type system right your code will never compile on the first time."
- dunkelheit 11y agoMaybe in ten years. Great thing about old mature technology such as C is that all gotchas have been tripped over innumerable times and are all well known and codified. Meanwhile new exciting technology like Rust contains unknown number of bugs like http://www.wabbo.org/blog/2014/22aug_on_bananas.html http://www.wabbo.org/blog/2014/22aug_on_bananas.html, undiscovered antipatterns and subtleties. My comment is not meant to bash Rust, on the contrary it is very promising and the fact that it is used to write Servo is likely to significantly speed up its maturation. But as author notes, if you are developing a project under a deadline you don't have time for bugs you didn't cause yourself. So old boring technology is the way to go.
- Rusky 11y agoThat bug was almost a year before Rust 1.0 was released. At this point, Rust is being used in production outside of Servo- for example Dropbox is even using it for their core data storage code. It's certainly not as old-and-boring stable as C, but it's a lot closer than you'd think.
- dunkelheit 11y agoAnd that bug was less than a 1.5 years before now. And Rust is at version 1.5 now. And all changelog entries since version 1.0 (which was released 8 months ago) mention "multiple bugfixes". Of course, that's all subjective, but for me these facts all scream "rapid pace of development, expect multiple annoyances and a couple of major bugs for your particular use case". Dropbox is using Rust in production? Great news! But I'll wait when a thousand of organizations use Rust in production before advocating its use in my own organization. Also, judging by this comment: https://www.reddit.com/r/programming/comments/3w8dgn/announcing_rust_15/cxum0dm https://www.reddit.com/r/programming/comments/3w8dgn/announc... they had incredible rapport with the language core team. That is a luxury not every team using Rust is going to have. Still, great news. I guess I must implement some kind of little personal project in Rust and in the process help iron out a few more quirks.
- steveklabnik 11y ago
- jaked89 11y ago"C# ... does a lot to railroad a programmer into a strongly OOP style that I am opposed to". C# has functional capabilities as well. People write in it nowadays in a whole lot of different styles, including procedural, OO, functional, reactive. Yes, the average developer uses it in an OO style, but it can do a lot more.
- gregmac 11y agoHis argument against OOP makes it sound to me more like he's using OOP design patterns he doesn't like: > I've spent most of my professional life working with classes and objects, but the more time I spend, the less I understand why you'd want to combine code and data so rigidly. I want to handle data as data and write the code that best fits a particular situation. To put it simply, I find when using DTOs to store data, and following SOLID principles to write the rest of the code, I end up with quite clean code that provides a very nice separation of code and data, and that the right level of abstraction and loose coupling is exactly what allows me to write the code that best fits a particular situation. Granted, I don't write games, but I do write high-performance, highly-distributed multi-threaded applications where clean and fast connectivity between components is very important, and the ability to unit test basically everything is essential. I guess to characterize OOP as 'combining code and data rigidly' is just so far off base from my style of OOP and my experience that I really can't identify with this as a reason to drop to C.
- mobiuscog 11y agoExactly - After all, you don't put all your code in a single C file. Using classes as simple modules - encapsulating a set of functionality - can still lead to a very procedural style without all of the extras.
- djur 11y ago> I would like to use [Go], but there are big roadblocks that prevent me. The stop-the-world garbage collection is a big pain for games, stopping the world is something you can't really afford to do. GC pauses in Go should not be a serious issue for games like the ones featured on the OP's site. The same general techniques used for high-performance manual memory management work fine in garbage-collected languages -- allocate on the stack if possible, allocate the heap you're going to need up front and reuse it (with object pools or the like). > The library support for games is quite poor I would say the same for C, honestly. Last time I was looking for game libraries to write a binding to (from OCaml) I found more C++ and Java options than C.
- jeremyjh 11y ago>I would say the same for C, honestly. Really? SDL is quite poor??? It has bindings in pretty much every language and I would guess is the most popular game library in existence, written in pure C. It is not a game engine but is an excellent library to build one with. It is so popular for this purpose that it has its own COLUMN in the Wikipdia table of game engines: https://en.wikipedia.org/wiki/List_of_game_engines https://en.wikipedia.org/wiki/List_of_game_engines
- yalue 11y agoOf course, a more or less 100% complete wrapper of SDL for Go exists, too, so SDL invalidates the original argument against Go if you're considering it for C.
- strangecasts 11y agoAnother nice library is SFML[1], which has bindings for C and several other languages (including OCaml). [1]: http://www.sfml-dev.org/ http://www.sfml-dev.org/
- seba_dos1 11y agoThere's also Allegro[1]. While its popularity peak was on older versions, Allegro 5 has been completely redesigned and it's a pretty great modern C library now. [1]: http://liballeg.org/ http://liballeg.org/
- raverbashing 11y agoI understand the want for simplicity in C (and Go gets closer, but has its issues), however, it seems in the end it drags you down. Just having the C++ ability to have objects doing things is very helpful. But yeah, C++ has the ability to get very complicated But it's your choice to have "complicated C++". Limit yourself to some functionalities and it's much more manageable. Use basic STL and keep it simple (also C++11 at least) and it's a very pleasant experience (or less worse experience, depending on your point of view).
- trendnet 11y agoI think that's what most engine developers do nowadays. Sticking to some part of C++ to a point that it looks like C with classes. Hey, some don't even use STL and go with their own libraries.
- hellofunk 11y agoI've seen Justin Frankel write that he works this way, and it has most certainly served him very very well.
- crafn 11y agoThere are some arguments to stick with C instead of a very C-like subset of C++. Off the top of my head: - Recompiling and reloading parts of your game at run-time is quite easy in C. In C++ you have to make sure (at least) that nobody has pointers to vtables of the dll at the time of reload. This can be a bit tricky if you're using things like std::function in your dll code. Yes, you could be using a scripting language, but thinking how to match the semantics of a scripting language with your engine, where to draw the line, and then write the glue code is a lot more work than just reloading some plain C functions. And if you later decide this was a bad/worthless idea, reverting from dynamic C code to static is almost a no-op, whereas reverting back from scripts is dreadful. - A quick & dirty reflection is easy when you don't have to deal with name mangling, templates, and overloading. Just some script scanning through your code and outputting elementary type info to .c file may be enough for things like real-time memory browser-editor for your whole engine. This can be very valuable when developing new engine features, as you can view and edit, and maybe draw even graphs of members you just added to some struct. Also useful for modifying game object data on the fly when debugging/creating levels. (I too do my game programming in C)
- ivanca 11y agoTL;DR Many people is making money doing Unity games, so I ignore it exists - for $1500 - and I go the hipster way and create my own hundreds of memory corruption bugs myself.
- scrollaway 11y agoIf you're going to write a TL;DR for others, you should at least read the article yourself, don't you think?
- deleted 11y ago[deleted]
- ivanca 11y agoI did, it is so abstract to pretend you can do better that there is no way to discern. He didn't even mention "unity" in his post, thats just ridiculous in 2016, but yeah, keep down voting, your implementation of 2d graphics, sound, collision, physics, plugins, marketing, sprites, menus is gonna be so much better than hundreds of engineers at unity withing 10 years straight.
- vardump 11y agoUnity games I've tried seem to stutter often. Any idea why? GC cycles?
- seanwilson 11y agoWith C and C++, you have to be careful you release resources yourself to avoid leaks. With GC languages (besides memory leaks from referencing objects you no longer care about) you have to be careful that you preallocate upfront a good portion of the objects you need and reuse them to avoid GC stutters.
- je42 11y agoGC cycles.
- 11y ago
- lugus35 11y agoI thought Lua was great for games development, the author does not mention it. http://www.lua.org http://www.lua.org
- cookiecaper 11y agoLua is widely used as a scripting layer on top of a game engine. The intense calculations needed to generate a high-fidelity simulation like graphics and physics are usually implemented in the engine in C++, and then the game logic/item behavior/etc. is defined in Lua. I haven't heard of anyone using pure Lua for a whole game, including the engine. It'd be really interesting to see what it looked like if someone did so.
- nunodonato 11y agothere are plenty of games using pure Lua. www.love2d.org :)
- lbenes 11y agoNo, Only the scripting is Lua. The engine is all in C++.[1] [1] https://bitbucket.org/rude/love/src/tip/src/ https://bitbucket.org/rude/love/src/tip/src/
- krylon 11y agoAfter all, that's kind of the point of Lua. Write all of the performance-critical / low-level stuff in C or C++, expose it to Lua, then orchestrate it from a Lua script. Lua's C API is very pleasant to use. As a standalone scripting language, I found it rather awkward to use when compared to, say, Python or Perl. It was only when using it as an embedded scripting language (not on a game, though) that I could really see it shine.
- adnzzzzZ 11y agoWhen using LÖVE you have to write a lot of stuff in pure Lua because LÖVE is a framework and not an engine. So, for instance, if you wanna do AI you have to write everything about it yourself (without calling any of LÖVE's functions because generally they won't help you with this task), and most people will do it in Lua only.
- smegel 11y agoDid anyone break it to him that when he writes C, he is writing C++?
- leksak 11y agoC is not a true subset of C++ so no, when he is writing C he is writing C.
- moron4hire 11y agoGiven he is calling C a strictly typed language, I'm not sure the OP really knows C that well. Sure, it's strictee than, say, PHP. But in the pantheon of languages, it's not objectively strict.
- leksak 11y agoI mentioned this in another comment, as has many others.
- AndyKelley 11y agoThe thing I miss most in C when I don't cheat and use a couple C++ features is templates. Specifically, a dynamically sized List implementation that is type-generic. If you do this in pure C, you have to pick your poison: 1. preprocessor abuse 2. void * 3. multiple redundant implementations of the data structure Dynamically sized lists are used so often, that this tends to be a problem in almost every C project. I wonder what the author's solution is to this dilemma.
- zik 11y agoThe trade-off with templates is much slower compilation times. Often slow C++ compile times can be traced to enthusiastic use of templated types, particularly given that standard types like std::string are often defined as templates themselves.
- jpfr 11y agoJust use queue.h, as do all the BSDs. https://github.com/freebsd/freebsd/blob/master/sys/sys/queue.h https://github.com/freebsd/freebsd/blob/master/sys/sys/queue...
- dottrap 11y agoThere is also STB stretchy buffer, popular with game devs. https://github.com/nothings/stb/blob/master/stretchy_buffer.h https://github.com/nothings/stb/blob/master/stretchy_buffer....
- krylon 11y agoI think it's GPL, so it's not for everyone, but the last time I did something in C, I came across Judy, which is totally awesome for what it does. Apparently, the implementation is complex enough to drive an ordinary mortal like myself insane, but it is hidden behind a very simple interface, and it is blazingly fast. It only gave me problems when trying to use boehmgc, because it does not detect pointers stored in a Judy tree.
- abcd_f 11y agoBAH! 4. The "intrusive" containers, but of course. The one true way to do it in C. For one, you can keep items in multiple containers, all being on equal footing. None of that typical C++ mess, when this list is a primary storage for items, and those maps are secondary indexes, all sprinkled evenly with iterators. Intrusive containers don't own items, they merely organize them, which is exactly the right way to go about it. For two, the actual code for container operations is as abstract and on-point as it gets as it focuses solely on "weaving" items into and out of a container rather than on other things, like de/allocating supporting structures. For three, you get no heap activity when adding/removing items to/from a container. This means that if you already have the items, you can always arrange them into a collection. This also eliminates a lot of error handling code, leading to a simpler code. Obviously, this is not limited to just linked lists. [1] http://www.makelinux.net/ldd3/chp-11-sect-5 http://www.makelinux.net/ldd3/chp-11-sect-5 (
- _ph_ 11y agoThe article mixes up the virtues of a programming language with the quality of the environment. C might very well be the best language in our current environment, which says little about the language itself. One major point certainly is, that it is that good compilers are available everywhere and almost any library can be used from C. There are a lot of historic reasons for that. If he wants strict typing, C is actually much worse than many languages of its time. But it is certainly stricter than Javascript. GCs and gaming are of course a challenge, but with the new GC of Go1.5 and hopefully futher improvements, it might actually become a very good language for gaming, especially if there is a better support with libraries. But if one wants good type checking, a simple language model and fast compilation times, it checks all the boxes.
- dottrap 11y agoThe Google Go team lives in a completely different environment. Their perspective of performance is not the same as a game dev. Go 1.5 stated their goal was 10ms GC latency. A game loop is 16ms for a 60fps game. 10ms is not close to acceptable. Fast for a web server backend, but not fast for a game.
- _ph_ 11y agoI have not experimented with the Go GC under heavy loads yet, but the important points of 1.5 are, that the GC pauses have an upper limit of about 10ms for multi-gigabyte heaps - previously they could be up to a second, and often are much faster (in a game environment with smaller heaps, they might actually as low as 1ms, which would be acceptable). I wrote, that there might be further tweaks required, i.e. having an API to call the GC for a set number of milliseconds. If your code isn't 100% using the time slice for each frame, it could use the remaining part of each time slice for garbage collection, eliminating the need for blocking stops. So, whether Go is acceptable now entirely would depend on some measurements. And if not, could be possibly tweaked. As I wrote, I would rather count this under "environment" where C might still win.
- moron4hire 11y agoIncidentally, all of his reasons that don't misrepresent C are all the same reasons I write games in JavaScript. Mostly, it's about speed of development, understanding, and platform compatability. Performance is good enough and almost always my fault when it isn't. I wish for a strictly typed language, but OP isn't using one, either. I've tried several of the transpilers and have generally found the workflow lacking in one way or another.
- seanwilson 11y agoDid you try Typescript? I'm curious what you thought of it for games if you tried it. I enjoyed using Cocos2D JavaScript bindings for cross-platform game development.
- moron4hire 11y agoFound it difficult to integrate with existing JS, such as THREE.js. Also found it difficult to create libraries (I make a RAD workflow for VR apps) that could be used in arbitrary JS projects; I want people to be able to drop my concatenated script into their page with a script tag and not have to worry sbout anything else. Also, early on I ran into quality issues with the 3rd party type mappings for popular libraries, and eventually decided it wasn't worth the hassle. Generally speaking, gradual typing doesn't get me excited. I don't think there is a payoff to having some of your code statically typed and others not. The mismatch between the two causes problems. So TypeScript, et al are an all-or-nothing proposition, and there were big chunks in my workflow that prevented it from being "all". If you choose to embrace dynamic code, you can write less of it and minimize your surface area to bugs. I'd prefer static checking and more code because of stricter typing, but dynamic can be done well in its own right if you approach it at a much higher, metaprogramming level. Don't half-ass two programming styles. Whole-ass one. I also missed the fast-reload workflow of native JS. I sometimes live-edit code in the browser, and being able to go back and forth between the two with no hiccups is nice. So while a lib layout e.g. THREE.js is "old", it at least works without major machinations on the most systems for the most implementing developers. I might start using more ES6 features, as I could use native browser support in my browser of choice for development and a transpiler to pack up packages for deployment. But I won't be going to a language that gets between me and the browser. Contemporary webdev workflow is designed for either A) automated setup and execution of scripts in remote, headless environments or B) getting beginners gluing libraries together quickly. These are frequently not the same thing as a great developer experience.
- leksak 11y agoIf by "strict typing" you mean strongly typed then you are factually incorrect. By virtue of casting C is weakly typed, as is Java, C++ et al. If your understanding of strict typing is statically typed, i.e. that types are checked at compile time then C still has some flaws as you could write a whole slew of C that is "typeless" using void * although that would be terribly misguided. I understand your intent, but I dislike the ambiguity of the phrasing.
- JDevlieghere 11y agoAs Dennis Ritchie once said "C is a strongly typed, weakly checked language."
- masklinn 11y ago> By virtue of casting C is weakly typed, as is Java, C++ et al. Java's casts are dynamically checked, memory-safe and only work through the inheritance hierarchy, if you try to cast to an invalid type you'll get an error. Putting it in the same class as a C-style cast makes your usage of "weakly typed" as meaningless as it ever is. For C++ — ignoring C-style casts — it depends which cast you use, dynamic_cast requires RTTI but IIRC it offers the same guarantees as Java's cast; static_cast should check that the types are related and the conversion is valid at compile-time, reinterpret_cast is the "weakly typed" one (essentially a simpler version of a C-style cast). > I understand your intent, but I dislike the ambiguity of the phrasing. Yet you use the expressions "strongly typed" and "weakly typed"?
- Rusky 11y agoThere's also a valid distinction to be made between weak typing through implicit conversions and weak typing through reinterpret_cast. C++ has both unfortunately, but the second one is often necessary for a low-level language.
- antaviana 11y agoDelphi compiles extremely fast, is strongly typed, no GC, has templates, objects. Too bad Embarcadero positioning towards Enterprise with its relatively high pricing effectively derailed it as a mainstream language and killed its community.
- egonelbre 11y agoAnd doesn't have console support (AFAIK).
- clouddrover 11y agoIf iOS and Android devices count as consoles (and I think some of them do) then Delphi has console support. :) Free Pascal (http://www.freepascal.org/ http://www.freepascal.org/) says it supports the Nintendo GBA, Nintendo DS and the Nintendo Wii (to what extent and how well I don't know, never tried it). It also supports Win32, Win64 and FreeBSD so I suppose it could be made to work on the PS4 and XBox One without too much trouble. A real strength of Object Pascal is that it can be as low level (inline assembly, manual memory management, etc) or as high level (OOP, generics, etc) as you like. It satisfies most of the article's wishlist items. Today I happened to find a simple but still interesting programming language feature matrix on Ian Hixie's website: http://ian.hixie.ch/programming/ http://ian.hixie.ch/programming/ He'll have to update the Execution column for Free Pascal to be both "Native" and "VM" since Free Pascal 3.0 can now also compile to JVM byte code: http://wiki.freepascal.org/FPC_JVM http://wiki.freepascal.org/FPC_JVM
- krylon 11y agoWell, there is FreePascal and the Lazarus IDE which appears to have been built by rather enthusiastic fans of ObjectPascal and the Delphi IDE. I tried to use it when I took over maintenance of a Delphi application developed in-house, because I had no prior experience with Delphi or Pascal. Both FreePascal and Delphi felt very, very similar to ObjectPascal and Delphi. Unfortunately, Lazarus crashed on me a lot both on Linux and OS X, so I gave up on it rather quickly. But it might work better on Windows.
- Ace17 11y agoSimplicity of a programming language, and simplicity of programs written in it are two very different beasts. I understand funny things happening under the hood (garbage collection) might not look attractive ; However you can't require everything to be explicit and, at the same time, keep your programs simple/small. The more you want your code to be small, the more you're gonna need a programming environment (language/API/runtime/framework) doing things for you under the hood. And there's nothing wrong about it!
- sebcat 11y ago> The more you want your code to be small, the more you're gonna need a programming environment (language/API/runtime/framework) doing things for you under the hood. And there's nothing wrong about it! Or have your code do one thing and only one thing, a single purpose, with clear, well defined interfaces and then compose things doing only one thing to a bigger thing that you can reason about more easily because the interfaces and processes are well-defined. One thing I've seen too much of in my professional life is complex projects trying to do too much, with ill-defined roles and implicit, poorly documented interfaces. Simplicity of a language works well as long as your projects are kept simple. You can build fairly complex solutions by composing multiple simple projects with well defined interfaces. I think we agree that simplicity of a language works less well when the scope of a single project is too large and too arbitrarily defined.
- oilywater 11y agoStatic typing and C. C is very simple and it's missing a Hindley-Milner type system. If that was a part of it, I'd use it. C++ wins now, every time. Type safety in C is a pain.
- je42 11y agono auto in C. no standardized data structures. no lambda. no exceptions. and C++ still compiles actually fast. at least on my machine.
- lmedinas 11y agoFor years developers used C++ without most of these features and built great code. So this is not the problem of C. There are still lot's of great code done in C.
- je42 11y agoReally ? Look at this code: https://github.com/danfis/libccd/blob/master/src/ccd.c https://github.com/danfis/libccd/blob/master/src/ccd.c Looks like great C code doesn't it? Still you see lots of plumbing: 1. call of init functions 2. unsafe array/pointer usage 3. goto I rather use C++'s functional constructs rather than the imperative ones. It is less code, that directly self-explains the business logic; instead of being littered with (unsafe) plumbing code. And IF I find a performance bottleneck - I can still opt to use/develop an unsafe lowlevel version.
- shurcooL 11y ago> The library support [in Go] for games is quite poor, I'd like to know the author's familiarity of Go libraries. Perhaps he's unaware of what does exist and makes false claims, or perhaps he's saying accurate statements and just has really high standards. I help maintain many of the Go libraries/wrappers for games, so I might be biased, but I'm happy with what is available. Almost more so than when I was using C++, because Go packages can be made go-gettable and very easy to include and distribute, unlike with C++. I've also not hit GC problems so far, but arguably my games are just not demanding enough yet.
- synthmeat 11y agoI'd like to pick your brain in real-time, but, in a nutshell, how far do you think Go game ecosystem is from something like Corona, LibGDX, Haxe? Have SDL, OpenGL wrappers stabilized, are there native ports? Any frameworks that might be considered close to production-ready?
- shurcooL 11y agoOpenGL libraries have definitely stabilized and have been that way for multiple years now. GLFW 3 wrapper is go-gettable (some years ago, it required manual installation of the C library separately, now you just go get it). I don't use SDL so I don't know much about it. I don't know if there are complete frameworks or engines that are finished, but there are some works in process. https://github.com/avelino/awesome-go#opengl https://github.com/avelino/awesome-go#opengl https://github.com/avelino/awesome-go#game-development https://github.com/avelino/awesome-go#game-development
- claystu 11y agoCan you point to some blog posts on this subject? I would love to see what's out there.
- shurcooL 11y agoLibraries and wrappers here: https://github.com/avelino/awesome-go#opengl https://github.com/avelino/awesome-go#opengl https://github.com/avelino/awesome-go#game-development https://github.com/avelino/awesome-go#game-development I'd also suggest looking over https://www.reddit.com/r/gogamedev https://www.reddit.com/r/gogamedev.
- SunShiranui 11y agoI don't share some of the needs the author has, however, for game development, I like to use Haxe. Mainly because it allows for very easy crossplatform development (to both PC and mobile OSes)
- sklogic 11y agoWell into C++14, but yet this outdated myth of an unbearable "complexity". This is not the language you knew.
- Rusky 11y agoC++11 and 14 make it possible to avoid or ignore much of the complexity of old-style C++, but they also introduce plenty of complexity of their own and they don't deprecate any of the old stuff. It's not a myth.
- sklogic 11y agoYes, but now you can safely use a nice and clean subset without ever touching any dark corners.
- hellofunk 11y agoThere are a few new dark corners in modern c++ ... Enough to inspire Scott Meyers to fill a new book of advice just for the new idioms. C++ is powerful but complex no matter how you look at it.
- dom96 11y agoHow about Nim? [1] [2] To me it is in many ways a "nicer and safer C". Sure it's not as mature as C, but what is? What it does have going for it is portability (it compiles to C so it shares C's portability), a soft real-time GC which can be manually controlled [3], generics, AST macros and much more. 1: http://nim-lang.org http://nim-lang.org 2: https://github.com/nim-lang/nim https://github.com/nim-lang/nim 3: http://nim-lang.org/docs/gc.html#realtime-support http://nim-lang.org/docs/gc.html#realtime-support
- vidarh 11y agoI can't speak for the article writer of course, but the Python-like syntax / significant indentation would be a deal-breaker for me. I'd suffer through a lot to avoid that. And back when I used C a lot myself, I found that even more objectionable. I often care more about syntax than many other language features - with a good syntax you can sugar over a lot of other deficiencies, but a syntax you dislike will stare you in the face every moment you use the language.
- dom96 11y agoI am in some ways the same, but the other way around. I like Python-like syntax more than C-like syntax. But not to the same extreme as you, I wouldn't mind using a language with a C-like syntax. What are your reasons for disliking Python-like syntax?
- vidarh 11y agoI want strong visual cues for the end of blocks most importantly. And I want the freedom to adjust indentation in ways that to me improve readability without consideration of whether or not it matches language expectations. But also because I've yet to work in any environment where broken indentation due to tools with different ideas about how to handle it has not been a regular occurrence - indentation is brittle.
- lobster_johnson 11y ago
- johnydepp 11y agoI write games as well (Written more than 10 games, though they are not very large at scale) and I write them in C++. Reasons being writing networking code (TCP/UDP) is much easier & efficient in C/C++ than any other language IMHO. And most of the code works across platforms.
- seba_dos1 11y agoJust my 5 cents: Although there's nothing wrong with it in the context of your comment alone, C and C++ are so distinct languages it's weird to see them aggregated as "C/C++" given that the article is about C and it explicitly recognizes C++ as a bad alternative.
- johnydepp 11y agoThe article doesn't say C++ is a bad alternative. Just that he did not use it to avoid complexity. And yes C and C++ are distinct. But the simple modules can be written in C, but the bigger ones need OOPS, so generally written in C++.
- ArkyBeagle 11y agoI'd look at the metaphors Tcl uses for at least TCP - UDP is a separate library, curiously enough. This one feature had kept me using Tcl for a long time.
- holografix 11y agotl;dr overly comfortable, old school C developer is still worrying about the death of flash and hanging on to what he knows. Finds reason why he shouldn't step out of his comfortable zone.
- fsloth 11y agoUm, "fast compilation", "hotloading dll:s", "future proof" are all to me valid and non-trivial technical requirements. Also - there are better languages than c for lots of things but there is a class of problems (like efficient and correct numerial code) where c is as good as any language "in the same category" (unless one counts fortran)
- cies 11y agoBecause he claims that reducing the possibility for bug is a main concern I feel two languages, in his nicely written write-up, are left out: Rust -- low-level like C, fast like C, more modern than C, specific ways to reduce categories of bugs (borrow checker), promotes a more functional way for programming Haskell -- not as low-level as C, but pretty fast (best possible performance was not his main concern), many ways to reduce categories of bugs that can arise For game dev't you'll find both have maintained bindings to SDL2.
- fsloth 11y agoHow is the Haskell stability nowadays? Simon Peyton Jones joked at one point that Haskell is not meant for production from the point of view that they are tinkering with it constantly. At some point the Haskell landscape looked like the GHC core and an endless desert of abandoned projects (which imply strongly it's not as good towards the librarys purpose as some other language).
- Kenji 11y agoI have worked with GHC for more than half a year and never encountered any compiler bugs or instabilities. Haskell is surprisingly solid. That being said, Haskell is not well suited for things like games. It's just not the right paradigm. Some people may disagree with me but the fact that most games (and also other programs) are not programmed in Haskell speaks for itself. Haskell is a fun and playful (and also difficult) language but I'd never start a large serious project in it again.
- chii 11y ago> That being said, Haskell is not well suited for things like games. It's just not the right paradigm. is that really true? i feel like a game ought to fit into a functionally pure paradigm much better, because a game should really only depend on player input, and that can be modelled much easier as RenderIO (WorldState b -> PlayerInput a -> WorldState b) , but not having actually written any, this is just my assumption...
- cLeEOGPw 11y agoI see one of the core reasons C is chosen over C++ is the speed of compilation. My question would be, to what extent is compilation speed relevant? What time differences are we talking about? I agree that every second counts, and I understand that fast compilation just feels good to work with for a hobby project, but what serious relevancy it has? At least the way I do it is divide program (a game for example) into several projects and compile them into dll's, this way compilation time is drastically reduced and with a side benefit of clear separation of different parts of the program.
- loup-vaillant 11y agoMost C++ projects I have worked with, regardless of their size, had re-compilation times that routinely exceeded 20, sometimes 30 seconds. There are various reasons for this, among which uncontrolled use of templates and nested header inclusions where a forward declaration would have sufficed. C, with its simpler grammar and the absence of template, tend to re-compile under 5seconds even for sizeable projects.
- cLeEOGPw 11y agoSo, roughly speaking, you can expect for a difference in the order of tens of seconds. But my question was, how relevant is this? At least in my experience, and I have worked with projects that took up to 50 minutes to fully recompile (before we moved to newer ms compiler) when taking all dlls, the full recompilation is rarely required. Sometimes you have to recompile project, which can take minute or so, but most often you do incremental compilations that barely takes a second. So for me it's hard to imagine compile time having considerable impact on delivery. Most of the time is used while reading the code and thinking how to solve a problem, not typing the keyboard and waiting for compilation to finish. And I would argue that properly written C++ can greatly improve the biggest part of work - reading and understanding the code. I admit that properly written code is not a given etc., but for personal project you can write however you want. In the end it's probably more personal prefference and how confortable you feel rather than strict rational choice. I think both C and C++ are very close calls, especially considering all the other choices there are.
- petke 11y agoYou don't really get rid of complexity by using a simple language. You just move the complexity into your own code. Say if your language doesn't have dynamically sized containers, you will end up writing your own. You hack it so you can store different types in it. You have reinvented polymorphism. And then you need sort functions, and everything else that is missing from the language. And it wont be simple any more. Probably slow and buggy too. But you are not alone. Everyone has their own private code framework that is too complicated for anyone else to make use of. If only there was some way to avoid this mess ...
- fennecfoxen 11y ago> their own private code framework that is too complicated for anyone else to make use of Well, to be fair, games are one place where code reuse and maintenance by third parties is less likely to be needed. The real sadness is when you get corporate websites, technology platforms, and the like that decide they need their own framework to make their own set of tradeoffs, and do a mediocre job of it, and end up with a slow buggy bastardization with 15% of the capabilities of a common well-understood framework. If I had a dollar for every minute I wasted on something like that... it'd be an accurate description of a nontrivial portion of my career :b Bonus points for making this framework to optimize performance, without actually measuring the performance or setting explicit goals.
- chii 11y ago> Well, to be fair, games are one place where code reuse and maintenance by third parties is less likely to be needed. i feel like this is somehow perpetuated like folklore, but there shouldn't be any reason why game code should be inherently less reusable than other areas of software development. For example, code that deal with geometry data shouldn't really be any different for games, or code that deal with setting up a rendering environment ought to be the same for most, if not all games (i can't imagine initializing directx or opengl would be different for different games). Game logic is one area that is going to change a lot between games. However, if you partitioned your game logic well, wouldn't it make the next game easier since you're "just" swapping game logic?
- rootw0rm 11y agoJust mix C and C++ like a regular horrible person would do. An entire game in C sounds....tedious.
- hellofunk 11y ago>Even more than that I care about the speed of the compiler. I am not a zen master of focus, and waiting 10+ seconds is wasteful, yes, but more importantly it breaks my flow. I flick over to Twitter and suddenly 5+ minutes are gone. Quick suggestion, has really helped me: take that 10 or 20 seconds waiting for compilation, and stare out a window. This gives your eyes much needed break from focusing on a computer monitor, allows the muscles to refocus and breathe, and doing this regularly during a coding session can have important long-term benefits for your vision.
- hvs 11y agoA "focus" application (there are many for macs/pcs) that block certain websites, applications is also helpful. You can set it for an hour at a time, or whatever. It breaks that knee-jerk habit of wasting minutes on twitter/news/etc.
- hellofunk 11y agoStill better to not look at a computer at all frequently, and focus on something in the distance.
- Grishnakh 11y ago>Quick suggestion, has really helped me: take that 10 or 20 seconds waiting for compilation, and stare out a window. Wow, that sounds pretty nice. I wish I had a window to look out of.
- coldtea 11y agoOr you know, just look away from the monitor, in the physical space of your office/whatever instead of a flat surface, which would have similar benefits.
- JoeAltmaier 11y agoSo many office spaces are rectilinear and planar. I find the fractal real world to be so much more restful to look at. It refreshes my mind in a way unlike any manufactured surface.
- Kenji 11y agoI wanted to program my game in C but then I took notice of how incredibly comfortable things like Vector and Map are. I never look back again. C is for plain libraries and OS where compatibility and performance are of utmost importance.
- hellofunk 11y agoSince game development often requires interfacing with robust C++ libraries in graphics or physics (i.e. Bullet), I'm curious how you do that... are you either not using physics or writing your own basics physics engine? Or, are you writing parts of your app in c++ just to wrap the interface in a way you can do the rest of the work in C?
- krakensden 11y agoI don't know about game libraries in particular, but in general, it's pretty common for C++ libraries to ship with a C api, and for most non-C++ languages to use that as the basis for their integration. It looks like several (https://code.google.com/p/bullet/issues/detail?id=43 https://code.google.com/p/bullet/issues/detail?id=43) people (https://github.com/bulletphysics/bullet3/issues/130 https://github.com/bulletphysics/bullet3/issues/130) have written C apis for bullet already, for that reason. Vala, .NET, LuaJIT and Rust all get mentioned.
- rhodysurf 11y agoIts trivial to expose a C interface from C++ and I would guess most game libraries have an api
- hellofunk 11y agoIt's not as trivial as you would think. I'm reading through the long discussions from the Bullet developers, and clearly it's not just a short project.
- swah 11y agoThis is exactly what Casey talks about on handmade hero.
- weavejester 11y agoAre GC pauses really significant? I can understand there being problems if you have to churn through gigabytes of world data, but the author's games don't appear to be on that scale.
- Narishma 11y agoTheir unpredictablity is a bigger concern than their duration when it comes to games.
- 0xcde4c3db 11y agoThey often are if specific care is not taken to minimize garbage in the game loop, particularly in resource-constrained environments like some console and mobile platforms [1]. In GC languages, this often means deliberately avoiding common idioms that perform allocation under the hood. The threshold for a noticeable pause is much lower for action games than it is for general applications. 100ms is often used as a rule-of-thumb "instantaneous reaction" threshold for general UX [2], but that's a lot of time to a highly competitive player (e.g. this guy playing Super Punch-Out blindfolded [3]). In fact, in high-reliability real-time software, even non-GC heap allocation is often avoided (or done once at startup and then left alone). Heap allocation is not a very predictable operation beyond "probably fast enough". [1] https://stackoverflow.com/questions/5063190/game-jitters-on-xbox360 https://stackoverflow.com/questions/5063190/game-jitters-on-... [2] https://www.nngroup.com/articles/response-times-3-important-limits/ https://www.nngroup.com/articles/response-times-3-important-... [3] https://youtu.be/vSr3aXd4XuQ?t=358 https://youtu.be/vSr3aXd4XuQ?t=358
- weavejester 11y agoI can see that you'd probably have to take care on mobile and older platforms, and with resource-heavy games. But I have difficulty imaging that there'd be much issue with anything else, as long as the code wasn't overly terrible. Do you happen to know of any benchmarks, or non-anecdotal evidence?
- davexunit 11y agoLike in any program written in any language, you want to minimize allocation. People love to play the garbage collector blame game.
- Tistel 11y agoC++ compile and link time. I once worked on a PS3 game that had a 50 minute turnaround time (change code -> compile -> link -> load). No scripting either. The horror. It was because the company had home brewed a bunch of "optimizations" into the build process. On the up side it will force you to learn to live edit the game with the debugger to tweak and adjust. If its C++ and the programmers know the engineering KISS adage it can be ok. I have seen so much horrible needlessly complex C++. So bad you are pleasantly surprised it runs at all. C++ so bad and unpleasant to work on it makes you question why you are a programmer at all. sigh Then you write some python, C, ruby or lisp (or scheme, or clojure) and your like: "oh, now I remember why i do this again, this is so much fun!" I like the simplicity of C too. You can have a good mental model right down the CPU of what is going on. But these days given how fast CPUs are and how much more productive you can be in a high level language (python is 10x more productive than C++, apparently) I think a garbage collected high level language is the way to go. If I accept their offer, my next job will be using Golang.
- je42 11y agoDon't mix language features with engineering mistakes.
- Tistel 11y agoOh, I agree. Its not the language's fault. You can write a good or bad program in any language. No language can save you on its own. But, as the expression goes: some programming languages give you enough rope to shoot yourself in the foot, other, enough rope to blow off the whole leg. I have done C++ for 14 years. It can be great and fast if you are careful.
- JoeAltmaier 11y agoI use C++ because of the leverage. It automates so much that folks do by hand in C. Like a power tool vs hand tools. I know, lots of folks are nostalgic for handmade crafts using only simple tools. But I'll never go back.
- 11y ago
- BatFastard 11y agoFlash is not dead. It's the ONLY plugin left that works in all desktop browsers, and works on Mobile phone. Facebook supports it, more and more who have started in HTML5 have lived to regret the day. For many years I was a C++ snob who totally dismissed Flash, but now I really enjoy actionscript I am working with a client who is write a phone app in Flash because of the low level cross platform abilities and it is awesome! It also lets me build web based admin tools for the backend really quickly. Only negative thing I can say about it is the garbage collection is slow...
- mikeash 11y agoFlash doesn't work in most installations of desktop Safari, nor does it work on iPhones. Many others are fleeing it because of massive ongoing security problems with it. If you're content with the audience that remains then great, but it's far from "all."
- BatFastard 11y agoFlash has many colors now, on mobile phones its called Adobe AIR. And it just won the mobile tech of the year award as CES.
- kilon 11y agoC is super slow when it comes to compiling, if you really want fast compiling take a look at Pascal, around 10 times faster the last time I checked. There is Free Pascal that is open source and also has a great IDE called Lazarus. Both much better as a language compared to C and C++ and still close to their speed.
- hjek 11y agoAbsolutely amazing games on the webpage, especially Knossu, a "A non-euclidean horror game." Crisp and trippy graphics and sounds. Good gameplay, no "installation" required. But running a closed-source binary can be a bit sketchy; whereas you don't have to trust a publisher to the same degree running a game in the browser.
- drawkbox 11y ago> I can't afford to spend my time dealing with bugs I didn't cause myself It is very frustrating to deal with bugs introduced by others, a product or engine changes that you aren't aware of. But you have to balance that with how much you can get done in your own engine/tech with the time wasted from bugs, and how much time you want to spend on tech vs games. For 2D games, building your engine is probably doable with lots of small kits like physics libs (box2D, bullet, etc), libgdx, sdl etc but for 3D games and certain titles, a single person working on an engine is difficult, tons of work on the tech side. So the balance is key, whatever makes you able to ship more often is probably the best choice. Unity is used by many people and does have very frustrating releases that aren't solid many times. Recently 5.3, 5.3.1 [1] all have issues. For a long time in 2015 the IL2CPP iOS versions were broken. But doing it alone you get caught in a tech swamp instead of making games if you aren't careful and limiting. There will be times where your engine product or team or yourself is wading tech changes that are needed and take time away from game making. During the period of IL2CPP and Unity bugs, games could still be developed in parallel and for other platforms, so this is a benefit even though there are bugs. Even when we do engine or platform based games it is a good idea to keep it as platform agnostic as possible. In Unity this might be keeping all source assets, using less MonoBehaviours, storing/loading data in JSON/web formats rather than in serialize prefabs. Anything that locks your game into one engine too much one should be careful of to limit your surface area of exposure to bugs by the engine. For a long time other UI libraries ruled Unity before they made their new UI, it is still a bit buggy but better. For a long time Mecanim was not very solid and many still use legacy animation. The newer Shuriken particle systems are awesome but not as accessible in code and had scale limitations for a long time. You just have to see where areas are solid and not venture into areas prone to bugs in your own engines or existing engine platforms for shipping games like Unity/Unreal etc. [1] http://forum.unity3d.com/threads/unity-5-3-1f1-particle-system-errors-invalid-aabb-result-isfinite-d.374926/#post-2432662 http://forum.unity3d.com/threads/unity-5-3-1f1-particle-syst...
- bproctor 11y agoThe language wars get exhausting. Several years ago Ruby was the coolest thing ever, now I guess people think it's just boring. Also, PHP got really unpopular and all you heard about was how it would kill your dog and sacrifice it to satan. Now days it's still cool to look down on those who use it, but you shouldn't talk about it. Don't know know all "real" devs program in Python? Go was short lived, a year or two ago it was the greatest thing ever and now all you hear about is how much it sucks. The latest trendy thing is Rust. Rust is our new savior. I wonder how long that will last before something else comes along as the coolest thing ever. Maybe Brainfuck for it's simple syntax?
- cdelsolar 11y agowho says Go sucks?
- Mikeb85 11y agoHe mentioned a bunch of languages, and I'm not sure why he doesn't look into something like Kotlin. It's the JVM so you get maturity and it's fast as hell (ran a few economics-related benchmarks on my machine, OpenJDK 8 beat both C++ and Fortran!), has great IDE support (Intellij IDEA - which will actually translate Java into Kotlin if you want to translate snippets), and it doesn't strong-arm you into an OO style. And of course Lwjgl 3 is written mostly in Kotlin. If he liked Flash, I'm also surprised he didn't go with Haxe. It's fairly mature, is a very nice language (Swift looks like it was mostly ripped from Haxe), with OpenFL he gets the Flash API (but can also compile to native or JS), and of course Haxe also has other frameworks available, or can even be used with native frameworks quite easily. Anyhow, as far as C goes, it's a decent enough choice. It's simple enough, if you don't mind writing helpers for various tasks and building your own libraries then why the hell not. I definitely prefer the typical C style of programming to the prevailing C++ style.
- krat0sprakhar 11y agoI've been meaning to get into Kotlin and building a game sure sounds like fun. Are there any Kotlin specific game programming frameworks (or any other resources for that matter) that you'd recommend?
- Mikeb85 11y agoWell Kotlin is basically a drop-in replacement for Java. You can literally create a Kotlin project in Intellij IDEA (Community Edition), drop in some jars (and compiled native lib if required), and you get full completion to every class, and everything 'just works'. So the obvious choices would be LibGDX and Lwjgl 3 (which is written mostly in Kotlin). As for tutorials, it's close enough to Java that you can rewrite anything pretty much word for word (albeit with a slightly different syntax), and there's a Java -> Kotlin translator in IDEA. It keeps the semantics very close to Java, but with some sugar and niceties. It really is the 'Java replacement' that languages like Scala and Ceylon attempted to be.
- ZoFreX 11y agoMaking games on the JVM is a lot of fun, but the garbage collector does limit what you can do (the OP mentions this as one of the drawbacks of Go).
- jokoon 11y agoTo me lambdas justifies using C++ while still coding in a C style. Although my wet dream would a C language with map, vector and other containers, a simpler build system (no more headers), more nice syntactic sugar, and an interactive mode... I'd gladly see a language that break C compatibility for this.
- dottrap 11y agoSwift might hit all your bullet points there. It breaks from C compatibility, but it has really impressive C bridging/interop.
- mpdehaan2 11y agoI've had this thought quite a few times. Basically, if you want your software to last and work on lots of platforms (particularly if it is a game you put a lot of love into), using a lot of dependencies you worry about it. I know I've written some things - not even games, that would be a major chore to port. But C and OpenGL APIs are still going to be there, and there's a nice feeling of quietness when it's just you, libraries you know are going to be stable, and the code, and not having to wonder "is this fully baked?" or "which one of these libs is the best". You can almost get paralyzed in finding the ideal tools and libs to use and keeping up with all of them. Whereas if you limit yourself to just what comes with the language (and maybe a few small things) a side project can be a lot more fun. A side project is also often about the journey, not the destination, and people can get a lot of mileage out of building incredibly complicated weird things that not many people will know are even there (I don't really know how to play Dwarf Fortress and don't play it, but the idea of the history generator, terrain generator, and so on... all that runs before you play the game strike me as great examples - the kind of thought that this is incredibly impractical and therefore must have been a ton of fun to write)>