Rule of Six
TL;DR
A line of code should do <6 things.
- human short-term & working memory can only cope with upto 6 pieces of info simultaneously
# bad
map(lambda x: x.split('=')[1], s.split('?')[1].split('&')[-3:])
# good
url_query_string = s.split('?')[1]
query_params = url_query_string.split('&')[-3:]
map(lambda x: x.split('=')[1], query_params)
personal opinion
The article begins by implying x, y = 2, 7
is bad. I disagree. I am against blanket-banning legitimate language features. Such bans miss the point. The point is to minimise time-to-comprehend. Everything needs to be considered on a case-by-case basis.
Highly human-readable, brilliant inlining of a single-use class TimeWindow(start, stop)
:
start, end = 2, 7 # time window in hours
max_retries = 1 # unrelated to above, so separate line