8 ms·
I wonder what advantages choosing C++ to write web apps would bring. At the end of the day it's all JavaScript so performance is rather moot point.
by Kip9000 12y ago
I wonder what advantages choosing C++ to write web apps would bring. At the end of the day it's all JavaScript so performance is rather moot point.
- virmundi 12y agoProbably none. However, it could act as a gateway drug for C++ desktop folk. They do exist.
- tylermac1 12y agoWe do exist. The fables are true.
- recentdarkness 12y agoSo it's like GWT for C++
- Touche 12y agoThat'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.
- aikah 12y agoWhile true,if your "c++" hit the DOM , in the client, you'll have the same problems as hand-written JS.
- Kip9000 12y agoYou 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)
- humanrebar 12y ago> 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.).
- pkolaczk 12y agoWriting 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.
- Kip9000 12y agoThat was going to be my response..
- pkolaczk 12y agoI 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.
- s_baby 12y agoNasa and military don't know what they're doing? C++ is the go to language in mission critical systems.
- pkolaczk 12y agoNASA 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.
- humanrebar 12y ago> At the end of the day it's all JavaScript so performance is rather moot point That's probably true, but C++ does provide very powerful compile-time evaluation mechanisms like templates, constexpr (compile-time evaluated constants and functions), and template metaprogramming. That being said, compile-time C++ can look very gross since most of the features are accidental. However, there are a lot of huge performance benefits to moving computation to compile time: selecting the most optimal algorithm for a type, guaranteeing you don't mismatch your units, precompiling search (glob, regex) engines, eliminating dead code, and so on. So I would be shocked if at least some javascript applications couldn't be much faster and more correct by writing in C++ first and compiling to js. That being said, it's probably not in scope for a minimum-viable product, so improving already business-critical parts of the code base might be the best place to start.
- pkolaczk 12y agoMetaprogramming and type-safety facilities of C++ are very limited compared to other languages like Haskell or Scala. And for the latter there is a JS compiler as well.
- swah 12y ago> it's all JavaScript so performance is rather moot point If that was the case, http://asmjs.org/ http://asmjs.org/ wouldn't be a thing.
- oso2k 12y agoAccording to the Chrome guys...it isn't a thing [0][1], and I tend to agree. They've kept up, and often exceeded FF, IMO, for real code by making a better JIT compiler. They still haven't implemented asm.js and yet their "naive" approach to asm.js style code is on par. [0] https://code.google.com/p/v8/issues/detail?id=2599#c53 https://code.google.com/p/v8/issues/detail?id=2599#c53 [1] http://mrale.ph/blog/2013/03/28/why-asmjs-bothers-me.html http://mrale.ph/blog/2013/03/28/why-asmjs-bothers-me.html
- gcp 12y agoThe links you pasted show Firefox currently being 3x faster than Chrome when running asm.js code, so I'm not sure what your point is. V8 is good at generating fast code without the hints, but obviously the extra restrictions help the optimizer. Even Google admits this when they try to promote Dart. asm.js does little for you if you write "real JS", but this thread is about cross-compiling other languages, which clearly has real world use.
- swah 12y agoI'm not a compiler expert but I also have the feeling that a new bytecode would be better. But if I recall correctly, there are very good reasons why we don't have that in our browsers; security concerns maybe? Anyone? Or http://hn.algolia.com http://hn.algolia.com, here I go again! (What a great post, thanks for linking. Even though I follow mraleph on twitter, I had never opened his website. Probably because it all looks like scary compiler stuff.)
- aboodman 12y agoAnother major benefit (of emscripten too) is that is you have significant non-presentation client-side logic, it can be shared between iOS, Android, and the Web. For example take something like Dropbox's Carousel architecture, which shares the client side cache, date model, and sync client between iOS and Android via a C++ library. Something like Cheerp or Emscripten allows you to also use this same library on the web.
- flohofwoe 12y agoFor me it's portability first, decent performance second and third the 'seamless distribution model' of the web (no installation, no app shops, no code signing, just an URL). I wouldn't write a web-only app in C++, but if the same code needs to run on other platforms as well (e.g. native mobile, desktop or gaming consoles) then C/C++ is basically the only choice. Also, at least in emscripten, compiled code is faster then hand-written JS for several reasons (asm.js, LLVM optimizer passes, no gc), so it makes sense to write stuff like physics/pathfinding/AI engines in C/C++ and compile it to JS. Plus, it's fun to write a desktop OpenGL demo, flip a build system switch and run it in the browser ;)