4 ms·
Some ways of programming in Python require a LOT of mental effort. And some don't. For example you can do a lot in one line in Python, but I usually have to wri
by globalnode 1y ago
Some ways of programming in Python require a LOT of mental effort. And some don't. For example you can do a lot in one line in Python, but I usually have to write extensive comments and references to external docs to keep track of what that one line is doing. I think sometimes it would be easier if I just had to write 3 or 4 lines of self evident code and use that as docs instead.
- bb88 1y agoHaving written python professionally for more than a decade, I highly recommend not writing complex one-liners -- unless there's some real benefit to doing so. The more one-liners there are in the code base, the more impenetrable and harder to debug the code is. Unrolling nested functions and switching comprehensions to lists and if statements often make it cleaner and easier to write unit tests for. If you rely upon code coverage for unit tests, a complex list comprehension won't help you see if you have hit the branch cases.
- throwaway2037 1y agoPersonally, I always find multi-layered list comprehensions the hardest to read... And debugging list comprehensions is basically impossible in my experience.
- never_inline 1y agoUse static types and treat python as more concise java. Use dynamic types sparingly. Limit expression complexity. Static types + IDE features make it much easier to understand any codebase.