|
Re: Idempotent operations
|
Posted: Jan 26, 2007 11:55 AM
|
|
> > Const would seem to be fairly simple to check but > > idempotence would seem a little more difficult to > verify. > Isn't an idempotent method the same as a const method > where all parameters are const? That would be easy to > verify. > Or is there an additional requirement that the method > doesn't perform IO?
In a strict interpretation of idempotence a function should always return the same result for the same parameters, and it should have no side effects. So, IMHO, a idempotent function cannot perform any I/O.
It's a little fuzzy when it comes to methods of mutable objects. Does a method always have to return the same value when invoked on the same object, or does it always have to return the same value when invoked on an object is the same state. Furthermore, is the object's state just the object, or the entire object graph reachable from the object? I would argue it has to be the entire graph.
So C++ const does not enforce idempotence. But that doesn't mean it isn't useful. I'd like to see it in Java.
|
|