Change the future

Friday 12:10 p.m.–12:55 p.m.

API Design for Library Authors

Chris McDonough

Audience level:
Best Practices/Patterns


A library is code distributed in such a way that strangers can use it. In this talk we consider: 1) why Python developers make bad libraries and poor APIs; 2) how to make your library API maximally useful for others; 3) examples of real-world antipatterns involving APIs.


Introduction and Guidelines

Why People Make Bad Libraries

Libraries vs. Frameworks vs. Apps

Convenience != "Cleanliness"

Global State is Precious

  • Module Scope Programming Antipatterns

  • Globals Mutation from Constructors

  • Functions Called for Side-Effects

  • Alternatives to Mutable Globals

Module Scope Configuration

  • Antipattern: Not-Really-Configuration

  • Antipattern: Inversion of Config Control

Avoid Convenience Features

  • Antipattern: Pylons' Stacked Object Proxies

Avoid Knobs on Knobs

  • Antipattern: Pyramid Authentication Policy

The Danger of Offering Superclasses

  • The Yo-Yo Problem

  • Codependency

  • Smells

  • Alternatives to Inheritance

    • Composition

    • Event systems

First, Do No Harm

  • Decorators that change calling signatures.