4 ms·
Your Javascript example is a bit contrived too. How about: foods.filter(function (e) { return e !== 'chocolate'; }).forEach(eat); Regardless, I disagree tha
by olalonde 13y ago
Your Javascript example is a bit contrived too. How about:
foods.filter(function (e) { return e !== 'chocolate'; }).forEach(eat);
Regardless, I disagree that the Coffeescript example is more readable. My brain is much faster at parsing symbols (`(`, `{`, etc.) than english words.
With your JS example, without having to read the words, I know there's a loop, a conditional and a function invocation. I also know that I can safely add statements after this piece of code without worrying it might break some other function (in Coffeescript, I'd have no way to tell if the implied return really mattered or not assuming it was the last line of a function).
With your CS example, I have no way to tell what's going on until I've read the full sentence. I have to read every word and see if it matches one of the many reserved keywords in order to determine if it has a special meaning or if it's just a regular variable.
In Javascript, you have a few reserved words but the list is relatively short and those words are almost always preceded by a line break or a symbol.
Maybe our brains work differently...
- colbyh 13y agoI'm obliged to agree. Even the "contrived" example is easier for me to parse given that I have years of seeing "{}[]()" as delimiters. Not to mention that filter/each functions will get even easier to parse once es6 standards reach the browser (stabby procs, woo).
- shittyanalogy 13y agoI don't understand. Because you have been doing something one way for years, a different way is harder and thus worse? I'm not trying to be inflammatory at all just wondering as this is a reply to my comment.
- shittyanalogy 13y agoAgreed, I dig the functional example you posted. Completely personally I think the CS example I posted fits my style more and is a bit terser. Also the CS reserved word problem you speak of surely isn't harder than learning to program in the functional style. I mean come on. ;)
- olalonde 13y agoI agree that using functional style was not fair (comment edited :)). By the way, here's a non contrived CS example directly from CS's source which I find really hard to understand: https://github.com/jashkenas/coffee-script/blob/master/src/grammar.coffee#L612 https://github.com/jashkenas/coffee-script/blob/master/src/g... tokens = [] for name, alternatives of grammar grammar[name] = for alt in alternatives for token in alt[0].split ' ' tokens.push token unless grammar[token] alt[1] = "return #{alt[1]}" if name is 'Root' alt Why is a loop assigned to a variable? I understand that loops are expressions but the intent here is not immediately clear and definitely requires some thinking. That's what I mean by readability (terseness is another thing).