Hacker News new | ask | show | jobs
by karmadog 3270 days ago
There's two big hindrances for success right off the bat:

1. Refusing to just use C/C++

2. Attempting to support most of the platforms

Both problems compound each other.

All platforms (even Android at this point) have C APIs for everything you need. Creating another layer of abstraction here causes more work and overhead.

Trying to get Java running on iOS with 3D APIs is a huge task in and of itself. The same goes for C# (a task which Unity does for you). Languages that require JIT for performance don't work on mobile (unless supplied by the OS, e.g. JavaScriptCore). Debugging becomes extra-difficult.

C/C++ are not convenient to use, but not hard to use either. It causes discomfort at first, but you get used to it. Being forced to do memory management manually also helps with learning how to structure programs, with a bonus of not having to wrestle GC pauses.

Having said all that, using a commercial engine is totally fine, of course.

4 comments

> Being forced to do memory management manually

It may be worth repeating that in C++ the need to manually manage memory is drastically reduced compared with C (due to the native support of the RAII pattern).

I refuse to use C/C++. If that's what I have to use to make games, I just won't make games. Fortunately, there are other languages available with a C FFI.

I don't think forced memory management teaches anyone much of anything besides how to manage memory manually. It doesn't make programs better. I'm very grateful for garbage collection so that I can spend my cycles thinking about the problem I'm actually trying to solve.

edit: I think this came off a bit too dismissive, but I guess what I was after is that what technology you choose depends on what you value. Personally, I value using programming languages that are pleasant to work with, and I don't personally find C/C++ to be pleasant. I enjoy dabbling in game development, but it's not so important to me that I would use tools that I don't like to do it.

>what technology you choose depends on what you value

No, what technology you choose depends first and foremost on what you want to achieve. If you want a to run a realtime application on as many platforms and devices as possible with steady fps, a GC language is not the technlogy you can use.

In contrast, you can write web applications in almost any language with little technical differences. That's the point where you can start to make a value assessment.

>It doesn't make programs better

Yes it does. With a GC you lose control over runtime, which is crucial to the performance.

I'm not advocating against GC in general. Many desktop apps, most web apps and low-tech games can be fine with it. But saying manual memory management is outdated, when our 4 GHz Multicore machines struggle to run smoothly is ridiculous.

>No, what technology you choose depends first and foremost on what you want to achieve.

Maybe for you. But not for me. I find the rest of your post to be very mean spirited.

I don't work in the games industry because those constraints sound miserable.

First of all, I'm talking about game engines, not games. Both Unity and the earlier Unreal Engine (afaik) used GC-ed languages for scripting.

However, if you want to make a quality game, you can not afford long GC pauses. I know that lots of people make games with GC pauses in them anyway. It is a value judgement, for sure.

It's certainly possible to work around GC pauses, but that effectively means you are manually managing your memory manager (instead of the memory), which can be surprisingly difficult.

It's also possible that whatever you do is so "small" that GC pauses never affect you. Enjoy your free lunch then.

Even if there was entirely non-stop GC (e.g. through reference counting) it's still wouldn't be a good choice for games since a game is, essentially, just a neatly arranged data structure in memory. Compared to the amount of memory a game reads/writes every frame all other I/O channels are just noise. You actually want to manage your memory instead of trying to figure out how to force a foreign memory system to do what is best.
Some of the work done to work around GC feels similar to the work you'd do in C/C++ to work around memory fragmentation issues. Also, depending on the language/runtime, you might be able to influence the GC algorithm, or at least the frequency with which it runs. If you can e.g. run a GC every second for not longer than ~1 frame, then pauses won't be noticeable.
A dropped frame is always noticable. What you can do is keep a budget for GC and then force-collect every frame.
Used to have a hard time with C, but after working with it for some time you might get to appreciate what computers do more. I oddly find C pleasing, and choose it to solve many problems by default.
I've spent enough time writing C to know that I want to minimize my time spent writing C. It's been an important language to know for dealing with foreign function interfaces, but I work almost exclusively in high-level, memory safe languages now. I'm much happier and my programs are much less vulnerable to exploitation.
I think C is pleasing because the program does nothing that you don't explicitly tell it to do, and because just about everything that you can tell it to do maps clean(ish)ly down to the machine language that implements the equivalent code. It's possible to know exactly what's going on, and when.
1. Refusing to just use Assembly.

Was the reply we got in the old days, when one used C, Pascal, Basic, Amos.

Thankfully many ignored that and moved the state of art to such languages.

A few years later the reply would be,

1. Refused to use C

When devs tried to use C++ or Delphi.

State of the art in games development only advances thanks to those that manage to produce entertaining games, while ignoring such advices.

I don't really feel like this is a fair statement if you have done any game engine related development. Even 'writing from scratch' is still gluing together a whole soup of libraries and many of those libraries are C API only. Fonts? Use freetype. PNG's? use libpng. COLLADA? Audio? Audio files? Input? OpenGL/DX?

