One thing I’m always interested in is reassessing things that were previously used in the IT industry, have fallen by the wayside for some reason but might have new application today, when circumstances have changed. This series of blog posts covers my thinking around taking the essence out of simulation languages to create dynamic unit testing or dynamic mock objects. I haven’t thought all this through yet but I decided to kick the ideas around anyway.
Simula (and Simula 67) were amazing languages. The Wikipedia article mentions that Simula 67 introduced objects, classes, subclasses, virtual methods, coroutines, garbage collection and discrete event simulation. It’s hard to comprehend that a language had these concepts back in 1967.
What I loved about Simula was its simulation abilities (hence its name). The idea was that to simulate say the people traffic at an airport counter, you’d describe each of the actors with procedural class code, then you’d run the simulation and see how they’d interact. But the real genius was that, just as real people don’t react the same way all the time, the classes included code that introduced random variation in the responses and Simula then provided the framework for running the simulation.
As an example, Hold() statement was a bit like System.Threading.Thread.Sleep() in that it made the object stop for a period of time but it allowed you to add in functions that would determine the distribution of the random values that determined the time involved. For example, from the Wikipedia article:
Hold (Normal (12, 4, u));
As another example, imagine if when writing code that said:
if (something == somethingelse)
you could add an attribute that said what the odds were of taking each branch of the subsequent code.
It occurs to me that current unit testing tools do a great job of testing code in a static way (particularly testing edge cases) but completely miss being able to test the dynamics of the code. By introducing some simulation constructs, we should be able to expand testing infrastructure into a dynamic test rig rather than a static one. This could be particularly useful in creating dynamic mock objects.