Ask HN: 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.
8 comments
[ 6.1 ms ] story [ 35.5 ms ] threadI love WASM, but mostly in a "bro check out my pecs" kinda way toward other nerds.
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.
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
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.
Edit: Pieced together how to do this from the official docs.