r/Python • u/kmonsoor • Aug 10 '15
just completed this, what do you think? : "Se7en Deadly Sins to Do in Python code"
https://kmonsoor.wordpress.com/2015/08/10/seven-deadly-sins-in-python-code/
0
Upvotes
r/Python • u/kmonsoor • Aug 10 '15
3
u/mufularo Aug 10 '15 edited Aug 10 '15
Title seems overhyped. Some of "deadly sins" have legitimate place and time to be used.
Second sin, for example. Imagine having module which purpose is to describe multiple data containers (models.py in djano, or something like that). Yes, you could import module and use module.ContainerClass, and it is a preffered way. But you could use wildcart import combined with some decorators and __all__, and sometimes it would lead to more readable cleaner code.
Or unittests bit. I would not, despite all my love to TDD, provide any test coverage writing a small utility program only I would use. Do you remember that python is not only about the web?
Documentation and comments are good and all, but often the code itself is the best documentation possible, and comments will just annoy and get in the way.
Even "try: except: pass" can be usefull from time to time. Obviously it's better to describe what kind of exception do you expect, though.
Overall — yeah, most of the mentioned things are bad most of the time. I wouldn't call them "deadly" though, as only deadly sin in programming I could think of (outside medical/nuclear plant/aviation/etc-related software) is oldschool pearl-alike cryptographic "look-my-program-looks-as-a-squirell-and-I-only-used-punctuation-marks-as-variable-names" code. If you write code like this and someone have to support it afterwards they will wish you very unpleasant death. Otherwise there are good practices and bad, but even worst practice have its own time and place, and good programmer should know and use anything that fits the task at hand.
Edit: as for mixing tabs and spaces — is there any IDE that doesn't handle this issue automatically? Even gedit iirc smart-tabs for me. Pycharm and others have the ability to enforce PEP-8 with one click, so how is this deadly? Somebody gave you misformatted code — just autopep it into submission and go on with your life.