3 ms·
I remember in college, even Python often turned into "code golf" style competitions. Could we collapse this 10-line block into an incomprehensible nested list c
by xvector 7y ago
I remember in college, even Python often turned into "code golf" style competitions. Could we collapse this 10-line block into an incomprehensible nested list comprehension? Why not!? Surely 1 line is better than 10 lines!
Later in college when we started doing more team projects, comprehensible code became much more important. No one had the time to understand someone's doubly-nested list comprehension. We just wanted to finish the project and get on with life. In this sense, I think the moment you read someone else's shitty code is the moment you realize that you need to write good code yourself.
Still, I'd say it was good practice and helped me think about code in different ways.
- cwp 7y agoThere is an element of relativity to this though. I guarantee that there are programmers and teams for whom nested list comprehensions are much more comprehensible than 10 lines of loop code that could be doing anything and have to be carefully analyzed to be understood. This holds for just about any programming technique that you might encounter. Of course, Kernighan's law still applies, it's just that the definition of "too clever" recedes with skill and experience.
- Gibbon1 7y agoA counter is a saw a blog post by a CS professor picking apart of a single line implementation of the Sieve of Eratosthenes. She points out the first clue is that it's performance is bad, like really really bad. And then shows it's not actually implementing the Sieve of Eratosthenes. I might just be dumb but I've been bitten so many times I'm dubious anything can be verified by inspection.
- tyurok 7y agoI have experienced this. The most brilliant programmer I've ever worked with wrote hardly comprehensible code since they could understand other's code easily, so they didn't feel the need to write readable code because, in their word, "What do you mean you don't understand it? It compiles, it runs, it works, you don't need more than that".
- stared 7y agoSome parts of Python are good for readable code, some - not. I bemoan lack of nice chaining. Some libraries provide APIs that allow chaining, e.g. Pandas. In other cases, I often find JavaScript (map/filter) and R (dplyr pipe operator) pipelines nicer to read. However, Python 's Zen of Python can (and IMHO: should) be adopted to other languages.