Hacker News new | ask | show | jobs
by WA 3650 days ago
HN community, how would I make my core model + business logic cross-platform? I want to re-use the model and its behavior (like some data evaluators) in my Web app, on Android and iOS without rewriting it every time from scratch. I'm fine with creating native code for the UI. but I'd like to share at least some code. What would you recommend?
2 comments

What I do is write the model and bussiness rules in Java, and I use J2ObjC[0] to export it for iOS. The configuration is not pain free, but once set up it has been extremelly reliable for me. I don't need to support web, but I hear GWT[1] works well for this. I don't see why JSweet[2] would not also work.

[0]http://j2objc.org/ [1]http://www.gwtproject.org/ [2]http://www.jsweet.org/

If you use react native on mobile and react on the web the core model and business logic can easily be shared since it is just pure js. And you can use any of the languages that transpiles to js: TypeScript, Clojurescript etc.
What about performance and the "overhead" that React Native might introduce?
The performance is impacted, avoiding premature optimizations I haven't looked into that part yet though. Without any performance optimizations I'm experiencing performance better than HTML5 but not really on par with native. To me the value of sharing the logic and the crazy fast development speed is more valuable than a few milliseconds of delay. At least in this stage.