Calling it Even (Idempotence One)
Idempotence in an operation exists when that operation may be exercised multiple times producing the same result. There’s a bit more but that’s basically it.
When I code a module, often times there is a part of the module that loads information. For example, an initialization method might load data from a file or a database. I compare these types of operations to realizing you forgot something and having to drive to the store — this is very inefficient behavior though sometimes necessary.
Sometimes you end up (inadvertently, perhaps) calling the loader function more than once… Generally I do something like this:
# pseudocode!
class = new Class() {
function initialize() {
i'm_not_loaded = true;
load();
}
function load() {
if i'm_not_loaded is true {
load_me();
i'm_not_loaded = false;
}
}
function load_me() {
do_lots_of_expensive_calculations();
drive_to_the_store();
}
}
class->load(); is functionally idempotent. The result is absolutely the same each time it is called. Note that if the load_me() function were written such that all of its expensive calculations had the same result each time they ran it would also be idempotent. What is interesting to me is that those expensive calculations (at the in-expense of a flag in memory) can not be run twice. This is an optimization, and while it is idempotent it does not replace something that is non-idempotent.
What’s idempotent in meatspace? Not much, it seems. Even if the result is the same the first billion times, the billion-and-first time might spark a total meltdown. Entropy is a bitch. Anyway I want to think about it some more. Ideas?
