We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Write more decorators (and fewer classes)

Formal Metadata

Title
Write more decorators (and fewer classes)
Title of Series
Number of Parts
160
Author
License
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
Write more decorators (and fewer classes) [EuroPython 2017 - Talk - 2017-07-11 - Anfiteatro 2] [Rimini, Italy] In the wake of famous talk “Stop Writing Classes” by Jack Diederich (https://www.youtube.com/watch?v=o9pEzgHorH0), I’d like to present a pattern that can be used to design clean and pythonic interfaces for programmers based on replacing single-method classes with decorated functions. This pattern is already used by some famous frameworks and libraries, like Pyramid (https://trypyramid.com/), but I believe it isn’t that well-known to many (even experienced) Python developers and is not as widely used as it deserves. I’ll show how this pattern can be employed to improve a programming interface which is used by an internal log processing framework at Yelp. This will demonstrate how a more functional approach, leveraging the power of Python decorators, can lead to simpler, more beautiful and easier to understand code. However, this talk doesn’t suggest giving up classes altogether, but making use of them only when they are truly useful. In fact, the use-case I’m going to analyze will combine classes, functions, and decorators to make the best out of these tools. Given that the presentation is going to be very code-oriented, the talk is intended for an audience of developers who are already familiar with most Python constructs, including decorators, even though the concept will be briefly introduced at the beginning of the talk. But, if you are one of these people, I promise you that the code will speak for itself