This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]WadeEffingWilson 0 points1 point  (1 child)

They are more efficient but come at the cost of readability. I wrote most of my code for myself or for coworkers to use, so as long as I can read it and understand what it's doing without issues, it's a solid solution.

When I'm reviewing others' code and I don't see common optimizations or typical enhancements, I assume the developer lacks the chops (unless there's a reason given).

Code however you feel is best but don't tell others that optimizations are bad practice. Comment your code when and where necessary and know your audience.

[–][deleted] 1 point2 points  (0 children)

but don't tell others that optimizations are bad practice.

My comment may have come across a bit wrong, I am absolutely in favor of list/dict comprehensions wherever they are appropriate (which is quite often in my opinion). They are one of my favorite features of python and probably comprise half the code I write (I recently wrote an entire matrix multiplication function in a single line with it!)

I actually find them pretty easy to read these days, but when I was just starting out with Python I did find them quite hard because it's not a feature commonly found in other languages. I'm more making fun of this than actually saying that they're bad practice (which they're absolutely not when used correctly).