Once upon a time i read this:
and then.. i came across questions requesting "short pythonic code". The complex short answers often attract more upvotes than simpler alternatives.
It is as if complex == smarts == good
. Well,.. not so good 4 months later when he spends 20 extra minutes to understand what he wrote.
Arguably, some experienced programmers might find the code rather easy to understand, but i doubt this is the case for most (new) users.
An example:
my_str = ' cat dog1 snake'
# This ..
for i, j in groupby(enumerate(my_str), lambda x: not x[1].isspace()):
if i:
index, item = next(j)
# .. versus this..
for m in re.finditer(r'\S+', my_str):
index, item = m.start(), m.group()
Personally i find the second code orders of magnitude more useful than the first.
Here are a few more examples (i ll update it with more examples over time):
example 2 (complex: 7 upvotes, simple: 0)
one liner (.. and one full page of text to explain it)
My reaction to such posts is a downvote. Reason why i downvote it, is to stop the proliferation of complex == smarts == good
.
- Is it just my imagination that short less readable code attracts more upvotes?
- Is my reasoning flawed?
- Is a downvote an exaggeration? Should i respond differently? Or perhaps ignore it?