Tom Ritchford
Sep 28, 2022

--

Again, your strategy is very un-Pythonic.

There are two sorts of styles in programming - bondage, and discipline. :-D

Bondage is where you go to a lot of effort to prevent other people from screwing up. Discipline is where you do avoid footguns, but you generally rely on people's discipline to not do bad things.

C++ and Java are bondage language; Python is a discipline language...

Your example, "current age", is simply wrong, as it should not be a property, exactly because calling it twice (without changing the object) will give two different values, and that is not what you expect of a property.

"Current age" should be a function, not a property.

---

Me, I use dataclasses and functools.cached_property and I get the best of both worlds.

--

--

No responses yet