Friday, July 17, 2009

Nothing is forever

I have been writing about the scaffolding metaphor - but after some conversations with my colleagues I realized that I did not do a good job there. I did not conduct well the main idea: nothing is forever. No library and no program is forever and we should not shy off from writing libraries that are useful only at some phase of the application construction. It is still valuable if you can quickly get to the point of having a preview, a simplified prototype of the functionality you need even if eventually you'll remove all of that prototype code from the project. This is very 'agile' and it is also 'worse is better (if you can have it early)' and those libraries, those tools that you use only temporarily, I call the scaffolding.

Now one would ask why write a library that is useful only temporarily? Why not include at once all the parts needed in the final product? There can be several reasons:

  • something that is only a part of the scaffolding in one project can stay in the final solution in another one
  • the author of the library might not yet fully understand the problem, and it can take years to reach the right abstraction
  • the distribution of possibly needed modification can be so uniform that there is no reason to concentrate on one of them more than on another one and it is virtually impossible to cover them all
  • and finally: nothing is forever - you never know where a project will go in the future and what you'll need to change

A good example (of the third point) are code samples from manuals - you copy them to quickly get something working - but later you modify it and sometimes you change every character from the original. Another one can be the scaffolding code in Rails - you can debate if it fits the first or the second or other points - but it was useful to a lot of people.

Every library can be used as scaffolding - so why not accept this and help the developers in using it that way?


phil jones said...

Hmmm ... surely a library is a collection of components that can be included in your application. That's not a relation which you expect to disappear. What happens if your library suddenly went out of date? You'd replace it with a new one?

The nearest thing I can think of to a disposable library is, say, a library of mock objects that simulate a database, which may get replaced by the real database at some point.

However, even these you'd normally want to keep around for running unit tests etc.

zby said...

Hi Phil,

Haven't you changed or completely got rid of some library when refactoring your code? In my practice that happens, it happens with my own libraries and with external ones, and it happens mostly at the beginning of the coding, but sometimes later as well.

phil jones said...

Agreed, I've sometimes thrown a library away during a refactoring. But I think you're talking about something different : *planning* to throw a library away; choosing to use a set of components which I know I'm going to move away from later.

Now I agree that there are kinds of scaffolding which you plan to throw away, eg. code-generators like Instacrud, but I don't think that the relationship your code has with a library (ie. calls to it scattered all over the place *in* code) is this kind of "short-term relationship".

When you know you are using something as temporary scaffolding, you definitely want dependencies to it to be ruthlessless demarcated and encapsulated in time and space. (Ie. in one place and at one fixed time.)

Library-use doesn't follow this pattern.