[Edu-sig] Design Patterns

Laura Creighton lac at strakt.com
Sat Aug 27 12:52:20 CEST 2005

In a message of Fri, 26 Aug 2005 18:24:33 EDT, Arthur writes:

>And am hoping he is quite wrong in the assessment that "information hiding"
>is a base requirement for information science. ;) 

He is quite correct, but 'hiddenness' is not an infinite human good,
such as health.  It is quite possible to hide too much.  Whether
'having things work like magic' is a good thing or not is always
a tricky judgement call.

>Kirby seems comfortable in the Meyerist camp.
>But I feel my anti-Meyerist sentiments are somehow bound to my pro-Python
>sentiments.  So am having trouble with my Meyerist Python friend's stance

My guess is that you think that properties violate 'Explicit is better 
than implicit.' 

In the example in http://www.python.org/2.2.3/descrintro.html#property
where x is restricted to positive values.

>>> a = C()
>>> a.x = 10
>>> print a.x
>>> a.x = -10
>>> print a.x
0                     #  I think that Art thinks this is too much magic
>>> a.setx(12)
>>> print a.getx()

One nice thing about overwriting __getattr__ and __setattr__ is
that when you are done you have something that fairly shrieks
'black magic here'.  Properties look innocuous. Some people go quite
nuts with them, and use them whenever possible, as if there was
something wrong with simple assignment in the first place.   Worst of 
all, they are easy enough to use that all the would-be-Nannies in the 
world can trivially write code to prevent you doing what they think is 
unwise.  This is most irritating when you are wiser -- or more 
imaginative than they are.  

This bit us the other day.  Somebody naively thought that not allowing 
certain variables to be set to zero would be a swell way to avoid 
divide by zero errors.

The problem is that the natural idiom used all over the codebase is:

    x = fast-way-to-solve-the-equation-works-most-of-the-time(**argv)
    if x is 0: # too bad
	 x = do-it-the-hard-and-slow-way(**argv)

He stuck his property in, and all over campus people started getting
weird mysterious errors.  People who tried to debug it and suddenly
found out that _assignment_ 'wasn't working' concluded that
'_Python_ was broken'.  Their mental model of 'how computer languages
work' doesn't include properties.


More information about the Edu-sig mailing list