Hacker News new | ask | show | jobs
by ntrepid8 3788 days ago
Maybe I'm being dense, but why would someone want to write c++ code and transpile it to JavaScript?
2 comments

In short, portability, better performance than manually written Javascript and simple distribution:

These demos run in the browser, and natively on iOS, Android, Windows, Linux, OSX with the smallest size and best performance on each platform compiled from the same C++ code: http://floooh.github.io/oryol/, http://floooh.github.io/voxel-test/, http://floooh.github.io/virtualkc/

The better performance then manually written JS comes from the use of asm.js, LLVM's optimizer passes, and a simple linear memory model which 'preserves' spatial locality also present in the natively-compiled C/C++ code (if the programmer paid attention to this)

Passing an URL along from which the code directly runs is the simplest distribution model imaginable, both for the 'publisher' and for the user.

PS: the performance part applies to emscripten and asm.js, not necessarily to Cheerp which uses a different approach

Whoa, your framework looks excellent. I've been looking at the options for making a simple graphical program that can run in native/desktop and in browser without introducing ridiculous bloat, and had already concluded that C++/emscripten was likely the best option, probably using GL. (The close runner-up being Haxe/OpenFL, but it's a bit heavier and kind of an experimental leap.)

I'm still deciding on which libraries to use, and Oryol suddenly seems like a great option, though what I'm making is not a game and is not 3D (basically a score editor). Other options considered were SDL(2) or something more basic like GLFW. But Oryol's killer feature here is that it's specifically designed to result in a lightweight web version. (Though SDL1 also results in small sizes, but that's because the emscripten team put a lot of work into converting SDL calls into browser API calls)

Thanks! But please keep in mind that Oryol is fairly experimental and the API might change on a whim, so it may be a bit painful to use for a real-world project that needs API stability.
I assume this is to port existing C++ code to JS? That's what Emscripten is supposed to do anyway.
I converted legacy code to JS using emscripten because the company had severe constraints on the output of the code. In other words they didn't know why their code did what it did. (grin)