Five Dollar Programming Words

@niels

That’s the definition of Deterministic, not Idempotent.

Idempotent means:
f(x) = f(f(x))

One that comes to mind is invariant.

Involution, least fixed point and coinduction are nice words.

polymorphism

The example of caching functions wrt idempotence is not very useful, because what you call functions here are really procedures with a side effect. In mathematics (and functional programming), function means something else entirely. Therefore, calling this constant behavior idempotence is a bit misleading, and not very useful IMO.

A better example of idempotence would be:

#119891;#8336;: x #8614; x % a

where % is the modulo. Example: 25 mod 10 is 5, and 5 mod 10 is 5.

Another non mathematical example would be a function FQDN which would return the canonical, fully-qualified domain name, given a name. Or one that returns the capitalized version of the input string.

Oh, and Scaffolding

That is NOT idempotent. Idempotent is from the database world and just means that you have the same results IN A DATABASE if you repeat the operation. The standard example is a withdrawal from a bank account (or credit card charge, etc.) You only want the balance to be debited once even if the action is submitted multiple times. That is, the CONSEQUENCES of the action are the same, not the return value of the function. It’s easy to see how you could be confused if you don’t have the right context for the description.

You can generalize this to identical consequences in any stateful system. That’s where the HTTP definition comes in. They’re saying that you should get the same results no matter how many times you do a GET, e.g., if you’re submitting a request for your bank account balance. If you want to change something, e.g., you’re transferring money between accounts, you should use a POST.

x = f(x) is identity.

If I’m paying $5 for a word, my word is ‘poontang’…

Anyway seems like a lot of people pretty uptight about what was a reasonably entertaining read. If it’s not any value to you, you might find your time better spent elsewhere instead.

A simple example of idempotent

As Chris questions if the following complies with the meaning of the word:
f(x) = f(f(x))

The answers is: Yes. That is idempotent.

Consider the following implementation.
int f (int someValue)
{
return someValue x 0
}

It does nto matter if you call it recursively or not. It does not matter if it is a rainy day, you always get the same results.

Practical examples:

  • A function that returns the value of Pi.
  • Save a unique record in a table e.g Save bank transaction #2343. Does not matter how many times you save the record, it will result in that record being unique in the table.

You want your code to be idempotent when you want to prevent duplication or conditional behavior.

Like preventing me from posting this comment multiple times by simply pressing the ‘submit’ button frenetically. You want the ‘submit’ button to be idempotent.

For me, although quite recent, it would be all the words associated to Functionnal Programming :

Curryification, closure, immutability

although closures are not inherent to FP, it took me quite a while to grasp the concept, wich is pretty simple when it finally ‘clicks’, hence the AHA moment. I’m not a .net guy but i remember they were added to C# quite some time ago.

V.Good link about closures, in javascript, which is good because most people can understand the syntax : http://blog.morrisjohns.com/javascript_closures_for_dummies

Immutability is a big one. I watched at the FP crowd like if they were crazy for a long time, i mean, what’s the use of an immutable variable.

This one is beginning to click for me, i’m in the middle of an AHA moment :slight_smile:

These aren’t quite as fancy as some of the examples above, but I always thought Verification and Validation were fun ones since it’s easy to switch the meanings or forget the difference. (Vaguely: Verification is Does it do what the requirements say? and Validation is Does it do what the user wanted?)

http://en.wikipedia.org/wiki/Verification_and_Validation_(software)

I just took my Sun Certified Java Programmer exam. Covariant, cohesiveness and coupling stood out quite prominently in the study guide for the examination.

Eric Lippert’s blog entry is a little confusing because it gives one of the mathematical definitions of an idempotent function without explaining how that relates to the typical computer science definition of the term (i.e. from Wikipedia In computer science, the term idempotent is used to describe methods or subroutine calls that can safely be called multiple times).

To help make things more clear think of it this way. Any operation you call in a computer program operates on an environment (the state of the program, i.e. values of local, global, and system variables). If you think of an operation as a function f, and the current state of the environment as x, then any operation can be written as x1 = f(x), where x1 is the new state of the environment after the call. For idempotent operations, calling a method once may change the environment somehow, x1 = f(x), but calling it a second time should produce the same result, x1 = f(f(x)) and thus f(x) = f(f(x)). To give an example, suppose we have an operation that adds two parameters and assigns them to the third parameter:

AddValues(x, y): x + y

And we call this operation twice:
z = AddValues(x, y)
z = AddValues(x, y)

it’s idempotent, because the environment is the same after the first call as it is after the second call. Now, suppose we have an operation that adds values to a global accumulator.

AddToAcc(x): acc = acc + x

And we call it twice:

AddToAcc(x)
AddToAcc(x)

it’s not idempotent, because the environment is different after the first call than it is after the second call. In other words f(x) != f(f(x))

wait, I thought understanding and eventual mastery was yak shaving?
http://en.wiktionary.org/wiki/yak_shaving

Another bloggers post cut-n-pasted into your own blog. Stop.

I once tried to use the word concatenate in a history paper. My prof wrote in the margin something about not making up words.

People, most of these (canonical, coupling, invariant) have the same definition in other disciplines, so they’re not software specific. Try learning something outside of your programming bubble!

  1. Closure - Which I found very useful in JavaScript
  2. Polymorphism - Basic Object Oriented Programming
  3. Pointer/Reference - 'Nuff Said
  4. Buggered - Technical term for describing the state of any given development project :slight_smile:

It’s interesting that all three of your $5 words have to do with resistance to change.

Immutable: can’t change, period;
Idempotent: can’t change after the first iteration (for a given input);
Orthogonal: can’t be changed by the other quantity.

Knowing what is and isn’t subject to change is of enormous benefit to the programmer. Const, final, invariant, value objects, and the like make our jobs easier because once established, we know what they’ve got. On the other hand, if everything were constant, programming would be impossible. Interesting software happens on the shore; one foot on solid dry immutable sand and one in wet uncontrolled chaos.

Like Serge, mine is Orthogonality which I picked up reading Pragmatic Programmer.