MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1p8aebh/c/nr9k9j2/
r/programminghorror • u/TheChief275 • Nov 27 '25
59 comments sorted by
View all comments
Show parent comment
2
Properties can do that but they do not have to.
Consider this Python:
@dataclass(frozen=True) class Point2: x: float y: float @property def hyp(self): return ((self.x ** 2) + (self.y ** 2)) ** 0.5 point = Point2(9, 17) print(point.x, point.y, point.hyp)
1 u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Nov 28 '25 Yeah, of course you can have whatever get and set logic you want. Or not even provide a setter and make the property read-only. I was thinking it would also create a private field with the same name of the property for you, but now I'm not sure.
1
Yeah, of course you can have whatever get and set logic you want. Or not even provide a setter and make the property read-only. I was thinking it would also create a private field with the same name of the property for you, but now I'm not sure.
View all comments
Show parent comment
2
u/nekokattt Nov 28 '25
Properties can do that but they do not have to.
Consider this Python: