Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Often people talk about cross-platform compatibility, but is it possible to write such "universal code" that would work both in browser, in desktop, on opengl, on webgl, and on html5 canvas-object? I'm thinking about writing a c-to-javascript compiler that would allow running desktop applications in browser. This utility would parse c/c++-code and generate javascript-code, and somehow replace all opengl-calls with webgl-calls. Something similar to Emscripten, but without assembly-like code (functions and statements would be converted one to one). Of course there will be some severe limitation on such c++ code. It will not support templates, dynamic polymorphism, etc. Also all libraries would have to be more or less substituted with javascript-implementations, so for example std-namespace will have to have javascript counterpart.

Do you think this is worth the trouble? Or should we just optimize better desktop-application download and execution, and except users to press "download" on our site? Google earth seems to be pretty popular even though it has a mandatory installation-step.

share|improve this question
up vote 1 down vote accepted

Unless writing C++ code is a requirement, maybe the Monkey programming language could be of interest? It works as an abstraction language, and can provide output code in at least C++, C#, Java, Javascript and Actionscript, which could make your application work on a wide range of platforms. The syntax is fairly lightweight and approachable, you can see a quick demonstration here.

Regarding the second part of your question: From a business' point of view, covering more platforms is definitely a benefit, but you'll have to ask yourself whether the extra cost is worth it. In any case, more and more applications are being browser-based, so personally I think that at least being able to run in a browser easily would make the effort worthwhile.

share|improve this answer
Wow, monkey code idea sounds great (supporting so many platforms and environments). Not sure if I'm willing to learn completely new language, but will definitely take a look. – AareP Apr 29 '11 at 8:54

If you're willing to develop in Java, see for an already built compiler. See for webgl support.

share|improve this answer
Java is not as fast as c++ applications :) – AareP Apr 29 '11 at 8:47
@AareP: Typically not, but in some cases it is actually faster. Anyways if the compiled JavaScript version that runs in the browser is fast enough, you'll have no complaints about the native version. So I'd focus more on what produces better JavaScript with the least work. (I say this as someone who does not like Java.) – btilly Apr 30 '11 at 13:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.