(side-)effects and ...

Robert Kern robert.kern at gmail.com
Mon Jul 6 01:44:19 CEST 2015


On 2015-07-05 21:36, Tim Chase wrote:
> On 2015-07-05 20:29, Stefan Ram wrote:
>>    But why do we not have a common and well-known term for
>>    the counterpart, that something does not modify the state
>>    of the world, but that the state of the world does
>>    influence the value (behaviour) of a call such as
>>    »datetime.datetime.now().time()«?
>
> I believe the term is "idempotent"
>
> https://en.wikipedia.org/wiki/Idempotent_function#Computer_science_meaning

No, "idempotent" means that if it changes the state, then applying it twice or 
more has the same effect as applying it once. For example, calling 
object.__setattr__(self, attr, y) with the same arguments is idempotent; whether 
you execute that once, twice or N times, afterwards, `getattr(self, attr) is y`. 
But calling it the first time probably did make a change of state. This is 
unlike functions like list.append(self, x) which will give you different results 
depending on the number of times you call it, even if the arguments are the same.

Functions that don't change state at all are naturally idempotent, but many 
idempotent functions do change state.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco



More information about the Python-list mailing list