A C-like if statement

Steven D'Aprano steve at REMOVETHIScyber.com.au
Fri Feb 24 06:07:20 EST 2006


On Fri, 24 Feb 2006 02:02:02 -0800, bonono wrote:

>> >>>> "test".index("a")
>> > Traceback (most recent call last):
>> >   File "<pyshell#0>", line 1, in -toplevel-
>> >     "test".index("a")
>> > ValueError: substring not found
>> >>>> "test".find("a")
>> > -1
>>
>>
>> Did you have a point?
>>
> It was about your side-effect talk, if you failed to see it, that is
> fine.
> 
> BTW, it seems that the term side-effect of function used is a bit
> different from my understanding of how it is in general used in this
> field.

What side effect?

Returning magic values (e.g. -1 to indicate "not found") is not a
side-effect in any terminology I've come across. 

A side-effect would be if s.index(substr) not only returned the index as
promised, but also (say) appended substr to a list somewhere. 

Side-effects aren't always bad (import, for example, does all its work by
side-effect). But they are generally frowned upon, and in functional
languages they are verboten.


-- 
Steven.




More information about the Python-list mailing list