
Ask HN: Best language for cross-platform mobile (non-UI) code? (Go? Haxe? C++?) - _alastair
I&#x27;m experimenting with making a cross-platform library (specifically for iOS and Android) and I&#x27;m curious to hear what languages other people who have done it ended up using.<p>The most obvious first thought is C++. I&#x27;ve only lightly dabbled in it, and the most frequent opinion I hear is that C++ is more &quot;necessary evil&quot; than &quot;a delight to work with&quot;. So I started looking at alternatives, having used none of them before.<p>Go has built-in functionality to make Go code callable from Objective C and Java. But it&#x27;s still the Go runtime underneath, just proxied out to native.<p>By comparison, Haxe can output both C++ and Java. Presumably it has some cleverness built into C++ to handle garbage collection, but it sounds like the output is more &quot;pure&quot; than Go would be.<p>But does that even matter? Haxe definitely feels like a more familiar language to write, but a more obscure language in terms of raw popularity (but it has generics!). Go feels more alien (and I&#x27;m concerned that it doesn&#x27;t seem to let you explicitly handle threads, which has bitten me on iOS before), but everything I&#x27;m reading about how it&#x27;s structured, testing etc. just feels very <i>sensible</i>.<p>Has anyone used any of these options to make a cross-platform library? Or is there another one I haven&#x27;t thought of? I&#x27;m curious to hear any experiences.
======
ahlwong
I’ve worked extensively in C++ for cross platform on iOS and Android. It’s
well supported - you cal C++ natively from Obj-C and use JNI patterns for
Java. Cocos2d-x is a cross platform game engine built on C++ as well that has
wide adoption and is production ready.

I also have not run into any task yet I haven’t been able to accomplish in C++
(threading, etc is well documented and you have a few options)

I’ve actually written a UI framework on top of Cocos2d-x (essentially C++ and
OpenGL) which we use in production that has also been robust and allows us to
just write it once and compile for iOS and Android.

C++ is definitely verbose but it is also very flexible and IMHO.

------
miguelrochefort
Xamarin is the obvious choice (C#, F#).

