[Tutor] running a script from IDLE

Lloyd Kvam pythontutor@venix.com
Mon, 11 Mar 2002 19:42:16 -0500


I think failure is best reported by raising an exception.

To my mind (based on limited FP experience) you want functions that
return useful values - even if it is only a reference the the object
that was passed into the function.  So long as the result of a function
makes sense as the argument for other functions, you have a function
that can be used as a building block.  This is easy to see with math
oriented processing.


Scott Widney wrote:

>>>Correct and FP is quite happy for you to return a new reference
>>>to the modified pencil. The point of returning values is that
>>>you can apply value substitution to prove the correctness of
>>>the solution. (The real FP afficianados wuill be screaming
>>>at me real soon :-) When a function performs its task without
>>>returning a value you lose the concept of the entire program
>>>being an expression that is evaluated.
>>>
>>...which is how I'm contrasting object.method() calls which
>>change object state without returning anything.  The point
>>of the method is to change the internal state of the object.
>>Nothing is returned.
>>
> 
> Hmmm... in Alan's example above, you could always have the function return a
> boolean indicating its success or failure at performing the task. One level
> up you'd have logic that would react accordingly. Now it's back to being
> functional again....
> 
> Actually, Kirby's object.method() ought to do that as well. Perhaps you've
> asked the method to change the object in a way that was never intended. You
> could have safeguards within the methods, but reporting an error would
> become a side effect. So, instead, in essence you're asking the object to
> modify itself, and it's responding with either "OK, done" or "I'm sorry,
> Dave, but I can't do that."
> 
> Oversimplified perhaps, but it seems as though having functions and/or
> objects only report errors, while leaving it to the caller to react to the
> error makes both more functional.
> 
> Scott
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582