Question

I know that V8 compiles JavaScript to native machine code (IA-32, x86-64, ARM, or MIPS CPUs) before executing it. And I have read that google native client compiles C/C++ to machine code, so if those two technologies return same result(machine code), What's the difference between them except for the used languages(JavaScript C/C++)?

Was it helpful?

Solution

Well, given a CPU architecture (say, you run on an Intel box) you can say that any technology ends up compiling to machine code, right? So Python, Perl, Javascript, C++, Fortran and so on are just different languages that get compiled down to machine code (Python and Perl are usually bytecode VMs but these also run as machine code down in the bottom).

v8 is a Javascript runtime. Yes, it uses compilation under the hood to speed up your code. Other JS runtimes do that too (*monkey of Firefox, etc.)

NaCl (through PNaCl or not) lets you write C/C++ code that ends up executing in the browser. This has some advantages and disadvantages vs. JS, and which ever you pick depends on your specific needs. For most applications JS is more suitable because it's a higher-level language so it's more convenient to program in. Some applications, however, need special levels of performance that's not achievable with JS (at least at this time). These applications benefit from having a NaCl module inside, that usually takes part in a larger architecture which includes JS as well.

Read this for more details.

OTHER TIPS

The main difference is, that JavaScript is supported by every browser and NativeClient is Chrome (Chromium) only. So, if you want to write a Web-Apps JavaScript is the way to go, because it will run in (almost) every browser, not just in Chrome.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top