Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I realise it works, I just don’t think it’s really useful for what was asked for, a way to write common cross-platform business logic for a platform-specific UI.

Unless there are some great new tools I’m not aware of, C on WebAssembly seems about the same as C on Android. You can compile stuff just fine, and run it, but actually connecting it up to any substantial UI written in JS/Java is going to be incredibly tedious.

For a computation library with well-defined inputs and outputs, and that “just works” and doesn’t need any debugging in situ, it makes a lot of sense. But I think business logic by definition is going to need a much richer interaction with the UI, and that’s what makes it hard.



The interaction between C and Javascript offered by Emscripten is a lot better than JNI on Android. I wish the Android NDK would steal a few ideas from Emscripten, but all the Android teams at Google don't seem to be able to look outside the nice comfy bubble they've created for themselves.

With Emscripten, you can embed Javascript source code directly into the C code and then call the embedded JS function from the C side as well as C functions from inside Javascript.

E.g. JS embedded in C code:

https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738b...

...called from C:

https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738b...

...and a C function:

https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738b...

...called from a JS function embedded in the C code:

https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738b...


Not bad! Sounds like the tooling has improved since I last looked.

How about debugging? Is it possible to step through a mix of C and JS stack frames?


The Chrome devtools have added experimental DWARF debugging support, but for big projects that's still a bit of a hassle:

https://developers.google.com/web/updates/2020/12/webassembl...

The embedded Javascript can be debugged as usual.

In my case I usually debug the platform-agnostic code compiled natively in IDEs like Visual Studio or Xcode, and for the HTML5 specific code (which is just a few hundred lines) traditional "printf-debugging".


Fair enough, and I strongly agree with the general point about the need for a solid cross-platform framework either way.

I don't see why you couldn't write your entire business logic, state management, etc. in C or Rust and treat it effectively like a client-side server, but I've never used wasm in that way so I can't speak from experience there. Either way, I can certainly see how that would require some extra effort, and of course it would only really be useful for applications that don't offload most of their work to a server.


Generally speaking the "connecting it up" between c/wasm + js or C + java/kotlin on android can be completely automated with codegen. It's really not tedious at all.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: