Evolutionary development

Published on

For many, the goal of software engineering is to turn a set of requirements into code. Equally important is checking that the code you’ve written actually does implement the requirements you have – this is the point of testing, and is an area which I think, especially in open-source projects, is neglected, or not done to a sufficient standard. This is part of the reason I’m writing Arete.

A few months ago, I attended an interesting workshop on test-driven development by Kevlin Henney, which introduced the idea of thinking of unit tests as requirements specified in code – from what’s defined in a unit test you can infer the interface for a class, and automatically generate the stubs for the class. This is nothing new, even Microsoft’s Visual Studio can do this nowadays. From a unit test, you could also infer the behaviour of the class too, I mean, that’s kind of the point of a unit test, to define the behaviour of the class.

So if we can infer the interface of a class from the unit test, can we also infer the body of the class? This is a more interesting point, but possibly nonsensical, as a bug in a unit test would result in a bug in the automatically generated application, whereas bugs in a unit test are quickly spotted using the red/green/refactor method, because if you think you’ve implemented something correctly and the unit test fails, it gives a flag to check the unit test. Still, with a comprehensive set of unit tests in addition to integration tests, if one had a bug in it, then the resulting requirements definition may be impossible, or never pass.

Still, we have the problem of how do we automatically generate the method body, etc… A possible way to do this could be using genetic algorithms. Now I must admit, this isn’t an area I have much experience with, or are particularly familiar with. We have obvious fitness indicators – the passing or failing of unit tests, but it would need a particularly clever method to be able to generate code, or a lot of CPU time…

I do think it’s an interesting problem though, maybe it’s one I’ll solve one day too.