4 ms·
Split Into Multiples Lines has a real problem, which appears in the example code. Let say you have a long code block that includes the revised snippet: > quer
by d_burfoot 4y ago
Split Into Multiples Lines has a real problem, which appears in the example code.
Let say you have a long code block that includes the revised snippet:
> query_params = s.split('?')[1].split('&')[-3:]
> mylist = map(lambda x: x.split('=')[1], query_params)
> ...
> ...
> (some more complex transformations, that only depends on mylist)
When you're reading the later stages of the code, you still have to maintain a memory of what "query_params" does, even though it's no longer relevant. That actually increases the burden on your working memory. The one-liner is more complex to understand initially, but it self-documents that the only info that is relevant to the downstream is the result of the map(...).
In general, the more variables that are declared in a code block, the more effort it is to understand, and the effect is probably superlinear with the number of variables. I'd say if you have to declare more than 5-6 variables, you should split into a separate function.