Live data from Hacker News

The not so hidden cost of sharing code between iOS and Android

blogs.dropbox.com

161–170 of 335 posts

Re: The not so hidden cost of sharing code between iOS and Android

#161

Recently worked at a company doing similar to this to support Windows and macOS. To add to the difficulty, they used Chromium as a UI front end much like Electron. All built in house though. They hired me as a JS/HTML/CSS dev, but same as the article states, the C++ work was the true bottleneck. They knew I had some C++ chops and set me to work doing C++ with a sprinkle of JS here and there. Due to incompatibilities…

> Due to incompatibilities in the compilers, there was a rats nest of dependencies, thousands of #ifdef’s to cover differing OS implementations, and we had to use some of the oldest versions of C++ to be compatible with both XCode and Visual Studio. My current work has me on a single C++ code-base for Linux, Windows and MacOS (not electron though, just native). You can avoid a lot of headaches by avoiding the platfor…

+1 for Clang. It integrates with everything. But like most open source options, it plays second fiddle to each company’s primary languages, and so thee’s no one IDE so perfectly integrated into these mobile dev C++ use cases as to make it easy to work with, the way, say, you can be productive on .NET framework with either C# or C++. Google and Apple are both C++ compatible, or have native bindings, but... they target their examples and ease of use at the languages that best integrate with the respective IDEs. (Swift for Xcode, Kotlin for Android Studio) The end result is possible, but it’s like picking Cordova/PhoneGap/Electron for your native app. You’re going to struggle to use native technologies at some point, and there are few examples to follow. Allowing for the realization that 80% of your app code is likely platform-specific even if the UI doesn’t vary much means you can adopt new approaches and native UI conventions faster. It’s like the difference in programming speed when you simply target Chrome for your web development vs when you’re trying to write code that runs on Internet Explorer also. It’s getting to the point where platform functionality diverges so much that writing it but from the same design/spec/data model is faster than trying to maintain compatibility. Especially if you need to support multiple versions of iOS and Android in a backwards compatible way and with different UI conventions in different OS releases. Native is native, nothing else looks or feels like native, when that’s what you need, and there’s more hand-holding for apps when they follow the latest spec from the platform, rather than try to chase it with their custom bindings/implementation...

Note re. targeting a platform — often learning and reading some C++ is inescapable. For me, reading Chrome source code makes it easier to work with Puppeteer in JS, or deliver a better web app because I know how things work under the hood and it’s easier to read the C++ than the read the web standards themselves. Similarly, C++ really is portable and fast, so it shows up in many places. But on mobile, the mix of C++ to Swift/Kotlin should be 90%-platform native if your app is a traditional CRUD app that deeply integrates with the platform. If it’s simpler than that, build a website, or if it’s a game engine or some custom UI, use that, sure, but if you want to benefit the most from Apple and Google implementations, native (with shared spec/data models) is the way to go...

Re: The not so hidden cost of sharing code between iOS and Android

#163
post #158

We've had a mostly different (positive) experience doing a similar thing at FullStory for mobile instrumentation, though I think I know where some of the key differences are. Our core "business logic" lives in Rust. This is a shared bit of code between Android & iOS that mainly deals with orchestration, serialization, and server communication. We managed to extract ~1/2 of each platform's native code into this shared…

“Our core "business logic" lives in Rust.” Uh oh. So immediately you do understand that you have taken on the risk of potentially being unable to find any good(or bad) Rust engineers in the future, correct? Also they won’t be cheap as there won’t be many of them. A smarter, business-friendly, future-proof approach would be to have done that in Java. Future you will want you to have done that in Java, but if you’re tr…

I think many of the best programmers would jump at the opportunity to work with Rust. That might change if the language de jour changes but working with rust is a positive for many of the best people right now.

Re: The not so hidden cost of sharing code between iOS and Android

#164
post #93
post #15

I have come to this same conclusion after many years. It's not cost-effective to have any bespoke business logic (models, controllers, etc.) shared between the two mobile platforms (don't get me started on sharing UI code). If you have some incredibly tricky low-level algorithm/library and/or need for speed, think database, crypto, intense graphics, etc., then fine, you may be able to swing a shared module in C++ or…

This is a fascinating idea, and reminds me of the dreaded [1] rewrite , where you rewrite the application because the new system will always be better in the new framework ... But this is different, if you write things simply , so the code can be ported easily . Then you're essentially making the code easier to share, without tightly coupling it to a specific platform... seems like a big win to me [1] http://wiki.c2.…

Note to self:

This also has the benefits of:

- Being easier to on-board new developers, as the architecture is generally language agnostic.

- Easier to add new OS clients, as the system is easily portable

Downsides:

- Harder to incorporate language specific dependencies, as they are much harder to find in multiple languages.

- Code duplication...

Always important to weigh up the trade-off's

Re: The not so hidden cost of sharing code between iOS and Android

#165
post #157

This is wild. So Unreal/Unity and others somehow get to run their arguably vastly more complex engines on mobile desktop and consoles, but sharing some logic between iOS and Android is too complicated for Dropbox. What are they smoking?

I see you haven't worked on that level (or maybe you are young)....

First, unreal/unity work at a different level of the hardware, and they have to deal with different graphic drivers, in the same type of the OS.

