Bytepawn Marton Trencseni on Software, Systems and other Ideas.

Show Me Your Data Structure...

2008/09/10

There's an old programming proverb which goes something like this:

Show me you algorithm,
and I will remain puzzled,
but show me your data structure,
and I will be enlightened.

This is a statement about software and coding, but first and foremost it is about human cognition. The way my brain works is to first visualize the data and then imagine what the algorithm does to it.

Given this cognitive limitation of my brain, I favor static, strong, class-based typing (C/C++) over dynamic, weak, object-based typing (JavaScript).

To give a strong example and stir up some controversy, consider Chapter 9 of Beautiful Code: Top Down Operator Precedence by Douglas Crockford. You can read it here, and you should to really get a feeling for what's going on...

I think it's spaghetti code.

The problems with his approach are many:

As I was trying to understand the code, I found myself writing out on a piece of paper the different "types" of objects that come up in the code --- in other words the classes. I was writing the header files for the code in order to untangle the mess!

To close this rant, I'll quote a thread Google turned up:

> A while ago there was one of those static-vs-dynamic debates (in the hackers
> and painters thread, I think), and somewhere (I'm sure) someone mentioned a
> quote along the lines of:
> 
> Early on in a project, as code is rapidly evolving, you want static typing
> to help you as much as possible. When the code has matured (it's well tested
> and not changing much), you want more dynamic typing so that the design can
> be more flexible.
> 
> Can anyone remember who said this?
> 
Not me.  But it's interesting.  Usually the argument goes the other way:
Early on in a project, as code is rapidly evolving, you want dynamic
typing to keep as many design options open as possible. When the code has
matured (it's well tested and not changing much), you want more static
typing for efficiency and to help root out obscure bugs that may be
waiting to manifest themselves.


- Marton Trencseni


blog comments powered by Disqus