Powerful Python reader Emmanuel asks a great question about the Levels of Python Code:
"Thanks for sharing this. Can we also refer to the break statement as in the idiom level? Or is it syntax level?"
To review, the 4 levels are
3) Design patterns
So, with code like this:
- # Process lines in a file.
- # Stop when you hit a blank line.
- with open(path) as handle:
- for line in handle:
- if line.strip() == "":
- break # No more lines
How would you classify that "break" statement? Is it syntax, or is it an idiom? Is there even a "correct" answer?
What I replied:
"That's a great fun question.
When I say there are 4 levels of Python code, that is a mental model that is more simplified and less nuanced than the full reality of complex code...
Which means we can identify aspects of Python that may not fit cleanly into one of those 4 categories.
I think "break" is a good example of this. I would say it's between the syntax and idiom levels, but closer to the syntax level. But good arguments could be made for other interpretations."
The reality is, much of what's powerful about programming spans all these levels, oozing between them.
And you might like the Powerful Python Book because of how it focuses on, er, this ooze.