Overrated things

Recursion

Recursion is sometimes noted to be beautiful, simple, elegant... It's not. It's a programming technique that's useful in a few specific cases, such as working with trees. Recursion is useful when it's used on structures that are themselves recursive - a tree consists of a node linking to other trees. But it is sometimes used in situations where this recursive structure feels forced. In such situations it becomes an ugly, opaque solution. Consider the problem of defining tetration and pentation in Python:

This is a non-recursive definition:

def tetration(x, y):

acc = 1

for i in range(y):

acc = x ** acc

return acc

def pentation(x, y):

acc = 1

for i in range(y):

acc = tetration(x, acc)

return acc

This is a recursive definition:

def tetration(x, y):

if y <= 1:

return x

else:

return x ** tetration(x, y-1)

def pentation(x, y):

if y <= 1:

return x

else:

return tetration(x, pentation(x, y-1))

Notice the number of lines is the same. The recursive definition is less intuitive; it requires working out a few examples on paper to truly understand. All those functions that are created take up lots of space, along with all the huge arguments in them.

The message is simple: don't use things just because you read they are good. Use what feels natural.