Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This brings me to a point. I was thinking about writing a game (real time 3d graphics, etc) for desktop and mobile, as many platforms as possible. What would be the language or tool of choice to go with?

My conclusion: in 2011 you should write your program in C if you want to reach the widest audience with a single code base.

You'll still have to write some Obj-C for OSX/iOS but it's easier to interop Obj-C with C than any other language. With Android you go with NDK and you might have to write a little Java/Dalvik if the default launcher of NDK is not good enough. On desktop Linux you'll need a little bit of X11 programming.

On iOS, OSX, Android and Linux you can do use Posix system calls pretty liberally but have to keep some portability issues in mind (e.g. epoll vs. kqueue).

Of course then there is Windows, that has almost nothing in common with any other platform out there but it can still be programmed with C.

I've seen products that claim to give you portability across all these platforms but my experiences with that kind of frameworks have always been negative. Some cross platform game engines may be able to deliver a bit better.

Of course then there's the option of simply duplicating the code base for all platforms which seems to be popular with small apps. With a game, where the graphics and game logic are the majority of the code, you probably don't want to duplicate that part. You could also try writing some of the non-speed critical stuff (like game logic) with a scripting language like Lua (if your appstores allow you to do such a thing).

I am slightly disappointed that we still have to write C to write code that's fast and portable, esp. on mobile platforms. Also the lack of any kind of standard library (apart from libc and posix) makes a cross-platform developers job a bit harder.



No idea if it's suitable for your particular purpose, but Unity is a 3D game engine that's pretty cross-platform. No doubt the licenses are pricy.

http://en.wikipedia.org/wiki/Unity_%28game_engine%29


I'm curious: what made you discard C++?


C++ support on embedded devices and smartphones is kind of iffy. First there might be actual language features missing because of a simplified runtime system those systems use. I'm primarily talking about exception handling but also other features.

Second is the standard library. The systems in question might not ship with a decent C++ standard library ("STL").

Third problem is C++0x. If I were to write C++, I would definately want to use C++0x, the language has cool features like auto and lambda and the standard library has nice additions w.r.t. C++98, especially std::thread and std::chrono.

Third is the API's you have to deal with. Using C API's in C++ apps either requires you to use a wrapper layer or give up using constructors, destructors, exceptions or at least give very special attention to those and end up writing code with a bastardized C/C++ hybrid.

Don't get me wrong, I like C++ but it's always a PITA to try to write something portable with it.


I'm writing a game engine at the moment, specifically for PC but also potentially to experiment with on mobile platforms, and I decided to go with C, for exactly the reasons you've mentioned with.


> with a scripting language like Lua (if your appstores allow you to do such a thing)

Which appstores forbid that?


I might be wrong here, but didn't Apple app store have limitations on what languages you were allowed to use. I don't know whether or not that applies to having an embedded interpreter like Lua.


those limitations have been removed as far as I know


You can ship with Lua. Just don't download more Lua after installation. I.e: Don't download code that wasn't included in the app submission.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: