Ask HN: Why isn't native mobile libraries written in C?
I've always wondered why Apple and Google decided to use Objective-C/Swift/Java for their native iOS/Android libraries instead of plain C. Considering you can write bindings to C in virtually every programming language out there whether the programming model differs a lot or not (e.g OO or functional), you would be able to create mobile apps in any language you want if it can target the architecture.
Is there any particular reason why Google and Apple didn't take this approach? Does it introduce problems with the permission systems for apps? Security issues?
9 comments
[ 4.0 ms ] story [ 38.3 ms ] threadSecondly, for stateful graphics programming, the most common kind of application on mobile, OO works really well. So Apple and Google both picked languages that support OO.
Finally, despite all this, both Apple and Google have native C apis. You can write C freely in Objective-C, which is a superset, and Android has its NDK.
Compare that to Java where you can look at the class file and get enough metadata to do anything.
Also while C has great interop. it still comes at a cost, you loose a lot of modern programming constructs like exception, static initialization, reflection and garbage collections.
I have been part of teams where entire stack (even UI layer) was in C. malloc() was a prohibited function by design! It was way too much of code for what could be accomplished by having c++-STL these days. But then the system specifications were very low (~130 Mhz) too.
In one of embedded projects couple of years earlier - the trade off discussion we had was whether to include boost or to have a JVM ported to it! So we 've come far away.
With good chances of myself corrected here - I 've a feeling that C will be restricted to drivers/kernel, in most systems going ahead, as everything that can be written in C in rest of layers can be written in OO languages.
eg: OS based on nodejs on top of linux-kernel: https://node-os.com/