5 ms·
I completely agree. English is English, code is code. I prefer `map`, especially when the function is any more complex than `i * 2`. And suffix conditionals (a
by thenduks 15y ago
I completely agree. English is English, code is code. I prefer `map`, especially when the function is any more complex than `i * 2`.
And suffix conditionals (and the like) are mostly useful to me when it's much shorter and sweeter, but doesn't lose any clarity:
return false if somethingBad
- endtime 15y ago>English is English, code is code. I'm not sure this kind of 'render unto Caesar' thinking is conducive to literate code. Definitely agree with you on the suffix conditionals.
- thenduks 15y agoI just don't think that forcing code to read like English necessarily makes the code any more readable. Sure, if you read it out loud it comes out sounding somewhat like a sentence. That's cool and everything, but when I'm reading code to, you know, understand it... I want it to be succinct and completely unambiguous. Here's a great example from Ruby: `unless is_allowed == false` Reads like English? Check. Sane code? No way. As @heycarsten put it: http://twitter.com/#!/heycarsten/status/28042439329 http://twitter.com/#!/heycarsten/status/28042439329 So I'm suggesting that 'reads like English' isn't the goal you should be aiming for. It's sane, readable code. Sometimes that's English-like (`return x if y`) and other times it's code-like (`list.map( func )`). Obviously there's room for personal preferences to color where you fall on this (and most other things) :)
- endtime 15y agoThat's not really a non-irrelevant example - it isn't different from a double-negative, which isn't a good way to write non-confusing English. I don't see a problem with something like `unless forbidden`, though.
- thenduks 15y agoFair enough, I'm only saying that 'like English' isn't some kind of holy grail of understandable code. I like code, I can read code, not every line needs to be turned into a sentence.