zero argument member functions versus properties

Peter Cacioppi peter.cacioppi at gmail.com
Sun Nov 3 09:06:04 CET 2013


Steve said:

"(This isn't Java or Ruby, where data-hiding is compulsory :-)  "

At the risk of striking a sessile equine, when the attribute shouldn't be modified directly by client code, then you hide it and use a property to allow client code access. It is the idiom of allowing client code to edit read-write data directly via attributes that is pythonic, even though discouraged (somewhat) in other languages. 

Actually C# is mature enough for this idiom. C# and Python both support getter/setter methods that present as direct attribute access to client code, and thus allow you to refactor the class without breaking backwards compatibility.




More information about the Python-list mailing list