Get the latest tech news

Design patterns you should unlearn in Python


image-1.jpg

Because C++ doesn’t have modules (before c++20) or proper package systems, Singleton was a clever hack to guarantee exactly one instance of a class, avoiding the nightmare of duplicate globals and multiple definitions. Managing this global state is tricky — and the Singleton pattern wraps this idea into a class that controls its own single instance, so you don’t have to worry about multiple definitions. So yes, Singleton is basically a band-aid for C++’s lack of modularity and clean global state management — not a holy grail of software design.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of python

python

Photo of design patterns

design patterns

Related news:

News photo

Following Up on the Python JIT

News photo

Tinyio: A tiny (~200 line) event loop for Python

News photo

Why MIT switched from Scheme to Python (2009)