HACKER Q&A
📣 jamil7

Best way to share client code in 2023


Mostly looking at this for a side project. How would you share code between native and web targets in 2023? Kotlin Multiplatform and Kotlin JS look like the most mature, although the toolchain kind of turns me off. What other solutions exist? WASM/WASI looks like it's still missing quite a few features.


  👤 natpalmer1776 Accepted Answer ✓
Personally I look to having a 'common core' for clients that handles all of the actual logic of the application, then implement the interface in whatever library is most appropriate for the target platform.

As an example for .NET 7 I would write an SDK for interfacing with APIs that host the service. For the web client I would use Blazor WASM, for desktop I would use either MAUI or a 'native' wrapper for Blazor, and for mobile I would stick with Xamarin.

In general I would suggest designing for 'the web' as it will be the easiest to port to other platforms quickly and require the lowest care & feeding. Once the project is more established you can then look at creating native-first versions of the client that leverage the design idioms of your intended platform.


👤 ozaiworld
As someone working on mostly native iOS apps, Flutter apps, and React webpages, I’ve been looking for a solution to share common models and other utilities between clients.

Kotlin Multiplatform definitely looks like the most mature option, but I’m looking at Flutter/Dart as an option, too. Dart has support for method channels with Swift/Obj-C and Kotlin/Java plus there’s the official dart2js compiler.

I personally don’t think Flutter is the right choice for a best-in-class native mobile app and definitely not for a website, but I think there might be something worthwhile using Dart as the language of shared library like Kotlin Multiplatform.


👤 matthewwolfe
I use a mono repo setup with “web”, “native” and “shared” using react and react-native. All of my logic and fetching code is hook based, and that can be 100% shared. I have to make a web interface and a native interface, but they are so different it’s nice to split on the UI. I wouldn’t want to have a desktop UI that I also show in an app, it just wouldn’t look good. All in all I probably share ~70% of the code. It’s all in typescript and really nice dev experience.

Maybe I’ve not been in the react native ecosystem long enough but it seems relatively painless. Granted I’m mostly displaying data, some icons, and buttons so YMMV


👤 aliqot
Tauri, or just an actual web app. The user has no clue what's in a webview app and that's fine. I'm only one developer.

I love WASM, but mostly in a "bro check out my pecs" kinda way toward other nerds.


👤 arcbyte
I write web services in enterprise Java using JAXRS annotated interfaces in their own project as the "interface". For other Java services and even android these jars can be shared directly and used as web clients. There are some great plug-ins out there that generate documentation and also typescript clients for node or browser environments (as well as many other languages). You get all the benefits of strong typing everywhere and only have to write the code once.