News for hackers. Stuff that matters.
Re:List of languages that compile to JS by 198d on Thursday January 06, 2011 @10:49AM (#2075699)
Am I the only one who just plain doesn't understand the value these tools provide? From my perspective, why not just _write_ javascript? Seems ridiculous. I mean, they're fun and all, but no one sets out to do a project of meaning or scale and chooses these tools, do they?
Re:List of languages that compile to JS by gruseom on Thursday January 06, 2011 @12:37PM (#2076255)
no one sets out to do a project of meaning or scale and chooses these tools, do they?

We certainly have (Parenscript) and it's vital for two reasons: (1) there are cases where we need to run the same code on either the server or the client; (2) we get the full power of Lisp macros. The latter means our source code is much smaller than JS we would have had to write by hand. Somewhat unexpectedly, there's a key efficiency issue here: making heavy use of abstractions in JS would make our code significantly slower. With Parenscript, we can write concise source code with nice abstractions that compiles to low-level, efficient (but still readable) JS. It's one of those rare times you get to have your cake and eat it too (an adage that really doesn't make sense, yet still always comes up #1 in the search results in my brain!)

Re:List of languages that compile to JS by grayrest on Thursday January 06, 2011 @02:09PM (#2076678)
I've switched over to CoffeeScript for all projects where I get to choose. It's an all around better language than js if you tend towards the functional side.

Iteration/comprehensions work like they should[1], destructuring simplifies extraction, there's a prototype binding construct in the language, less line noise, and everything is an expression. I also happen to like indent-significant languages and think it's a great DSL language.

I could certainly produce the same code writing in JS, but what would the advantage be? I'm already doing a build step for combo/minification and if not, a --watch compile gives roughly the same workflow as raw JS. I have to search for a snippet of text rather than going to a line number when I'm debugging, but I think the coding gains/cleanliness is worth the slightly increased debugging effort.

[1] With one gripe, `y = x + 1 for x in 0...10` got changed in August to match up with `z = x if x % 2` and friends (it was special cased) so y is now 10 instead of the array 1..10 and you have to wrap the comprehension in parens.

Re:List of languages that compile to JS by jgfoot on Thursday January 06, 2011 @10:55AM (#2075733)
I enjoy using CoffeeScript on my hobby projects. If you write your server code in a language like Python or Ruby, CoffeeScript makes Javascript more familiar. It adds nice features like list comprehensions, and I prefer the way it handles classes and objects. But no, it isn't for everyone.
Re:List of languages that compile to JS by windsurfer on Thursday January 06, 2011 @11:19AM (#2075854)
The same reason people don't just write in assembly (or more accuratley, C) to write a desktop application very often. Javascript is the assembly language of the web.
Re:List of languages that compile to JS by defrex on Thursday January 06, 2011 @11:48AM (#2076004)
That analogy breaks down though. JavaScript is just as much of a high-level language as most of the things that are compiling to it. Most of the time the reason people don't just write in JavaScript is because they don't like it's _style_, rather then with C or assembly, where the goal is to work at a higher level to avoid writing boilerplate and managing things are are unnecessary.
Re:List of languages that compile to JS by wahnfrieden on Thursday January 06, 2011 @12:22PM (#2076178)
It doesn't break down entirely though. Imagine we were all restricted to C++ for writing desktop software (although that's nonsensical, it's the case with JS and the web) - wouldn't it be reasonable to start developing other languages that compile to C++?

If you can output JS that's fast enough, why not?

Re:List of languages that compile to JS by sedachv on Thursday January 06, 2011 @05:01PM (#2077450)
I agree with you esp. when it comes to GWT - going from Java to JavaScript is going from a terrible language to an ok one. There are two reasons why it has become popular:

  Java programmers don't want to learn JavaScript
  It comes with good UI building tools
If GWT didn't have good UI building tools, Java programmers wouldn't have any excuse not to learn JS and program normal web applications. But here's a tool that lets them use their existing Java knowledge to build halfway decent web GUIs.

This is just another example of how technologies are chosen by considerations other than objective technical merits.

Re:List of languages that compile to JS by wahnfrieden on Thursday January 06, 2011 @11:29AM (#2075899)
Google Wave and AdWords were built on GWT, which is Java->JS. So yes, they do.
Re:List of languages that compile to JS by sedachv on Thursday January 06, 2011 @04:48PM (#2077384)
AdWords UI didn't start out on top of GWT, I think they switched over sometime in 2009.
Re:List of languages that compile to JS by gommm on Thursday January 06, 2011 @11:43AM (#2075977)
I used to think the same way as you do... I couldn't understand the point of using ruby or java (GWT) to generate javascript (and I didn't understand the popularity of rjs in rails). First, on the contrary to many, I actually like javascript and, second, I founnd that it's just didn't feel like a really good fit...

Now though, I use CoffeeScript but it's very different to the above. It was made with javascript in mind, it's more of a clean syntax for javascript, allowing you to code exactly like you would normally in javascript but in cleaner, neater way..

Re:List of languages that compile to JS by jerf on Thursday January 06, 2011 @12:18PM (#2076158)
For the same reason people don't write everything in Javascript. It is not the global optimum language any more than any other language is, and there are tasks where it is easier in programmer terms to write in another language that can have stronger guarantees or a better DSL for some task or whatever than Javascript. As more and more stuff moves to the client an expanding range of client tasks falls under this category.
Re:List of languages that compile to JS by postfuturist on Thursday January 06, 2011 @02:42PM (#2076826)
Most projects do just use straight JavaScript which is a big problem. JavaScript does all the wrong things by default. "for in" loops and "==" comparisons are a couple big offenders, that often appear to do the right thing (but fail later in unexpected ways). Any of these compilers worth their salt will limit their output to properly formed loops and comparisons and otherwise cross-browser compatible code, etc, saving you from a great deal of pain.
Re:List of languages that compile to JS by wladimir on Thursday January 06, 2011 @02:55PM (#2076873)
Are you serious? GWT is used in a lot of large, commercial projects. And of course by Google itself which also isn't exactly small-scale :)
Re:List of languages that compile to JS by boneheadmed on Thursday January 06, 2011 @12:35PM (#2076233)
One reason is to be able to consistently work with the same language both on the server and on the client. In this way one doesn't need to change gears all the time. I do like JS, but I'd rather use Ruby (or language of choice) most of the time.