Friday, May 13, 2005

Static typing exposed

Making code look wrong is an excellent article by Joel Spolksy that illustrates a really, really, really important point about data types in programming languages.

Having a compiler, or a naming convention, that keeps your ints from your floats from your strings is solving the wrong problem. The real problem is a different type of 'type', a type related to the problem domain such as Joel's 'unsafe string' example for Web apps.

I've always hated Hungarian notation as practiced in statically typed programming languages - mirroring the type system of the host programmming language - because it essentially doubled up (badly) a job that the compiler was doing anyhow.

Not only that, but both the compiler and notation were checking something which was basically the wrong problem. To use Joel's example, unsafe string encoding would go through clean as a whistle.

Simonyi's original concept as explained by Joel makes much more sense to me. The same (or maybe a different?) legion of programmers who interpreted 'type' at the wrong level for Hungarian Notation are now doing the same thing with XML. There is this overpowering urge to statically type the stuff. It leaves me baffled for the same reasons that Hungarian notation and static type-checking leave me baffled.

No comments: