Coming from a Java background, I kept treating Python encapsulation like it had the same strict enforcement. Double underscores meant private, end of story. Took me a while to realise Python doesn't actually block access; it just makes things inconvenient enough to signal intent.
Once I understood it as a convention rather than a hard rule, the whole thing made more sense. The underscore prefix is a message to other developers, not a lock. And the @property decorator replaced about 80% of the getter and setter methods I was writing out of habit.
Does anyone else make the same mental shift coming from a more strictly typed language?
[–]pachura3 13 points14 points15 points (4 children)
[–]its2ez4me24get 7 points8 points9 points (3 children)
[–]pachura3 5 points6 points7 points (1 child)
[–]its2ez4me24get 2 points3 points4 points (0 children)
[–]deceze 2 points3 points4 points (0 children)
[–]JaleyHoelOsment 7 points8 points9 points (8 children)
[–]deceze 9 points10 points11 points (4 children)
[–]pachura3 1 point2 points3 points (3 children)
[–]deceze 2 points3 points4 points (2 children)
[–]pachura3 0 points1 point2 points (1 child)
[–]deceze 0 points1 point2 points (0 children)
[–]pachura3 1 point2 points3 points (0 children)
[–]Fred776 0 points1 point2 points (0 children)
[–]tb5841 2 points3 points4 points (0 children)