I’ve been going deeper into Python recently. I was able to use the language a few months ago to automate a multi-column spreadsheet that calculates folder sizes and dependencies checking. Writing it was easy but I wrote it just to write it and finish it.
Now, I’m undergoing a slightly more formal approach with Python by learning Django and some online tutorials. What I found in common is they all point to Python’s PEP 8.
This document gives coding conventions for the Python code comprising the standard library in the main Python distribution.
Oh, my. I broke a lot of rules in my previous script. Ha. Anyway, the part I found interesting in the document is this:
Two good reasons to break a particular rule:
- When applying the rule would make the code less readable, even for someone who is used to reading code that follows the rules.
- To be consistent with surrounding code that also breaks it (maybe for historic reasons) — although this is also an opportunity to clean up someone else’s mess (in true XP style).
There are always exceptions to rules and the PEP8 document didn’t fail to outline them. I’m giving this special attention because it trades off blind-rule-following for readability and adaptability. It gives priority to Python’s cause: readability.
We should learn from it. Whatever we do, whatever rules or beliefs we follow, we should always give way to our priority. Whatever it is. Sometimes, we get so caught up and obsessed with specifics without noticing how much time has been wasted on something what isn’t even part of the real direction.
This goes deeper for me than I am willing to share. But maybe next time 😉