Magic function

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Jan 12 06:17:59 CET 2008


On Fri, 11 Jan 2008 19:36:24 -0800, Michael Tobis wrote:

> On Jan 11, 8:40 pm, Steven D'Aprano <st... at REMOVE-THIS-
> cybersource.com.au> wrote:
> 
>> Read the OP's post again. His (her?) users aren't expected to create
>> the toolkit, merely to use it. To create good toolkits you need both a
>> master programmer and an expert in the field. It is an advantage if
>> they are the same person. But to use such a good toolkit, you shouldn't
>> need to be a master programmer.
> 
> It appears we are in agreement, then.
> 
> But that leaves me in a position where I can't understand your
> complaint. There's no reason I can see for the sort of compromise you
> ask for.

What compromise do you think I'm asking for?

I'm suggesting that the scientists be given a brief, introductory 
education in *how to use their tool*, namely, Python.

Instead of creating some sort of magic function that "just works" (except 
when it doesn't) by doing some sort of implicit "grab every object of 
type Obj() you can find and do processing on that", stick to the more 
reliable and safer technique of having the programmer explicitly provide 
the objects she wants to work with.


> Clean abstractions benefit from their cleanliness.

An automatic "run()" that uses a bunch of stuff you can't see as input is 
not a clean abstraction. "Do What I Mean" functions have a long and 
inglorious history of not doing what the user meant.

There's a fundamental difference between (say) Python's automatic garbage 
collection and what the OP is suggesting. Explicitly deleting variables 
is almost always the sort of trivial incantation you rightly decry. The 
computer can tell when a variable is no longer reachable, and therefore 
is safe to delete. But the computer can't safely tell when the user wants 
to use a variable as input to a function. The user needs to explicitly 
tell the computer what is input and what isn't.

The OP is suggesting taking that decision out of the hands of the user, 
and making every variable of type Obj automatically input. If you think 
that's a good idea, consider a programming tool kit with a function sum() 
which inspects every variable you have and adds up every one that is a 
number.



> It's not clear that this is the sort of application where cutting
> corners makes sense, so I don't see how your advice is justified.

Sorry, are you suggesting that training the scientists to use their tools 
is cutting corners? Because I'd call the OP's suggestion to use magic 
functions a dangerous, ill-conceived cut corner.


-- 
Steven



More information about the Python-list mailing list