4 ms·
It's a tool, that is all. Ambiguous code is a poorly thought out contrived example with a simple solution. To me, this: eat food for food in foods when f
by shittyanalogy 13y ago
It's a tool, that is all.
Ambiguous code is a poorly thought out contrived example with a simple solution.
To me, this:
eat food for food in foods when food isnt 'chocolate'
Is kind of beautiful and much more readable than:
for (var i = 0, var len = foods.length; i < len; i++) {
var food = foods[i];
if (food !== 'chocolate') {
eat(food);
}
}
How is this even an argument?: "One wouldn’t realize it was conditional until reading the end."
How do you expect to understand any code without reading it?
How do you understand people when they talk without listening? And the whole paragraph is moot with syntax highlighting.
Variable clobbering is javascript's problem not coffescript's.
ECMAScript 6 introduces a syntactic sugar for classes as well as like every single JS framework.
Knowing plain old JS is important, especially for understanding CS. CS is just a tool that some people find useful, I don't really understand the passion or frustration.
- c0nfused 13y agoWhile on the one hand I agree with your overarching point, I actually find the second set of code tells me much more about what is going on. That might be because I have been doing curly brace languages for a decade but tells me more, Foods is an array, not an object. The word isnt as a keyword also makes me want to scream inside a little every time I see it:) That said you are totally right, It's a tool in a category of tools I never really got into.
- olalonde 13y agoYour 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).