The Wall Has Circuitry Inside It: Descriptors in Python
You have a class. It has an attribute. You want to protect that attribute — maybe validate it, maybe log every write, maybe make it read-only after the first assignment. So you do what most developers do. You prefix with an underscore, write a get_temperature() method, write a set_temperature() method, and tell yourself that’s “Pythonic.” It works. But every class that needs this pattern gets the same boilerplate. Every attribute that needs protection gets its own pair of methods. The class that started as twelve lines is now forty-five. And somewhere around the third get_x / set_x pair, you start feeling like you’re writing Java. ...