[Tutor] Getting/setting attributes
lists at justuber.com
Wed Sep 22 00:41:23 CEST 2010
>> As I understand it, it makes most sense to set/get the attribute of
>> an object using a method rather than doing it directly.
> Heavens no!!! That's backwards!
> It might be justified in languages like Java, where you can't easily
> change your mind about direct attribute access. There's also a school
> of thought that disapproves of direct attribute access for a number of
> philosophical reasons, but if you strongly agree with that philosophy
> you'll probably find Python isn't a good language for you. (It has to
> do how much the compiler should forbid the programmer from doing, and
> how much software reliability that buys you.)
Heh, at the moment I don't have a programming philosophy. It's slowly
being formed by conversations with people like you :-)
> 90% of the time, stick to direct attribute access, especially for short
> scripts and pre-release versions of software. If and only if you find
> that too limiting, or perhaps not limiting enough, then change to using
> getter and setter functions and properties.
This definitely seems to be the consensus. My instinct is telling me
that it's probably best to use getters and setters when requiring
input from a user that needs to be validated perhaps, but that my
initial reading on the matter seems to have over emphasised the
importance of accessing attributes via methods.
More information about the Tutor