[after Ray spills a box of toothpicks on the floor]

Raymond: 82, 82, 82.
Charlie: 82 what?
Raymond: Toothpicks.
Charlie: There’s a lot more than 82 toothpicks, Ray.
Raymond: 246 total.
Charlie: How many?
Sally Dibbs: 250.
Charlie: Pretty close.
Sally Dibbs: There’s four left in the box.

The idea behind this famous Rain Man scene actually comes from the true story “The Twins,” told in the fascinating book The Man Who Mistook His Wife for a Hat by British neurologist and author Oliver Sacks. In that story, a box with 111 matches falls on the floor, and the twins instantly notice that what they’re seeing in front of them is three times the prime number 37. Sacks confirms the number by counting the matches by hand. In the movie, the directors probably wanted to leave out the counting from the scene, and solved this by leaving a few toothpicks in the unused box. Unfortunately, they missed the fact that the twins were primarily interested in prime numbers, which clearly 82 and 246 are not.

For all those software and hardware developers who can’t recognize multiples of prime numbers in a pile of matches at the blink of an eye, there are models, which operate at higher levels of abstraction. Abstraction, you see, is a wonderful weapon against complexity.

These days, even small software and hardware systems consist of millions of lines of code. In my pocket, I typically carry about 30 million lines of code, by means of an Android phone. On my desk there’s a PC, which includes roughly 50 million lines of code as part of Windows, and another 50 million lines of code by means of an Ubuntu installation that runs under a virtual machine. That’s just the base configuration. I’m not counting any of the applications that run on top of this machine. I’m not counting all the code that’s just a split second away from my fingers, by means of running a Google search.

But complexity doesn’t necessarily scale with the number of lines of code. It can be incredibly difficult to find a bug in a snippet of code that’s only 20 lines. Now image trying to find a bug in 100 million+ lines of code. Or being assigned to optimize an application that consists of 1 million lines of code.

One remedy to control such huge complexity is to split the system into modules, and to keep the code within each module as simple, readable, and understandable as possible. Another remedy is, for those sections of the design that allow it, to raise them to a higher level of abstraction. The nice thing about hardware and software is that these  high-level models can be automatically translated to an implementation. And, since this translation is fully automated and follows rules that are proven to be correct, the implementation is often guaranteed to be accurate to the model.

Using a model, one can briefly describe what is otherwise too longwinded or complex when stated using a programming language. This keeps the complexity manageable for the designer. As the complexity of systems increases, the use of models should also increase. We’re not all Rain Man, after all, who always sees the trees for the forest.

This item was previously published in the Dutch magazine Bits&Chips, in their model-based-design issue. Thanks for translating Dutch-American Translations.