Just to clear one thing up -- Oscar writes: > The examples on the CoffeeScript site are purposely written > to be ugly to make CoffeeScript look even prettier. ... not at all. The side-by-side examples on CoffeeScript.org are showing you the compiled output . The point is to demonstrate -- although it's certainly far from perfect -- how CoffeeScript features can be compiled into clean JavaScript. Really, our goal is…
Writing Eloquent JavaScript Without CoffeeScript
31–40 of 55 posts
Re: Writing Eloquent JavaScript Without CoffeeScript
#32Oscar, when your code itself is making little frowny faces at you after you write it, something has gone wrong. x == 1 ? alert(x) :( alert('Error'), x = 1, alert('All Fixed!') );
Alerting 'All Fixed' and afterwards 'Error' seems like it'd be just as valid an interpretation of the code.
Edited to add: Actually, I think the comma operator does do that, so no bad. Though the code is still unsightly...
Re: Writing Eloquent JavaScript Without CoffeeScript
#33Just to clear one thing up -- Oscar writes: > The examples on the CoffeeScript site are purposely written > to be ugly to make CoffeeScript look even prettier. ... not at all. The side-by-side examples on CoffeeScript.org are showing you the compiled output . The point is to demonstrate -- although it's certainly far from perfect -- how CoffeeScript features can be compiled into clean JavaScript. Really, our goal is…
This kind of clarification is exactly why I posted this link. It's great to clear the air in one respect and at the same time ask the question, "is there something on the CS site needing change to avoid this confusion?"
Re: Writing Eloquent JavaScript Without CoffeeScript
#34But feel free to correct me if I'm wrong, but I doubt vanity is the primary reason people are using CS. My number one favorite feature is the list comprehension, and if it didn't have that, I might not be bothering with it.
Re: Writing Eloquent JavaScript Without CoffeeScript
#35Re: Writing Eloquent JavaScript Without CoffeeScript
#36So Javascript can be formatted to look kind of like CoffeeScript?
While I agree that Javascript is often misunderstood, to me his formatting of Javascript is making things much worse, in terms of maintenance (yeah...let's all line up equal signs...).
I personally DO NOT write CoffeeScript but I think the difference between CoffeeScript and Javascript goes beyond formatting. Writing CoffeeScript seems to me to be a syntactic improvement and eliminates some of the need to really learn Javascript (which I think takes quite a bit of effort)
Re: Writing Eloquent JavaScript Without CoffeeScript
#37They work only in a monospaced font. I code in a proportional font, and none of the column alignment tricks will look right when I view the code.
Even if you like to code in a monospaced font, there's no reason to write code that becomes hard to read in a proportional font. It's very easy to write code that is perfectly readable in both monospaced and proportional fonts: you merely forgo these column alignment tricks.
Also, this style of code is a pain to maintain. If you add a variable with a longer name, you have to go up and down adding spaces in front of all the other = signs.
And I find it hard to read even in a monospaced font, e.g.
var i = 123
, j = 456
, k = 789
, aMuchLongerVariableName = 'foo';
Matching up the initializer values for i, j, and k means my eye has to scan way across a sea of whitespace and hopefully remember which line is which when I get there.Finally, the example with the escaped newlines all in a vertical column does not do at all what he expects! All those extra spaces become part of the string.
Re: Writing Eloquent JavaScript Without CoffeeScript
#38Just to clear one thing up -- Oscar writes: > The examples on the CoffeeScript site are purposely written > to be ugly to make CoffeeScript look even prettier. ... not at all. The side-by-side examples on CoffeeScript.org are showing you the compiled output . The point is to demonstrate -- although it's certainly far from perfect -- how CoffeeScript features can be compiled into clean JavaScript. Really, our goal is…
This kind of clarification is exactly why I posted this link. It's great to clear the air in one respect and at the same time ask the question, "is there something on the CS site needing change to avoid this confusion?"
CoffeeScript on the left, compiled JavaScript output on the right.
Maybe the two halves should have the headers directly aligned above them:
> CoffeeScript
> The JavaScript that it compiles to.
Other than that, it's hard to make it any clearer for its intended audience (people who know JS and know what the words "compiled" and "output" mean).
Still, I'm tempted to upvote the OP as good Friday satire.
Re: Writing Eloquent JavaScript Without CoffeeScript
#39Oscar, when your code itself is making little frowny faces at you after you write it, something has gone wrong. x == 1 ? alert(x) :( alert('Error'), x = 1, alert('All Fixed!') );
thing[conditional ? 'show' : 'hide']();
instead of:
thing[if conditional then 'show' else 'hide']()
Re: Writing Eloquent JavaScript Without CoffeeScript
#40There are some real problems with these "eloquent" styles. They work only in a monospaced font. I code in a proportional font, and none of the column alignment tricks will look right when I view the code. Even if you like to code in a monospaced font, there's no reason to write code that becomes hard to read in a proportional font. It's very easy to write code that is perfectly readable in both monospaced and proport…
That's really your problem. If you think people will stop aligning things in their code because you are in the tiny minority that use proportional fonts, you're crazy.
> Matching up the initializer values for i, j, and k means my eye has to scan way across a sea of whitespace and hopefully remember which line is which when I get there.
Nobody's actually going to do what you just showed in real code. Instead, it would look like this:
var i = 123,
j = 456,
k = 789,
aMuchLongerVariableName = 'foo';
And still look quite good.> Finally, the example with the escaped newlines all in a vertical column does not do at all what he expects! All those extra spaces become part of the string.
Absolutely, but if you are putting HTML in that string (a while other discussion there) 99% of the time the whitespace will not matter. And for all the other cases, this is no different from multiline string behavior in Python and other languages.