Designing APIs with many arguments is tough, and validating them can be even harder. Inspired by Golang’s functional options pattern, this talk explores how, and whether it’s a good idea, to implement this API design approach in Python, comparing it to alternatives like builder and chain patterns.
Documenting lots of arguments well is hard. Validating each is even harder. Function arguments are not scalable past some point. Configuration structs are heavy, specially if every function expected it’s own config instance. Functional APIs solve this problem in their own awkward little way with a bit more code.
The first time I saw functional options in Golang, I didn’t fully understand why something as simple as configuring options (class or function args) looked so awkward. Then I read about the technique and realized that this solved a problem we have in every language, not just Golang.
Several years later, I found the chance to apply it when designing an API in Python and noticed no existing implementations! But was it a good idea?
This talk is about exploring a very interesting API option design from Golang’s Rob Pike in Python, and comparing it to other design patterns like builder & chain.
Hello! I’m a fullstack engineer maintaining a couple of open source projects (DataLine, Pet).
I really enjoy designing things - whether an event poster or a total refactor of a big monolith or a 3D printed CAM. I think good design is the foundation of everything great, and I aim to achieve it in everything I touch.
I’m also an avid cook, music and art lover, and I spend too much time on social media.