[Tutor] best practice: throw exception or set a flag?

ALAN GAULD alan.gauld at btinternet.com
Fri Feb 4 14:48:36 CET 2011



> > And most methods do not return the object of which  they
> > are a part (in Python at least, in SmallTalk they do).
> That  seems like it would get rather confusing...

Actually, from an OOP point of view, its a very powerful 
default and I wish more Python methods did it. It allows 
you to chain operations together. Using Python notation:

employee.updateName('fred).updateAddress(number=7).resetPassword()

Using the Python idiom of not using a return value for updates 
you'd need to use 3 separate lines to do the updates... Of 
course 3 lines are easier to debug, but often chaining 
operations like this is useful. If the return value is not 
needed then you can just ignore it.

But I often use 'return self' as a kind of default option in 
my own classes.

Alan G.



More information about the Tutor mailing list