Wednesday, November 16, 2011

The beauty and the beast: explicit and implicit types

Working with Haskell has brought on an unexpected question:

  • Is it more productive to work with implicit types or explicit types?
By this I mean: “Should major types be mostly inferred or mostly specified with type signature”?

The bizarre fact is that you may well use two different parts of your brain to work with inferred types or with “defined” types!  Here is the reasoning:

Programming is an incremental process: changes are made locally and then overall consistency is assured. When programming around types, changes are made to type specifications or to expressions which affect type. The two kinds of changes lead to two styles of programming: the first is to start by changing a type definition or type annotation, the second is to start by changing an expression, which results in a change to the inferred types, and possibly needing a fix to a type signature.

The bare minimum of type annotation is not even to provide argument to “top level” functions, such as in let f = fun a b -> … , where we only know that the function f has two arguments because it is inferred from its body. This style may sound contrived but is a way to work around the type class restriction in F#.

So how does this affect productivity? Mental work is much about having a good inner dialog; Your mind is taking a very static view of the program’s design when you worry about type signatures. While when you worry about the result of the type inference, you are effectively “re-running” the program in your head. It is not the same thing! And I find in many cases the second thought process, the reliance on inferred types, the more productive way to work.

Getting past the Peter Principle

Today I am asked about X. I say "You know the Peter Principle"?

This answer was more an amusing way to explain a deeper issue, and not really what I thought about X.
Although the Peter Princple says  "in a hierarchy every employee tends to rise to his level of incompetence", the real story is we all grow past some of our competence zones, but we also build some new ones. A key competence for managers to aquire is to have enough confidence to pull their ego back, and let others shine; It is to understand that management is about helping others to succeed.

Highly skilled employees that are given management positions will fail or succeed on their ability to understand that it is not "about them", but about the project and the people they are asked to manage.