[albatross-users] impedance mismatch 1
Gregory Bond
gnb at itga.com.au
Thu Jul 3 11:37:15 EST 2003
> Dawn breaks over Marblehead. In other words, folks use attributes on objects
> every single day thinking that they are class variables and treating them as
> such. this single concept I think was the biggest block in my mind. It
> deserves a prominent position in the documentation.
This isn't an Albatross thing, it's a Python thing(*). Getting you head
around this one is a big step forward as a python hacker.
For the sort of work I do, it's one of the best things about Python (compared
to a strongly-typed language such as C++) - the ability to take existing
objects and "decorate" them with new attributes without having to do silly
things like keep parallel arrays or hash lookups or "(caddr_t)user_data" or
whatever. Yes, you can be burned when the underlying object adds a "real"
attribute with the same name, but the alternatives also break in ugly ways,
too.
I'm forever doing things like
list = get_lots_of_orders()
for o in list:
o.is_local = o.deliver_country == 'aus'
o.gst_payable = o.is_local and o.client_type != 'exempt'
# Display the list, including an indicator of which are local, etc
(*) or a smalltalk thing, or a perl thing -- basically, any dynamically-typed
language.
More information about the Albatross-users
mailing list