Ask HN: Any alternative to JavaScript in sight?
42 points| digamber_kamat | 15 years ago | reply
Does anyone feel that sooner or later JS will probably turn out to be not-so-suitable for stuff we want to do ?
Are there any attempts being made to provide an reliable alternative or can JS itself evolve ?
[+] [-] stephenjudkins|15 years ago|reply
Besides CoffeeScript, which mostly only offers syntactic improvements to JavaScript, there are several projects which compile very different languages to JS, including:
* Emscripten (http://emscripten.org/) compiles arbitrary LLVM bitcode to JavaScript. Since clang and GCC can both target LLVM, a whole lot can be compiled to JavaScript. The Python interpreter (http://syntensity.com/static/python.html) and the Bullet physics engine (http://www.syntensity.com/static/bullet.html) are both particularly impressive.
* Google Web Toolkit (http://code.google.com/webtoolkit/) compiles Java to JavaScript. It's used in many real projects. Scala+GWT (http://scalagwt.gogoego.com/) aims to use this toolchain to compile Scala code, though it's not yet production-ready.
* The reductio ad absurdum of this approach is http://bellard.org/jslinux/, a x86 PC emulator written in JavaScript. You can run almost any language in the web browser with that!
See https://github.com/jashkenas/coffee-script/wiki/List-of-lang... for a (possibly exhaustive) list of languages like this.
Whether these approaches can deliver passable performance for legacy browsers is an open question. However, for newer browsers it's safe to assume this general approach holds a lot of promise.
[+] [-] nxn|15 years ago|reply
I'm a fan of P/NaCl for this reason. Their approach goes directly at the problem instead of banging on a square peg for years and years until it barely manages to fit through a round hole. By the way, that is the only way I can describe using html/js/css for application development at this point. If it makes me sound bitter/angry, it's probably because I've been doing it for too long and grown tired of how tedious and limited it is.
[+] [-] jules|15 years ago|reply
Another answer is to compile your favorite language down to Javascript. This gets you the expressiveness at the cost of a slowdown in runtime speed. Languages like Coffeescript are very close to Javascript so they don't incur much overhead by doing this, but even this approach can't go as fast as code running on Native Client.
[1] http://code.google.com/p/nativeclient/
[+] [-] jinushaun|15 years ago|reply
However, CoffeeScript provides an interesting look into the future of Javascript. I also see a similar thing happening with CSS and Less, where people are no longer waiting for browsers to support features developers want.
And lastly, I personally really enjoy coding in Javascript. The ugliest part about it is the DOM and Jquery successfully hides that. I think part of the reason Node.js is so popular because of the strength and programmer joy of the language.
[+] [-] Detrus|15 years ago|reply
To run compiled binaries from such languages you'll use Native Client http://code.google.com/p/nativeclient/ and Pepper APIs which let you access HTML5.
Go gets rid of some insecure low level things like pointers, keeps such things in an unsafe package to discourage its use. They intend to make it seamlessly compatible with NaCl. C/C++ code needs to be modified to work there.
JS is already not suitable for lots of stuff. Vendors are stretching its capabilities with big teams of fancy programmers implementing fancy VMs with big chunks written in assembler. At Google I/O they mentioned V8 is about as fast as it will get. Then bigger teams are writing massive APIs because even with fast VMs the language isn't fast enough to roll your own CSS/XAML/MXML/HTML parsers or 2D rendering contexts. So you're forced to wait or hack together things like LESS, CoffeeScript, Stylus in an attempt to communicate with the overlords.
With the browsers becoming the operating system for many users, you need a runtime that's as powerful as a regular operating system. Google and Mozilla are major players and it's nice to see them exploring alternatives.
But even if NaCl/Go is superior technologically, it may not overcome JavaScript's business and political momentum. As usual, technology is not chosen based on technological merit, but business considerations like legacy, lock in, etc. Perhaps NaCl/Go approach will succeed but it will be too little too late. Kinda feels that way with Flash and Browsers, they're finally serious platforms but might be too far behind Objective-C, C# and Java on mobiles.
[+] [-] knowtheory|15 years ago|reply
That said, JavaScript really is an awesome language to use, if you can get over the syntax. So i really can't see how JS would be unsuitable for future use, especially in light of the changes that have happened and continue to come down the pipeline in newer versions of JS.
Coffeescript is a fantastic view of the power and capabilities of JavaScript packaged in a way that is considerably more elegant to look at and use on a daily basis. Check out the talk that Brendan Eich and Jeremy Ashkenas did at JSConf (http://news.ycombinator.com/item?id=2662846 ).
Javascript really is going to be a development powerhouse for the foreseeable future. And i'm actually happy about that.
[+] [-] jerf|15 years ago|reply
The logical conclusion of this line of argument is pretty much NaCL: http://code.google.com/p/nativeclient/ Is that the anwser? Is there some intermediate where Javascript isn't the only choice for everything but we don't go to the other extreme?
Beats me, but we'll all find out together. But my main point is that it definitely is not the case that Javascript is just the answer to everything and the situation is just peachy keen as it is. It isn't the answer to everything. No one language is. Either we get something else into the client, or we face some combination of wasted effort jamming programs into a language that doesn't really want them and applications simply never written because they don't work well with Javascript's abstractions. Maybe that's OK too, maybe we want a distinction between "native" and "web" app.
[+] [-] davidw|15 years ago|reply
http://en.wikipedia.org/wiki/Lingua_franca
Also: no, probably not. We're still dealing with browsers that are 10 years old, so even if you were to release a browser, with, say, Tcl as the default language, it'd be years before it was something you could count on being everywhere.
See: positive network externalities, and "lock in".
[+] [-] kenjackson|15 years ago|reply
I'm not saying to get rid of JS, but it would be nice to have a first class alternative.
[+] [-] robin_reala|15 years ago|reply
[+] [-] Ruudjah|15 years ago|reply
[+] [-] zrl|15 years ago|reply
[+] [-] rw|15 years ago|reply
It is evolving: Coffeescript, node, npm, and V8 are four examples. It can feel good to code in JS, just like it can in Python or Ruby (or Scheme :-) ).
[+] [-] phillmv|15 years ago|reply
[+] [-] liquidcool|15 years ago|reply
That said, Apple is making it really hard for developers to choose it for all but intranet apps (for which it's really well suited).
I second GWT and the responses here have prompted me to look into CoffeeScript, so thanks for asking this!
[+] [-] dstein|15 years ago|reply
If JavaScript continues to be improved (Harmony, V8/Spidermonkey engines, etc) then I see no other language on the horizon that will replace it.
[+] [-] kwamenum86|15 years ago|reply
[+] [-] sktrdie|15 years ago|reply
I've tried many different languages, including the real pretty ones such as Ruby and Python, and I just have more fun using JavaScript because of how free-form it is.
[+] [-] Stiffy|15 years ago|reply
However, people are now using JavaScript for development that far exceeds those uses. JavaScript is just not suitable for larger applications.
Once your application starts exceeding a few thousands of lines of code, the problems become very clear. You soon wish you were using a language like C++, Java, C#, Python, or Ruby. Toss in a development team made up of at least several people, if not more, and the pain becomes far greater.
[+] [-] bauchidgw|15 years ago|reply
[+] [-] VMG|15 years ago|reply
Don't get me wrong, I love coffescript, but it clearly is a hack.
The internet landscape would look very different if browsers had a standardized bytecode interpreter.
[+] [-] jensnockert|15 years ago|reply
It will be harder and harder for ruby/python/perl/x to compete with js in the future just because people know js and because it essentially runs everywhere fast.
WebCL, WebGL and friends will cover anything with extreme computational needs, and that will be everything you need to learn to write applications in the future, unfortunatly.
[+] [-] haikurion|15 years ago|reply
[+] [-] neilk|15 years ago|reply
Be more specific. Every programming language is not-so-suitable for stuff we want to do.
> Are there any attempts being made to provide an reliable alternative or can JS itself evolve ?
What's "unreliable" about JS? The lack of standardization in available features among browsers? That's an issue, but it will be dealt with, one way or another. C gained a huge infrastructure of tools and standards to make it more portable, and platforms that didn't or couldn't keep up are no longer used.
This presentation from Velocity 2011 shows just how far JS has come. The author suggests that in the next iteration will be type inference in JS engines and/or optional explicit typing in the language.
http://www.slideshare.net/newmovie/know-yourengines-velocity...
[+] [-] frobozz|15 years ago|reply
Just like some languages have tools to translate them to C, there's no reason why you wouldn't use a tool to compile from a language more appropriate to your task, into javascript.
[+] [-] reedlaw|15 years ago|reply
[+] [-] arethuza|15 years ago|reply
That's already been done: http://code.google.com/chrome/nativeclient/
[+] [-] yottabyte47|15 years ago|reply