12 points · by eatonphil · 11y ago · 22 comments
With tools like emscripten and js_of_ocaml, I can write C++, C, OCaml, Python, Java, Rust, Haskell, Objective-C, CIL (and any other language that compiles to LLVm bytecode[0]) and use that to power my browser scripting.
As we get closer to a Javascript as a bytecode, it seems like there may no longer be a need for Javascript the front-end. If I had to start a new app today, I think I might choose to do it in a unified language that either targets LLVM bytecode, or Javascript directly. In this way I could achieve unification of my server-side and browser-side code. Allow ease of maintenance, hiring, etc.
The only reason I can see actually "writing" Javascript continuing is in maintaining "legacy" code bases. Any thoughts?
[0] http://en.wikipedia.org/wiki/LLVM#Front_ends:_programming_language_support
Given the current popularity of Javascript, this means that the exotic language must be very compelling; the two main reasons, reusing good libraries written in some other language and reusing good programmers who don't know and won't learn Javascript, appear rarely applicable (there are Javascript libraries for most needs and most developers involved in web development think they know enough Javascript) and they cover only a portion of most plausible projects or teams when applicable (there are important parts of the application beyond any library, and someone will want to use Javascript).
As for actual language fetures (templates in C++, various functional styles in Ocaml and Haskell, etc.) a language fan needs to justify costs like performance loss, write-only generated Javascript code, flaky libraries, gigantic file sizes, and so on.
I used Node recently for a project. Never again. It's just not a good language, for many reasons. The Node community is good, and the packages in npm are good, but the language itself is so wishy washy and has so many warts that if you try to do anything either very complex or performant it crumbles quickly.
Of course that being said, I've gotten a bit jaded about dynamic languages in general. IMHO they deliver high productivity up front but you pay for it later X2 at least. But among dynamic languages Ruby, Clojure, and Python are orders of magnitude better than JavaScript.
I feel like web developers have Stockholm syndrome with it. They've been forced to use it, so they sort of forced themselves to pretend it doesn't suck.
- Can't deal with 64-bit integers
- Insane type system, e.g. null vs. undefined and all kinds of complexity around seeing what something is. Types are strings? Really?
- No baked-in language-standard way to do async coding despite the language being inherently async, which leads to a mishmash of promises and indent cascades with callbacks.
- How do I use exceptions with callbacks or promises? All kinds of edge case hell here. Either have exceptions or don't. Again there are probably good patterns, but since there is no canonical way everyone does it differently.
- The == vs === mess
- Lots of fragmentation around how to do classes, inheritance, etc. Getting fixed in ES6, but there will forever be tons of legacy code where everyone did it differently.
- In practice I've found it easier to get leaks in JS event-driven code than in other GC'd higher level languages.
I'm sure others could list other things.
JavaScript is the product of a death march at Netscape in the late 90s, and it shows.
- 64 bit ints (yup)
- Type system (you'll get over it)
- Async coding - everyone has a different standard, but it does work whichever way you do
- Exceptions - callbacks have err as first parameter, every time. You have to boilerplate. Promises you have to pass in an error function, you have to boilerplate. Could definitely be improved, but like handling async there aren't anything standard, just opinions at this point.
- always ===, hint your code
- OO stuff - absolutely. But its also not fundamentally an OO language, its much more flexible.
- Leaks - Tooling could improve a LOT. Finding and sticking to a technique is the biggest part, which can get harder as a team grows bigger. Show me 2 people with 5 years of javascript experience at different places, and you'll have 2 very different code styles.
If you're intent on making javascript with OO and aren't coding partially for a browser, use something else. If you want very easy asynchronous functionality with a very fast communications server, Node is pretty damn good. Node is great for breaking down complex tasks, as long as you have a good method of flow control (promises, async + callbacks, etc).
Plenty of people still write their own javascript, to do basic DOM manipulation and whatnot. I really can't imagine that the common use cases for JQuery, for instance, are better served by compiling C. It is a scripting language, even if you want to pretend it's "bytecode", and even if treating it as bytecode is useful for some people, I would argue that's still the exception and not the norm.
It appears that, at least for now, this pretty much always requires some JavaScript FFI work to actually do things in the browser.
This alone is enough to motivate me to keep honing my (functional) JS.
( It's also nice to be able to bang out something quick and dirty with minimal tooling. )
Would that suffice for you?
* I do concede ES6 is much much better