Implementing class attribute access methods via pseudo-function o verloading.

Ville Vainio ville at spammers.com
Mon Oct 25 09:54:25 EDT 2004


>>>>> "Duncan" == Duncan Booth <duncan.booth at invalid.invalid> writes:

    Duncan> theProblem.Title = "Java affecting adoption of Python."

...

    Duncan> This is much clearer than wrapping your attributes up in
    Duncan> accessor and mutator functions and doesn't lose you
    Duncan> *anything*. If your code ever evolves to the point where
    Duncan> you need to intercept the attribute access or mutation
    Duncan> then you simply change the affected attributes into
    Duncan> properties, but there is no need to make them properties
    Duncan> until this happens.

I felt this is something worth highlighting - in Java you *need* to
implement accessors because you can't convert direct attribute access
to accessor methods if/when you are start to second-guess the
design. In Python (and some other languages) you don't need to do
that.

That's yet another "guilt" that must be washed away from aspiring
Pythonista's minds, just like while 1, if cond: break...

-- 
Ville Vainio   http://tinyurl.com/2prnb



More information about the Python-list mailing list