Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's this general idea that I've found quite illuminating, where physical code size in itself can cross a certain limit and suddenly take more time to read.

Something like (+ 5 (* 3 2)) is, IMO, an easier think to parse than add(5, multiply(3, 2)). 5 + (3 * 2) obviously wins some points from being what we get taught for a decade.

So if you have these sorts of idioms that are meant to be within other idioms, stuffing them all in one line means there's less place for issues to hide, without paying size costs.

The real thing of course, is less the above example and more things like:

results = [2 * x for x in data]

turning into:

results = [] for x in data: results.append(2 * x)

Where in one version I immediately pattern match on a comprehension, so I can immediately determine cardinality and other properties, where the other one I gotta do a _touch_ more work mentally. This feels like it doesn't matter, but it all adds up!

Terseness is a quality, especially if everyone messing with the code speaks the same vocabulary.



> 5 + (3 * 2) obviously wins some points from being what we get taught for a decade

It also has the benefit of having an obvious starting point: on the left, and moving to the right compared to "on the right but inside all of the parentheses, but don't ignore them because they're needed!" Where it fails is the implicit assumption of operator precedence, which breaks the "left to right model". If anything though, I'd argue that eliminating precedence rules and requiring parentheses for anything other than strict left-to-right order would be _more_ intuitive, and the fact that we were all taught about the "order of operations" is the only reason it isn't obvious that it's probably not better for anything other than writing polynomial expressions, which is not something that most people will ever do outside of the specific educational context where we're taught the precedence rules in the first place.


Of course that would also just be written as results = 2*results in array languages


Or indeed just results*:2


I had the same question as the person you replied to, and these excellent examples really made it click for me. Especially the second one. Thanks for sharing.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: