Stop writing classes

Sometime in 2012, Python core developer Jack Diederich gave a talk in PyCon titled Stop Writing Classes. It was an unsettling talk: So you’re telling me I could just throw all the Object-Oriented theory in the dustbin and resort to writing functions? Very uncomfortable notion, indeed!

And if you look on Quora, you’ll find a discussion thread on the talk, with people basically calling Diederich an opinionated ass.

My take?

One should take conference (and movie and book) titles with a grain of salt. The talk was so named so that it could generate sufficient interest. Throughout the talk, Diederich does point out cases where we should use classes, including using them as tiny namespaces.

I’m writing this to take exception to the Quora thread. The people who wrote answers there either don’t realize the fine shades the talk was painting, or refuse to. Consider the facts:

  • Diederich provided many examples (including that of an API) where doing away with a class simplified things massively.
  • He said several times that one could always do it later when there emerge a pressing need to refactor.
  • He was mostly against the idea of two-function classes, one of which was __init__().
  • He defended classes: “Classes are good for what classes are good for”.

All in all, for me the talk was a welcome alarm bell: The next time I’m writing a class I’ll be very cautious of riding the Object-Oriented horse hard and giving birth to a towering hierarchy that no one needs. Sometimes module + function is the way to go.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.