Does Python really follow its philosophy of "Readability counts"?

Duncan Booth duncan.booth at invalid.invalid
Tue Jan 20 04:30:07 EST 2009


Luis Zarrabeitia <kyrie at uh.cu> wrote:

> It boggles me when I see python code with properties that only set and
> get the attribute, or even worse, getters and setters for that
> purpose. In my university they teach the students to write properties
> for the attributes in C# ("never make a public attribute, always write
> a public property that just gets and sets it"). I never understood
> that practice either, given that the syntax for attribute access and
> property access in C# is exactly the same. (Could it be that even if
> the syntax is the same, the compiled code differs? Don't know enough
> about .NET to answer that). 
> 
The compiled code differs. That doesn't matter if the class is only 
accessed from within a single compiled program, but it does matter if you 
expose a public interface from a library: if you change a public attribute 
into a property then you need to recompile all code which accesses it.

Actually that's no worse than making any other change to the published 
interface, and the source code doesn't need to change, you just need to 
recompile.

Personally when writing C# I use properties when it seems like a good idea, 
but for small internal classes I just expose the attributes until I know I 
need to do something different.


-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list