Isn't this precisely the problem? Why make a better Javascript then make the same mistakes as the original? One of the main goals is for Coffeescript to be more readable that Javascript. Having ambiguous syntax and so many different ways of doing things means that people will write code in all of these different ways.
Your rebuttal is a long list of what you SHOULD and SHOULDN'T do, but there are two problems:
1. Not everyone will agree with you.
2. People will write it the "bad" way anyway.
Ultimately this means less readable code, especially when you have to read someone else's code.
People will write bad code in every programming language you give them. I don't see that as a justification for limiting the expressiveness of a language. If you take that line of reasoning too far you end up with Java.
That's a straw man. I never said that the expressiveness of the language should be limited. There are plenty of languages that are just as (more?) expressive than CoffeScript without the syntactical ambiguity.
> If you take that line of reasoning too far you end up with Java.
That's the slippery slope fallacy. I am in no way suggesting that CoffeScript should have completely rigid syntax. Surely there is a happy medium between CofeeScript and Java. There are plenty of languages that live there.
Even python's critics would admit it's a very readable language, and it would be unusual to claim it's not expressive.
x = 3;Is it really more expressive just because there are N ways to do it?
In short, it was badly designed. Pointless to use it.
In CS, assign everything to a var, because good luck parsing CS tokenization.
In JS, assign a few things with a keyword or explicitly to a namespace, because good luck with global state(s).
Unfortunately, only the later is recommended, while the former is NOT and discouraged in lieu of being so verbose like the later. sparkles
You don't always have to assign things to vars.
If you have two or more function calls on the same line, use parentheses after the first one. Or use parentheses in all of your function calls. Its just an advantage for some people to be able to leave the parens out because it is a little more readable for them. Otherwise, you can just write it the same as you would in JavaScript.
Scope is another big advantage of CoffeeScript.
Same goes for parentheses "here or there but not there, sometimes." This may very well be the anathema for those that don't understand the claims that ";" or "function" or "}" are real burdens.
doSomething () -> 'hello' just isn't valid code.
Is valid code. Not that you'd ever actually want to use it: coffee> doSomething = (fn) -> if fn then fn() else (-> 'hi')
doSomething = (fn) -> if fn then fn() else (-> 'hi')
[Function]
coffee> doSomething() -> 'hello'
doSomething() -> 'hello'
'hi'
coffee> doSomething () -> 'hello'
doSomething () -> 'hello'
'hello'To make the OP assessment of CoffeeScript fair we would have to apply the same logic to Javascript its self. If we looked at any minimised JS code we would have to conclude that the language is unreadable.
In 1948, Edward Murphy, Jr. an aerospace engineer, was working for the Air Force to install sensors to test g-forces on humans during deceleration. There were two ways to wire each sensor, and one of them was wrong. Someone had methodically installed every single sensor backwards. Murphy quipped something -- no one is exactly sure what it was -- which was cited in the Aviation Mechanics Bulletin as "Murphy's Law: if an aircraft part can be installed incorrectly, someone will install it that way." A few mutations later and this became the famous "Murphy's Law".
I think the original Murphy's law applies with great force to the world of programming languages. If there are multiple ways of doing something, and some of them are stupid, you still have to know all of those stupid methods because some idiot on your team will do it. The probability of this happening increases as the size of your team increases.
The proper course of action as a language designer is to make sure that foolish methods are not built into your language. What you do not do is design foolish methods into your programming language, and then put up a big sign on Hacker News saying "don't do that".
The Original Murphy's Law is so critical to the design of systems -- languages, APIs, libraries, etc., that after your post I feel compelled to ask you to put down your Programmer's Card and step away from the keyboard at this time.
Since you are obviously an expert in programming language design, I am curious to know, what programming languages have you designed?
He made it flexible in order to appeal to people who want a functional programming style and like to be clever. I don't want to deal with that type of code especially but some people actually prefer that way if that is the way they have been programming for a number of years or if they are just looking for something new.
"Put down your programmer's card" -- very uncalled for.
Any language can be abused or used in styles that are difficult to read or maintain. Almost all languages that I have seen have more propensity for that than CoffeeScript.
This one of the best language designs ever because of the significant whitespace (which to me is logically the most obvious rebuttal to your comment), small amount of required punctuation, intuitive and practical keywords, solving many of JavaScript's problems, appeal to Ruby enthusiasts and functional programmers which represents a sizable chunk of the best software engineers in web development, and compatibility with JavaScript. In order to do all of that it needs to have the flexibility that we are discussing.
CoffeeScript allows for the closest thing to my pseudo-code that I have seen.
Anyway I have spent way too much time on this discussion already.
...
> Since you are obviously an expert in programming language design, I am curious to know, what programming languages have you designed?
...
> Any language can be abused or used in styles that are difficult to read or maintain.
These were three classic fallacies in a row.
As to the second one (ad hominem demands of authority): an in argument, it is never classy.
That being said:
> "Put down your programmer's card" -- very uncalled for.
That was meant as a joke but I can see that it might deservedly cause offense. And so I rescind it and apologize.
> doSomething (->
> 'hello'), 1
> Indentation is significant in CoffeeScript, just like it is in Python. Just having a parenthesis shouldn't change that.The point, I think, is that the example above should be an error instead of compiling into something you wouldn't expect.
Here's a syntax I've seen a lot:
doSomething ->
'hello'
, 1
or even doSomething ->
'hello'
,
1
That style is also handy to construct a long list of object literals.> This is called destructuring assignment,
I think destructuring assignment is something else entirely. http://coffeescript.org/#destructuring
> its probably better to use isnt instead of !=, although rather than !=, you would want !==
'!=' is equivalent to 'isnt'. And '!==' is not CoffeeScript at all.
Er... in Python, having a parenthesis does change that, within parens Python uses continuation lines which are not subject to the same restrictions as free-floating code.
Usually I would write
or maybe If you write it the way he did, the parenthesis are confusing.For this one:
-- first of all, you always want to indent two spaces. But the main problem with that is in CoffeeScript you do need to use parenthesis after the first call because your code will be unreadable otherwise. You just can't write it the way he did. Those are ridiculous examples. No one does that. You just write moveTo 10, 20, 10 Indentation is significant in CoffeeScript, just like it is in Python. Just having a parenthesis shouldn't change that. Anyway, what I do is this: and then I can just write You don't write it like that if the function takes two objects. You would probably just write This is called destructuring assignment, and its part of the new ECMAScript. Its useful to not have to repeat key1, key2 everywhere when the variable with the value has the same name as the object property. The extra curly braces are just necessary to differentiate from the normal syntax.Sometimes yes/no or on/off are more readable than true/false. That's an advantage.
Don't use semicolons in CoffeeScript. I also don't put if statements at the end of a line because I don't believe that is very readable for most people including me. Also, in CoffeeScript its probably better to use isnt instead of !=, although rather than !=, you would want !==. I'm not that sure about the use of unless, although it probably is a little bit more readable overall. He says that is supposed to delete TERMINATOR from tokens. I tested it, it doesn't do anything, and the second example of the correct way doesn't work either. I think he meant this: Another example of something you CAN do in CoffeeScript but shouldn't. Actually it is a bad idea in general. I think a CoffeeScript programmer would actually write something like this: I would never write something like 'mainModule.moduleCache and= {}'Instead of
I would write