Live data from Hacker News

Ask HN: Best language to share code between an Android and iOS app?

news.ycombinator.com

81–90 of 123 posts

Re: Ask HN: Best language to share code between an Android and iOS app?

#81
post #28
post #15

C++. It is part of both SDKs, you have direct support for mixed mode debugging on the IDEs. No need of extra tooling. On Android JNI is always going to be a pain, but at least with C++ Studio gives you an hand on accessing JNI APIs.

I want to like this answer but not sure it's true. Do you mean bridging ObjectiveC++ and Swift? Apple is now deprecating ObjectiveC++ (after all the work we went to to make it work back in the NeXT days). I would like to integrate C++ code into a SwiftUI app but am not sure how to do it. Are there some iOS C++ APIs I'm overlooking?

> Apple is now deprecating ObjectiveC++

I’d be very surprised if this was true. Apple’s own frameworks are all C++ under the hood, e.g. CoreAnimation, AVFoundation, AutoLayout (part of UIKit and AppKit), Metal, etc. The meat of these frameworks is in C++ with an Objective-C++ layer on top, exposing an Objective-C (and thus Swift) API to developers.

Re: Ask HN: Best language to share code between an Android and iOS app?

#82
post #60

Since no one else has said it, I'll be the voice of reason. Share your design specs only, and let each platform team write the implementation in the language that they think best. Yes, you'll have two teams spending time on doing the same thing. However, you'll get important benefits. Each team will be able to implement appropriately for their platform. While iPhones and Android phones are rather similar in terms of…

Having attempted this in the past let me say: I’m in violent agreement.

Attempting to “share code” between Swift/Kotlin is folly at this point. I’m not going to close the door on Kotlin Native some day. But for now just say, “No”.

Re: Ask HN: Best language to share code between an Android and iOS app?

#85
post #60

Since no one else has said it, I'll be the voice of reason. Share your design specs only, and let each platform team write the implementation in the language that they think best. Yes, you'll have two teams spending time on doing the same thing. However, you'll get important benefits. Each team will be able to implement appropriately for their platform. While iPhones and Android phones are rather similar in terms of…

I have a react native app published as part of our SaaS software suite. I don’t think users notice or even care if things feel marginally non-native.

I’d agree optimizing user experience by developing in native code might be important if you have a game or social media app where the worth of your company is directly correlated with your app install metrics.

Do you have any anecdotes or data that illustrates that users will be “confused” or “insulted” by non native apps?

Re: Ask HN: Best language to share code between an Android and iOS app?

#86
post #54
post #48

Earlier quoted context omitted.

C is also very simple to add security exploits to your app. I would never advise C unless the platform is lacking of a C++ compiler. Just use extern "C" at the boundaries.

A super thin layer made of C between say Objective-C or Swift and C++ is quite convenient though and doesn't add much of an security risk. See it as the lowest common denominator.

That’s what the extern “C” does

Re: Ask HN: Best language to share code between an Android and iOS app?

#87
post #48

Earlier quoted context omitted.

C is also very simple to add security exploits to your app. I would never advise C unless the platform is lacking of a C++ compiler. Just use extern "C" at the boundaries.

What vulnerabilities does C introduce that C++ doesn't?

Smart pointers make it exponentially easier to write memory-safe code in C++ than in C.

Re: Ask HN: Best language to share code between an Android and iOS app?

#88

Earlier quoted context omitted.

For example it is easier to avoid buffer overflows with std::string than with C-style strings.

It’s also easier to avoid buffer overflows in C by using the “n” variants of C string library functions.

Why subject yourself to that risk when you can just use C++ and make everyone's lives easier? Is there a benefit to using C?

Re: Ask HN: Best language to share code between an Android and iOS app?

#89
post #88

Earlier quoted context omitted.

It’s also easier to avoid buffer overflows in C by using the “n” variants of C string library functions.

Why subject yourself to that risk when you can just use C++ and make everyone's lives easier? Is there a benefit to using C?

What “risk” is there in an overflow from using strncmp, strncpy, etc?

C++ still isn’t as easy to interop with other languages as C and the low level APIs built into operating systems are not going to use C++/STL and you still end up converting to standard C strings and arrays.

Re: Ask HN: Best language to share code between an Android and iOS app?

#90
post #60

Since no one else has said it, I'll be the voice of reason. Share your design specs only, and let each platform team write the implementation in the language that they think best. Yes, you'll have two teams spending time on doing the same thing. However, you'll get important benefits. Each team will be able to implement appropriately for their platform. While iPhones and Android phones are rather similar in terms of…

That's the ideal way of solving the problem, but it is a luxury not everyone can afford.
Post reply on HN