A long time ago in a land far away, I went to university and studied computer science. In those days we learned how to program in Java and C++, and whenever we were assigned coding assignments, we had to submit the assignment with a makefile. The makefile was what was used to build our assignment, and if our assignment could not build, we automatically got a zero grade.
These days there are several tools for building applications that are considered more modern. In the heyday of Alt.NET there was NAnt; Microsoft felt left out and developed MSBuild; and nore recently we’ve seen the Boo Build tool and PSake for PowerShell based builds (which I tried out today and I like a lot).
But there is one thing that these so called modern tools are missing – something that I call timestamp dependency analysis. It might be known as something different to the developers of make, but I do not know what they call it, so lets call it timestamp dependency analysis. Perhaps a commenter can inform us.
To explain what I mean by timestamp dependency analysis, consider the following makefile what I copied from a make tutorial that I read recently:
This makefile uses the g++ compiler to compile the .cpp source files into .o files. Then it will take these .o files and link them into an executable file.
The interesting thing about the way that make operates – and this is demonstrated by this makefile – is that you can have targets as dependencies, but you can also have files as dependencies.
Having files as dependencies is how timestamp dependency analysis can do its work. Make will look at the files that are dependencies of a target and will evaluate whether any of the dependencies have newer timestamps than the target files and it will only execute the target if the dependencies are newer than the target. So in the example, for each .o target, it will evaluate whether the .cpp files are newer that the .o files and it will invoke g++ only that is the case. Of course, if the .o file does not exist, then g++ is invoked anyway.
This timestamp dependency analysis has the potential to make builds quite quick. Checking the timestamp of a file is a very inexpensive operation compared to compiling and if a small change is made, most of the output files will be up to date and the build will be very quick.
This kind of optimisation is missing in modern build tools and I notice this especially in Visual Studio 2010. If I make a small change to a unit tests, Visual Studio seems to try and build all of the projects and a build of fifty projects can take a few minutes sometimes. This is very disrupting to someone who likes to be in a good TDD rhythm, and even if TDD is not practiced, large projects can experience quite a significant productivity loss. (Visual Studio 11 seems to solve this problem by only building projects that change and their dependencies.)
One thing that I am going to try in the next few weeks is to hack MSBuild or PSake to include this timestamp dependency analysis. Check back in a few weeks – I’ll post up some things that I am trying.
And I hope that at the end of this .NET developers are celebrating faster builds.