Pythonic Interfaces: The secret to building maintainable, quality code!
Praveen Shirali (~praveen2) |
An interface is a shared boundary across which two or more components share information. They facilitate building large, stable, modular, and maintainable applications. Interfaces are a core offering in several static-typed languages.
But, Python, a dynamic language, has no inherent support for interfaces, making application development and testing challenging. A few tools & libraries exist; each addressing interfaces in a different way. What does each one do, and how do you choose the right one?
THIS TALK WILL COVER:
- The challenges faced in building and maintaining applications. [4 min]
- Approach: Passive (linters, checkers, static code analysers) vs Active (baked into the application; enforcing correctness) [1 min]
- A metaclass based solution: Standard library's
abcpackage (Abstract base classes). How does it work and what does it do? [3 min]
- Python3: type annotations and improvements to
- How 3rd-party libraries like
implementssolve problems [4 min]
- Design choices: metaclass vs decorator; inheritance vs composition; early vs late detection [2 min]
- How do you choose a solution for your application? What are the factors? [4 min]
WHO IS THIS TALK FOR?
This talk is applicable to all python developers interested in building applications that have a long shelf-life. If you use python for your hobby projects, this may be a good starting point to understand concepts. If you are part of a team that maintains and operates any python application in production, this talk will be very relevant and useful to you and your team.
You will get an overview of the different types of solutions available, how they operate internally, and in which situations they provide the most value. You'll also get information on where to look, and what to pursue if you wish to expand on existing solutions or build your own.
Prior knowledge of the items listed below is very useful to fully comprehend the talk. A handpicked link has been provided against each topic.
- Metaclasses - Video: https://www.youtube.com/watch?v=NAQEj-c2CI8 -- [20min, 40s]
abcand abstract classes - Video: https://www.youtube.com/watch?v=PYj2f6TjlPI -- [4 min, 20s]
- Decorators - Video: https://www.youtube.com/watch?v=tfCz563ebsU -- [16min, 16s]
signature- Video: https://www.youtube.com/watch?v=ccYCu72UTX0 -- [1min, 12s]
- Type annotations - Video: https://www.youtube.com/watch?v=pMgmKJyWKn8 -- [32 min]
Praveen Shirali has been writing Python code for the last 12+ years.
He has been an ex-Head of QA, test architect at RiptideIO & principal engineer at Symantec. He has used Python for test automation, product development and research projects.
He now provides training and consulting on quality engineering, engineering & design principles, improving testability of code, refactoring, TDD etc.
He has been involved in the Python community since 2014, speaking at PyCon India (2014, flash talk) and BangPypers (2016+), and has conducted workshops through PythonExpress. He is currently a co-organiser of Golang-Bangalore.
He is also a core-contributor to the
implements python library, which will be discussed in this talk.