News for hackers. Stuff that matters.
Re:Cheerp – A C/C++ compiler for web applications by Touche on Tuesday August 12, 2014 @09:54AM (#8167718)
That's actually not true. Emscripten compiles to code that is much faster than hand-written JavaScript. In this case they are not using Emscripten or a similar technique but are compiling to regular old JavaScript, so performance probably is the same, rather this might be for people who just like C++, like what GWT is for Java devs.
Re:Cheerp – A C/C++ compiler for web applications by Kip9000 on Tuesday August 12, 2014 @10:13AM (#8167794)
You misunderstood. People mostly write with C++ when performance is critical. Why? C++ offers deterministic memory management, Specialize to CPU instruction set and better use of CPU caches etc. Those performance benefits would not translate when you cross compile to something like JavaScript. I get the point about converting the legacy desktop apps to web apps, but how would it handle the architectural differences ( Desktop apps don't scale)
Re:Cheerp – A C/C++ compiler for web applications by humanrebar on Tuesday August 12, 2014 @10:41AM (#8167901)
> People mostly write with C++ when performance is critical.

Performance is a big reason people use C++, but there are many others. For example, people also write C++ when correctness is critical (bank software, safety-critical systems, etc.).

Re:Cheerp – A C/C++ compiler for web applications by pkolaczk on Tuesday August 12, 2014 @10:57AM (#8167992)
Writing for correctness in a language with no memory-safety, weak type system and, till not very long ago, no standardized memory-model, and UB in every other paragraph of the specs? Good joke. If they are really doing this, they have no idea what they are doing. There are plenty of languages better for safety-critical systems than C++; even widely hated, boring Java is much better.
Re:Cheerp – A C/C++ compiler for web applications by humanrebar on Tuesday August 12, 2014 @03:51PM (#8169783)
It's a bit off topic, but I'm being descriptive (based on professional experience) and not normative when I say C++ (and C and Ada) are used for safety-critical software. Javascript and functional languages certainly aren't.

The vagaries of the standard aren't issues since safety critical software is validated on a per-platform and per-compiler basis. Memory safety is certainly a concern during the development process but more importantly (!) GC languages (like javascript and Scala) do not have provably (for some value of provably) deterministic execution times. Determinism is also a problem for lazy languages (like Haskell).

I say that to say the zero-cost abstractions of C++ is a huge benefit when writing safety-critical software. The level of control over emitted binaries is essential and fairly rare in programming languages.

> If they are really doing this, they have no idea what they are doing.

Well, I can't speak for entire industries, but that's a pretty sweeping generalization. You might be surprised what the challenges are when writing safety-critical systems software. That being said, I'm sure large portions of the industry are ripe for innovation.

Re:Cheerp – A C/C++ compiler for web applications by pkolaczk on Wednesday August 13, 2014 @03:40AM (#8171842)
> GC languages (like javascript and Scala) do not have provably (for some value of provably) deterministic execution times

This is not unique to GC languages, but any languages with dynamic memory management. C++ new/free and STL abstractions built on top are not provably deterministic either. And if you program without ever touching dynamic memory (statically allocating and pooling everything) then GC is not a concern.

> I say that to say the zero-cost abstractions of C++ is a huge benefit when writing safety-critical software.

You're talking about performance now, not correctness. All those benefits get lost once translated to JS.

Re:Cheerp – A C/C++ compiler for web applications by Kip9000 on Tuesday August 12, 2014 @11:12AM (#8168066)
That was going to be my response..
Re:Cheerp – A C/C++ compiler for web applications by pkolaczk on Tuesday August 12, 2014 @11:25AM (#8168135)
I was replying to the statement: "For example, people also write C++ when correctness is critical". And I say if someone writes C++ in a correctness critical system, he must not know what he is doing. Even if you're using only STL, RAII and following all the good coding practices, there are still so many ways to screw things up, that C++ is among the worst choices in this regard.
Re:Cheerp – A C/C++ compiler for web applications by s_baby on Tuesday August 12, 2014 @12:48PM (#8168655)
Nasa and military don't know what they're doing? C++ is the go to language in mission critical systems.
Re:Cheerp – A C/C++ compiler for web applications by pkolaczk on Tuesday August 12, 2014 @02:43PM (#8169412)
NASA and military are using a whole lot of different technologies and languages, including, but not limited to assembly, C, C++, ADA, Haskell, Coq, Python and Java. Saying they use C++ for correctness, when they are using Coq or Haskell as well, is again - exaggeration. I believe they use C/C++ more for performance / low memory overhead rather than its correctness related features.
Re:Cheerp – A C/C++ compiler for web applications by flohofwoe on Tuesday August 12, 2014 @12:46PM (#8168641)
At least when compiled with emscripten, the same memory-access-related optimizations used in native code also apply to cross-compiled JS code since the memory layout is exactly the same. emscripten uses a big linear memory buffer (a single big JS typed array) as heap and dlmalloc for dynamic memory management within this heap. If your code is cache-friendly in the natively compiled version of the code it will also be cache friendly in emscripten compiled code. Cheerp seemt to use a different approach though and seems to generate 'traditional' high level JS objects (which also means it requires garbage collection, which emscripten generated code doesn't).
Re:Cheerp – A C/C++ compiler for web applications by Touche on Tuesday August 12, 2014 @10:53AM (#8167969)
You do get some of those performance benefits when you cross-compile. JS VMs have different paths for different types of code and the type of code that Emscripten produces goes through a faster path because more is known about the code ahead of time.
Re:Cheerp – A C/C++ compiler for web applications by illumen on Tuesday August 12, 2014 @11:42AM (#8168245)
You also get 1.4MB of code, which takes 1 hour to load on a mobile connection, and reimplements functionality that host JS/Browser provides which goes much quicker ;) Most C++ code does not care about compiled size(especially with templates!!!), but JS code often does, so is written in a smaller way.
Re:Cheerp – A C/C++ compiler for web applications by flohofwoe on Tuesday August 12, 2014 @12:27PM (#8168522)
True, you need to be sensible about compiled code size which traditionally wasn't important for C/C++ code, and it's also true that the C++ std lib or careless use oft templates can bloat the code size. On the other hand, three.js which is basically the standard lib for 3D rendering on the web comes at 0.5 MB minified, which isn't exactly small either ;)
Re:Cheerp – A C/C++ compiler for web applications by aikah on Tuesday August 12, 2014 @10:10AM (#8167783)
While true,if your "c++" hit the DOM , in the client, you'll have the same problems as hand-written JS.