[Python-ideas] Control Flow - Never Executed Loop Body
Sven R. Kunze
srkunze at mail.de
Wed Mar 23 18:42:32 EDT 2016
On 23.03.2016 23:17, Andrew Barnert wrote:
> You clearly don't understand my precious responses. If you don't see the difference between good syntactic sugar and useless syntactic sugar, then I can't explain to you why Python is better than assembler. :P
Good syntactic sugar is sweet. What means good to you? ;-)
> So you're refusing to provide examples because you're sure that no
> examples would convince anyone?
No, I didn't say that. I don't need examples mostly because I see them
each day.
But because you asked, here you are:
class MyClass:
def mymethod(self):
try:
if my_condition:
dosomething()
elif another_condition():
makesomething()
andanythingelse()
else:
butdontforgetaboutthis()
except SomeException:
pass
finally:
return None
Would turn into:
class MyClass:
def mymethod(self):
if my_condition:
dosomething()
elif another_condition():
makesomething()
andanythingelse()
else:
butdontforgetaboutthis()
except SomeException:
pass
finally:
return None
1 line saved and 7 lines with 1 indentation level less (maybe even
related to PEP8 and 80 chars line length).
You might call it useless, I call it good.
Regarding Python syntax, we are constantly going into territory where
there is nothing much left to improve. The big "good syntactic sugar" is
already done. However, I don't think we should stop here. 10 smaller
improvements are as good one big one.
Btw. I don't believe we could improve all Python code out there with
this change, however when you are in such a situation you really
appreciate it if you can do it. Especially when the surrounding source
code already blows your mind; you are grateful for every single
simplification (less lines, less indentation). I don't know what Python
code you maintain but this would our lives easier.
Best,
Sven
More information about the Python-ideas
mailing list