Maintainability anti-patterns
These anti-patterns make your code difficult to understand or maintain over time. We are going to discuss several anti-patterns that should be avoided for better quality in your Python application or library’s code base. We will focus on the following points:
- Using a wildcard import
- Look Before You Leap (LBYL) versus Easier to Ask for Forgiveness than Permission (EAFP)
- Overusing inheritance and tight coupling
- Using global variables for sharing data between functions
As mentioned for the previous category of anti-patterns, using tools such as Flake8 as part of your developer workflow can be handy to help find some of those potential issues when they are already present in your code.
Using a wildcard import
This way of importing (from mymodule import *
) can clutter the namespace and make it difficult to determine where an imported variable or function came from. Also, the code may end up with bugs because of name collision...