PyCon UK 2019
Syntactic Sugar vs Maintainability
Open the slides and notes
Synopsis
Is it ever worth committing coding sins for the greater good? We'll look at techniques which can make your code easier to use at the cost of being harder to maintain, and when the effort is worth the reward.
There are plenty of ways in which you can use and abuse the power of python to make your library code easier for your users to work with. I'm going to talk you through some techniques to design clean and simple library interfaces for your users, and explain how they can make things both easier and harder at the same time.
Using real world examples we'll touch on topics such as automatic registration using metaclasses; changing base classes at runtime to save your users a line of code; and the joys and pitfalls of monkey patching things which should probably never be monkey patched.
By the end of the talk you'll know why doing these things is usually a bad idea, and why I think it's worth doing them anyway.
Referenced
-
Mara - networking library using decorators
- The @service.listen decorator and related event handler
-
Django
- The ModelBase metaclass
- The Model base class
-
Django-Tagulous - tagging library for Django
- Perl for Python
- and of course, Wildfish, my employer - contact us for all your Python and Django needs!
Feedback
@DRMacIver livetweeted the talk
The talk has had a warm reception in the Python community:
- "That is quite something!" - @simonw
- "Has science gone too far?" - @TheEnbyperor
- "Oh no" - @TheEnbyperor
- "Oh this wasn't even the worst bit of the talk" - @TheEnbyperor
- "this is still the human centipede of programming" - @ComradeEevee
- "This is my new favorite feature of Python!" - @tecknicaltom
- "W...why" - @ovelny