4 ms·
> CoffeeScript encourages creating small flexible code blocks, which together make a powerful structure. This all leads to fewer opportunities for bugs to appea
by MatthewPhillips 14y ago
> CoffeeScript encourages creating small flexible code blocks, which together make a powerful structure. This all leads to fewer opportunities for bugs to appear.
Personally I find single-line statements that do too much to be difficult to read.
I also find nested functions really difficult to read in CS. From a coffee mug I own:
coffee.height drink coffee, e.angle
That's only 2 functions, it gets much more confusing when it's 3 or 4 which multiple parameters. Before you say "don't nest functions that way", I agree completely, however a large part of the appeal of CS is reducing LOC and these one-liners, so in real world code I've come across this often.
- lowboy 14y agoYeah, I'm with you on this one. However, you can add brackets if you want (and I often do): coffee.height(drink(coffee, e.angle))
- Cushman 14y agoYou can even use sexpy syntax if you want to confuse people: (coffee.height (drink coffee, e.angle))
- meric 14y agoIt looks like it borrowed that syntax from Haskell.
- xanados 14y agoHaskell programmers hate parentheses. They would write it as: flip coffee.height e.angle $ drink coffee Where "flip" is the function that reverses the order of two arguments of a function and "$" is basically like a set of parentheses that are implicitly closed at the end of the line.
- pooriaazimi 14y agoRespectable CS coders I've seen "never" code like that. Jeremy (among others) have always said that you should "always" use parenthesis when not using them makes code ambiguous even in the slightest bit. So, you should write than as coffee.height (drink coffee, e.angle) Also, understand that you can use parenthesis in a lot of places to remove ambiguity: setTimeout ( # ... ), 400 instead of setTimeout # ... , 400 Or doSomethingWithHashAndOtherVars { var1: 1 var2: 1 var3: 1 }, var4, var5 instead of doSomethingWithHashAndOtherVars var1: 1 var2: 1 var3: 1 , var4, var5 ------- Rule of thumb: When in doubt (or fear of future doubt), throw a couple parens around expressions, and a couple braces around objects.
- tjholowaychuk 14y agolooks terrible either way
- OriginalSyn 14y agoAs a rule of thumb I use braces and parens as a standard. I think making parens and braces optional was a mistake and they are necessary punctuation to the language. There is simply too much ambiguity without them and then when you're mixing and matching things become unreadable.
- comex 14y agoI wonder whether people would be less skeptical of CoffeeScript if its syntax were a bit closer to Python's: more parens, but simpler and clearer. For instance, what are Perl-style backwards if statements doing in CoffeeScript? They make it impossible to tell what a statement does by looking at the beginning of it (e.g. in other languages, "foo = ..." is almost always semantically an assignment of foo, and always syntactically an assignment) and thus decrease readability, just to save a pair of parentheses.