As soon as you say you are throwing out C/C++ you better have amazing alternatives that make sense for the language you are working on. Games are large enough projects with broad enough scope that if you don't have a language that works well with a bunch of external libraries you are immediately in the weeds once you end up with a problem that isn't covered by what is already available. If you find this out too late in the project (especially in a hobby/side project) this can be a death knell.

This is a constant problem in game engines or other large frameworks- once you get off the rails in a significant way all your development time is going to making that kludge work. If you are using a language that is just wrapping C API libraries often a lot of this development time is just fixing the wrappers to the actual library instead of getting anything done.

If you know the end product is 100% covered by a game engine you can save all the game engine development time and the kludge fix time all at once. I had written a whole tutorial series based on XNA for instance because it was easy to demonstrate the concepts I wanted to share, but when trying to start working on a particular topic I realized the engine's limitation and it all went to hell and I had to scrap it.

A growing number of languages are ABI-compatible with C. A small but significant subset of those languages is ABI-compatible with C++. Quite a few languages (Perl 6, Julia, Tcl w/ critcl, pretty much everything that uses libffi AFAICT) are able to do this without having to write full-blown wrappers for a whole C/C++ library (though you still need to wrap specific functions in most cases).
Julia JIT compiles C calls via LLVM, so there's no libffi performance overhead (similar to LuaJIT's CFFI, though that does not use LLVM).
Neither does Tcl's critcl AFAIK (I think it just sticks the C code in a Tcl extension and compiles it using the system compiler). My intent there was just to list cases where wrapping a whole C/C++ library is unnecessary, not to imply that Julia uses libffi :)

On that note, LLVM helps a lot here, too. Are there any LLVM-based languages that don't have some degree of C compatibility?

Parse error on my part, excuse the pedantry :) Tcl is such a weird and wonderful language, and I occasionally miss it (though I don't miss working with a GUI written in C++ wrapped around tk).
On a past life I used to be an IGDA member, attended GDCE a couple of times, and knew personally developers working in a few European game studios, until deciding boring IT work was a better way to make a living and enjoying life.
Game developers used Assembly to write games when it was the best tool for the job. They then moved to C when it was feasible and then to C++ when that was feasible. For their engines, they never moved on to anything else, because there still is no better tool for the job, all things (tooling, SDKs, platform support) considered.

Unity, Unreal Engine and CryEngine are all written in C/C++. They have sometimes elaborate script bindings, but the engine remains in C/C++.

There's a lot of people leaving college that have never learned how to use C/C++ and immediately they want something they're comfortable with, which is Java/C# or Javascript or maybe even Python. These languages are not good choices for a game engine, for the reasons I mentioned. Will there never be a better language? I did not say that, but it would be an uphill battle.

Usually game developers changed language when the OS or game console's SDK release forced them to do so.

> These languages are not good choices for a game engine

I have seen these words written against C, Turbo Pascal, Modula-2, C++.

Some of the games I saw "written" in C for MS-DOS were like this all over the place:

    void my_func(void)
    {
       asm {
         /* 100% of my_func actual code */
       }
    }

Just as if C was a macro assembler.
SDKs never forced anybody to move to C or C++, but the opposite is true: C/C++ compilers were either unavailable or limited.

"I have seen these words written against C, Turbo Pascal, Modula-2, C++."

So what? Those words probably had a good argument behind them, at the time.

In the MS-DOS days, compilers weren't as good as today, so handwritten ASM paid off.

> So what? Those words probably had a good argument behind them, at the time.

> In the MS-DOS days, compilers weren't as good as today, so handwritten ASM paid off.

Just like C compilers had enough money spent into their optimizers, that eventually made them competitive against Assembly, so can C#,Go,D, <whatever language> have enough work placed into them, that eventually they will become competitive against C.

People believed they could make C competitive against Assembly, just like they believe they could make C++ competitive against C.

So it is a matter if one wants to believe and lead, or don't and follow.

If <whatever language> makes certain assumptions and guarantees on behavior, then no, belief is not enough. It has to be plausible. GC alone really is a big issue and all the research (of which there is a lot) has not solved fundamental issues.

There are of course languages (like Rust) that have the fundamentals to match C/C++, but then it's still a matter of adoption. C++ also still develops.

Unity's multi-platform track record is quite solid at this point in time.

I wouldn't bet on exotic Java attempts of "write once run everywhere" though.

Java is actually not that bad – Java with LWJGL gets you within a factor of 1.6 to C++ performance, while actually being "write once run everywhere" (for PC, at least). That’s good enough.
Maybe on a Hotspot VM with JIT, while using frivolous amounts of memory for good GC performance.

You're not allowed to do JIT on consoles or mobile and you're memory constrained. A PC-only game engine is going to be a tough sell these days.

Also, unless you're bundling a JVM (not sure about the legals here) you have to make your Windows (i.e. primary) customers install the obnoxious Oracle Java runtime.

there's actually a pretty serious niche of us Go game developers growing as well
I look forward to it.
Yes, the track record is often negative if you want to make action games on not-Windows because of GC pauses caused by Mono's inferior garbage collector.

As for Java, Notch managed to do it for Minecraft, except for the mobile port which I think I remember reading was re-written from scratch on iOS because the performance was terrible.