But keep in mind that they are not the end product! The end product is the game that run on them.

So, the cost to building a multiplatform game, is having a whole Game Framework (which are whole companies), to deal with the lower level details and help abstracting out the differences of the platforms.

Dropbox is the end product. So, to make the code shareable, they have to build something like the equivalent of a game engine....

which is not a simple task....

I have worked at Spotify, and we had a lower level library to help (built in C++) to help out with some of the common features across platforms. It was ported from the desktop app, to iOS and Android, and it was a separate project. Over time, as features kept piling in, it turned into a giant un-manageable mess. It got so bad at some point, that we had to skip a couple of scheduled releases to clean up/fix some of its issues.

The problem became even worse when Spotify tried to build a unified UI on top of it (HTML 5 based), with a bridge layer to the C++. The idea was to write once, and (haha) run it everywhere. It failed, for the reasons many of them failed in other companies as well (facebook was doing HTML5 at the time as well).

That got removed, but the problem still remains that "Core" got overly complex as many platforms had their own features, which often were "one off", A/B testing, to see if it works or not. And separate teams (iOS, Android, and Desktop) had their own schedule on this. (It makes perfectly sense to A/B test one feature in Android, and another one in iOS, to see if people even like that feature before making is x-ross platform.

Common platform code, massively slowed down A/B testing of new experimental features, and thus it was a huge cost to the company.

The only solution to this was to keep the common "Core" (as it was called), to the most minimal features needed, and mostly related to playback (ie. song retrieval, caching, retrieval, decryption, playback, and some account features).

Do, the A/B testing on the platform level (iOS, or Android), of it was successful then roll what made sense to the rest (but still trying to keep core as lean as possible).

But since I left few years ago, things might have changed again....

Re: The not so hidden cost of sharing code between iOS and Android

#166
post #88
post #15

I have come to this same conclusion after many years. It's not cost-effective to have any bespoke business logic (models, controllers, etc.) shared between the two mobile platforms (don't get me started on sharing UI code). If you have some incredibly tricky low-level algorithm/library and/or need for speed, think database, crypto, intense graphics, etc., then fine, you may be able to swing a shared module in C++ or…

The article says it all - they chose the wrong language with no community support for the trail they were blazing and that technical debt destroyed their productivity. I achieved 90+% code share in Xamarin including UI across windows - ios - andriod. 100% buisness logic shared. You can write cross-platform UIs, and swap out to native code on a widget by widget basis. Threading is seemless. Sure it has its own set of…

Xamarin on paper seems like the holy Grail, but the fact that Microsoft itself chose to use react native instead of its own solution for Skype made it seem like I should not expect long term commitment to xamarin from MS.

Re: The not so hidden cost of sharing code between iOS and Android

#167
OK, but they didn't attempt to use Qt.

I'm currently working on a project where we have indeed decided we needed to go Swift/Kotlin native on each platform, but with the long-term goal of building a cross-platform app with Qt.

Qt certainly has its issues, but I respect what its developers have accomplished. And it appears to offer adequate ways to do common things like parse JSON, and it abstracts things like Bluetooth usage and file storage in the apps' sandboxes; so I don't see some of the hurdles cited in this article.

Re: The not so hidden cost of sharing code between iOS and Android

#168

Interesting post. I wonder if the major pain point was the fact that they were doing dev with a language that had nothing to do with either platform. We’re currently investigating Kotlin/native and it looks really promising. We don’t have to write stuff in a foreign language, but can repurpose our existing Kotlin code and share with iOS. This model seems promising. Does anyone have any experience with Kotlin/native?

"but can repurpose our existing Kotlin code and share with iOS"

How so?

Re: The not so hidden cost of sharing code between iOS and Android

#169
post #88

Earlier quoted context omitted.

The article says it all - they chose the wrong language with no community support for the trail they were blazing and that technical debt destroyed their productivity. I achieved 90+% code share in Xamarin including UI across windows - ios - andriod. 100% buisness logic shared. You can write cross-platform UIs, and swap out to native code on a widget by widget basis. Threading is seemless. Sure it has its own set of…

It was years ago, but Rdio went the Xamarin route, regretted it, and then did exactly what Dropbox just did and went full native. The reasons for regretting it were similar: lack of available engineers on the market, incompatibilities between runtimes, and lagging support for platform features (although in the Xamarin case it's not even in your hands to fix it)

Xamarin is open source now.

Re: The not so hidden cost of sharing code between iOS and Android

#170

Recently worked at a company doing similar to this to support Windows and macOS. To add to the difficulty, they used Chromium as a UI front end much like Electron. All built in house though. They hired me as a JS/HTML/CSS dev, but same as the article states, the C++ work was the true bottleneck. They knew I had some C++ chops and set me to work doing C++ with a sprinkle of JS here and there. Due to incompatibilities…

I'm currently working on some code that is for VS/Windows, Clang/macOS, and GCC/Linux. I'm just setting the std to C++17 on all of them with no extensions. I have had some warnings that have sprung up on some platforms, but not others. But I haven't run into any show-stopping incompatibilities for vanilla C++17. What should I be looking out for? Or was this a matter of using different standards on different compilers?
Post reply on HN