Re:The Complexity Trap: Think Before You Leap
by malkarouri on Tuesday December 11, 2018 @11:17AM
(#18656320)
Solving things with list comprehensions is very idiomatic in Python.
Also, not nesting things is very idiomatic Python ("Flat is better than nested" is part of the Zen).
So, people generally don't think of nested list comprehensions as idiomatic.
Re:The Complexity Trap: Think Before You Leap
by reificator on Tuesday December 11, 2018 @01:18PM
(#18657386)
And `explicit is better than implicit` is idiomatic python, but the language uses the most implicit characters available on the average keyboard (` ` and ` `) to denote control flow.
Re:The Complexity Trap: Think Before You Leap
by lmm on Tuesday December 11, 2018 @01:42PM
(#18657632)
The language uses indentation levels to denote control flow, and those are very explicit - much more so than braces in fact.
Re:The Complexity Trap: Think Before You Leap
by reificator on Tuesday December 11, 2018 @01:49PM
(#18657689)
They're not though. They only exist as the relation between the edge and the start of content.
How many levels of indentation are there on each line?
https://i.imgur.com/s1WBHxU.png
Spoiler: Line 3 has no indentation while Line 6 has one level. Line 4 has a mix of tabs and spaces that would confuse Python.
The fact of the matter is that indentation is white space, and white space is implicit by definition. It only exists as the gap between other things.
Re:The Complexity Trap: Think Before You Leap
by Franciscouzo on Tuesday December 11, 2018 @03:55PM
(#18658760)
Stop using a legacy version of Python.
You will get a "TabError: inconsistent use of tabs and spaces in indentation" exception if you use Python 3.
Re:The Complexity Trap: Think Before You Leap
by reificator on Tuesday December 11, 2018 @07:00PM
(#18660170)
I haven't used python with inconsistent indentation recently, that's true.
Re:The Complexity Trap: Think Before You Leap
by lmm on Tuesday December 11, 2018 @02:36PM
(#18658133)
In that sense control flow only exists as the relation between other things, so it makes sense for it to be denoted that way. If a line with no code on it is indented in the forest and nobody hears it, does the line execute?
Re:The Complexity Trap: Think Before You Leap
by iak8god on Tuesday December 11, 2018 @03:41PM
(#18658648)
I write my python interactively in a repl, and often end up with deeply nested list comprehensions as a result. I always need to break them up to have any chance of understanding it even a day later.
Re:The Complexity Trap: Think Before You Leap
by umvi on Tuesday December 11, 2018 @02:53PM
(#18658273)
I weep anytime I need to decode a one-liner list comprehension/map/filter/reduce/lambda abomination. Like... would it have killed you to break it into multiple lines and sprinkled in some comments?
Solving things with list comprehensions is very idiomatic python, so the thought process goes "the more of these I can stuff inside each other, the more idiomatic my code is."