By properties, I mean attributes with getters and setters that use the syntax of a plain attribute instead of the syntax of a function, like this:
class Test: def __init__(self, color): self.__color = color @property def color(self): return self.__color @color.setter def color(self, new): if new in ('red', 'blue', 'green', 'yellow'): self.__color = new else: print("invalid color")
I don't know if properties is a universal term for them, I'm just calling them this because of the name of the Python decorator.
So I'm of the opinion that properties are bad because they are misleading, since they look like plain attributes but aren't. It's already a pattern in a lot of languages to have methods like
set_someattr(), and I'm not convinced there's any significant gain to using a
someattr property with a getter and setter over just using the methods. I would say the only real difference is that you're defining functions and you can either make them look like functions or look like not functions. Why would you choose to make a function look like a static property? The typing increase is of minimal importance.
What's the consensus here? Am I missing some big advantages?