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

Python Descriptors for Better Data Structures

Formale Metadaten

Titel
Python Descriptors for Better Data Structures
Serientitel
Teil
112
Anzahl der Teile
169
Autor
Lizenz
CC-Namensnennung - keine kommerzielle Nutzung - Weitergabe unter gleichen Bedingungen 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen und nicht-kommerziellen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen und das Werk bzw. diesen Inhalt auch in veränderter Form nur unter den Bedingungen dieser Lizenz weitergeben
Identifikatoren
Herausgeber
Erscheinungsjahr
Sprache

Inhaltliche Metadaten

Fachgebiet
Genre
Abstract
Adrian Dziubek - Python Descriptors for Better Data Structures Have you ever wondered how Django models work? I'll present a story of data structure transformation. I will talk about ideas from Django models that I used and how I rediscovered descriptor API. I will talk about printing, serializing, comparing data structures and some other examples, where descriptors excel at making declarative code easier to write. ----- I worked as a developer of a testing framework for a C++ server. The framework tested binary protocol implemented by the server. Most of the work involved testers preparing test cases. The data format was primitive structures -- hard to read and easy to break. Field order and all the data had to be entered manually. At the time, I have already seen the better world -- the models from Django. Have you ever wondered how those work? Step by step, I used the ideas from there to make the structures more friendly and on my way I rediscovered descriptors. I'll show in incremental steps, how: - used keyword arguments to lower signal to noise ratio, - order of definition for sorting the fields, - realized that `__call__` is used instead of assignment, - used `__setattribute__` as first step to extend primitive fields, - discovered that I'm actually reimplementing descriptors, and how it lead me to: - implement printing in a way that is friendly to regression testing, - use diff library for less code and better results, - implement more readable validation. I want to show how descriptors work in Python and how they enable declarative style of programming. By the end of the talk I want you to understand what is at the core of the magic behind field types used by object relational mappers like Django.