Does your code smell? Have a weird fragrance? It turns out code smells are a real thing and an amazing conceptualization of suboptimal design. This talk helps you identify code smells in Python. It also shows you how to wash them away by the technique of refactoring. You will learn the art of writing Pythonic, clean and maintainable code.
Code smells refer to the symptoms of problematic code design. Identifying different types of code smells is the first step to successful refactoring. I will talk through some classic examples:
- Unnecessary long and complex code
- Using mutable data structures
- Uncommunicative naming
- Coupled code
Knowing what to refactor, I will share a few learnings that lead to good quality code:
- The scout's rule: always leave the code cleaner than you found it
- Pythonic data structures: Enum, Namedtuple
- The art of naming
- DRY and the separation of concerns principle
I will also share tips on using refactoring at your company, which includes convincing your product manager, looking out for code smells during code reviews, and employing automatic tools.