3 ms·
Whenever I nest a list comprehension I feel dirty anyway, I wonder if a better error message will help solve something that is just hard to grasp sometimes.
by teekert 4y ago
Whenever I nest a list comprehension I feel dirty anyway, I wonder if a better error message will help solve something that is just hard to grasp sometimes.
- 8organicbits 4y ago"Debugging is twice as hard as writing the code in the first place. Therfore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Rajanand Although, personally, I enjoy python list comprehensions.
- timoteostewart 4y agoI believe that quote about debugging being twice as hard as coding is by Brian Kernighan. https://en.m.wikiquote.org/wiki/Brian_Kernighan https://en.m.wikiquote.org/wiki/Brian_Kernighan
- 8organicbits 4y agoMaybe, I grabbed the first matching quote I found. I can't attribute it on my own.
- timoteostewart 4y agoNo sweat. I’m a quote nerd so it jumped out at me
- polski-g 4y agoAll list comprehensions should error with message "FATAL PARSE ERROR: Will you really understand this in six months?"
- TremendousJudge 4y agoIf people complain about Rust's borrow checker already...
- wheelerof4te 4y agoList comprehensions should be used for making quick lists that contain simple calculations or filters. Anything more will come back to bite you later.
- teekert 4y agoSomething like this I find ok (just a filter): [x for x in y if x is not z] Sometimes though, facilitated by Jupyter's notebooks making executing as you build the code very easy, I create a beast like this: [os.path.join([x for x in y if x is not z]) + '/bin' for a in b if 'temp' not in a] Yes this is fictional and probably contains an error but you get the point, you can filter lists of lists like this, but it's really unfriendly to anyone trying to understand it later.
- mikepurvis 4y agoNot even with nesting— as soon as it's long enough that I'm breaking it into multiple lines, I'm immediately like, okay this is long enough to just be a normal for-loop, or maybe a generator function. But it doesn't need to be a list comprehension any more.