|
| 1 | +======== |
| 2 | +Syllabus |
| 3 | +======== |
| 4 | + |
| 5 | +Title |
| 6 | + Pythonic APIs Workshop |
| 7 | + |
| 8 | +Abstract |
| 9 | + Python is so consistent that often we can infer the behavior of new objects by assuming they work as the built-ins. The Python Data Model is the foundation of this consistent behavior. This workshop presents the construction of Pythonic objects: classes that feel "natural" to a Python programmer, and leverage some of the best language features by implementing key protocols of the Data Model. |
| 10 | + |
| 11 | +Category |
| 12 | + Best Practices & Patterns |
| 13 | + |
| 14 | +Audience level |
| 15 | + Intermediate Python |
| 16 | + |
| 17 | +Prerequisite knowledge |
| 18 | + Attendees should be very familiar with Python and know its key data structures and how to implement basic classes. |
| 19 | + |
| 20 | +Materials or downloads needed in advance |
| 21 | + Attendees should have a laptop with Python 3.5 or newer installed. Although the content also applies to Python 2.7, 3.5 will be used in the examples. |
| 22 | + |
| 23 | + |
| 24 | +Description |
| 25 | +=========== |
| 26 | + |
| 27 | +This tutorial will show how to implement objects which behave as "naturally" as the built-in types, and therefore deserve to be called *Pythonic*. The whole presentation and exercises will be guided by doctests, which support a form of BDD (behavior-driven design) and allow participants to check their progress in the hands-on parts of the tutorial. |
| 28 | + |
| 29 | +An API is considered Pythonic when it supports convenient and suitable Python idioms. For example, Python programmers expect that any collection is iterable and supports the ``len()`` function. Empty collections should evaluate "falsy" in boolean contexts. Objects of any type should have an user-friendly string representation, and another display format that doesn't hide details and is useful for debugging. Objects of several types support operators such as ``+`` and ``*`` when it makes sense. Pythonic objects are one of the keys to high programmer productivity with the language. |
| 30 | + |
| 31 | +All of these object features, and more, are defined in the Python Data Model: the API that applies to Python objects in general, from plain integers to collections and even to functions and classes -- when we treat them as first class objects in the language. The most important of the special methods defined in the Data Model will be shown and exercised during the tutorial. |
| 32 | + |
| 33 | + |
| 34 | +Outline |
| 35 | +======= |
| 36 | + |
| 37 | +Estimated time per topic in minutes (total: 180', including 15' coffee break) |
| 38 | + |
| 39 | +* Introduction |
| 40 | + * (3') Tutorial Overview |
| 41 | +* A simple but full-featured Pythonic class |
| 42 | + * (4') Object representation |
| 43 | + * (10') Exercise: Implement an Alternative Constructor |
| 44 | + * (7') Formatted Displays |
| 45 | + * (9') A Hashable Vector2d |
| 46 | + * (4') "Private" and “Protected” Attributes in Python |
| 47 | + * (5') The __slots__ Class Attribute: Use and Caveats |
| 48 | + * (9') Overriding Class Attributes |
| 49 | +* A Pythonic Sequence |
| 50 | + * (7') The Sequence Interface |
| 51 | + * (15') Exercise: Implementing Sequence Behavior |
| 52 | +* (15') -------------- Coffee Break -------------- |
| 53 | +* A Pythonic Sequence (continued) |
| 54 | + * (14') Slice-Aware __getitem__ |
| 55 | + * (7') Dynamic Attribute Access |
| 56 | + * (10') Hashing and a Faster == |
| 57 | + * (12') Exercise: Implement Formatting Support |
| 58 | +* Operator Overloading Done Right |
| 59 | + * (5') Unary Operators |
| 60 | + * (10') Overloading + for Vector Addition |
| 61 | + * (7') Overloading * for Scalar Multiplication |
| 62 | + * (10') Exercise: Implement @ for Dot Product |
| 63 | + * (7') Rich Comparison Operators |
| 64 | + * (7') Augmented Assignment Operators |
0 commit comments