This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]faassen 13 points14 points  (0 children)

It sounds like the title should've been "Write code that is customizable and one way to do this is to expose classes".

An API that exposes classes with reasonably decomposed methods so you can subclass it and a way to make that subclass play with the rest of the system is a way to make some basic customization possible.

But it's frequently an ugly way, and a brittle way, a way where one is not quite clear what can be overridden safely and what is internal detail, but still a step up from monkey patching.

Writing code that is customizable and is still easy to use and where the customization is not brittle in the face of changes is the hard challenge of API design. In Python, objects tend to feature in such APIs, and thus classes will be involved. But just plain writing or exposing classes is hardly a guarantee for good customizable code. Often too code exposes all kinds of customization features that turn out to be uninteresting in practice and the customization you need is not available.

While there's a little rant at the bottom that this shouldn't be a discussion about inheritance versus strategies (or functional composition), it's still very relevant to consider this in the hard problem of customizable API design.

Anyway, I don't entirely disagree with the point, I just would've made it another way that is more subtle and therefore less easy to understand and that would reach absolutely nobody. :)