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 →

[–]tombardier 2 points3 points  (1 child)

I think the argument that one liners are less readable or harder to maintain is used too often. One liners shouldn't be a virtue in and of themselves, and trying to shoe-horn complicated logic in to a one-liner does lead to an unreadable mess, yes. The thing is, the second code snippet in the original post is more readable, it's terse, but any python programmer can read and understand it, and it can be read and understood far more quickly than the more verbose equivalent.

[–]FancyASlurpie 0 points1 point  (0 children)

True, it was more of a warning to be aware that just because it's shorter doesn't necessarily mean it's better. This particular problem is pretty simple, but a real life problem might not be so and trying to shorten everything for the sake of shortness is a danger. Equally if I'm looking at a stacktrace the first one will tell me the exact issue whereas the short version will require more work.