Implicit code – what makes it good or bad

NOTE HXA7241 2010-12-04T17:16Z

To make a software structure implicit you should adhere to a clear abstraction – then being implicit is good and not bad

Making things implicit in code is often noted as bad. Implicit type conversions in C++ were avoided as a cause of misunderstanding and surprise. And right at the top of ‘The Zen Of Python’ is the line: “Explicit is better than implicit”.

But making things implicit is also good. We only have a limited amount of capability so the only way to do more is to ignore certain details. We need to make some things implicit in order to take larger steps. (“Civilization advances by extending the number of important operations which we can perform without thinking about them.” – Whitehead.)

So what is the difference between good implicit and bad implicit?

Good implicitness is about good abstraction. The implicit should map to the open/varying part of an explicit abstraction, so then it is bounded by the fixed part.

The mechanism of tail-recursion is implicit. We do not need to think about conditionally adjusting the PC-register and leaving the stack alone. If you follow the explicit rules, it will work as expected.

(Similarly for many other things like list comprehensions, associative-arrays/dictionaries, etc.)

Implicitness adhering to abstraction cannot create surprise, because what is used or seen is the fixed part of the abstraction, and that fully contains and limits any effect of the varying part. If you understand the fixed part, you understand all that can show through, at that level, of the varying part.

The mechanism of function calling is also implicit, although it seems to have a chink. Stack-space is limited: if you call too much it will break. It seems the abstraction itself has an implicit rule of limited usage – is that bad? With software it is normal to have a background wariness that resources are limited, so one should not be reckless – so you could say that is also a known abstraction, and the implicit rule fits it. Fairly well.

Humans mess up perfect abstractions by fudging them with interpretation and context (which is a source of creativity, so it is not bad). Things still work well though, but the goodness of implicitness always has some matter of degree.