When to inline!

Today we were working on a bit of code that is at the centre of our application. It is the front controller for the entire website.

There are several loops in there which switch between different page renderers and handlers for the request.

We initially thought to put these into seperate methods to make the body of this method shorter but actually in the end it looked much better with everything inline.

We did have quite a bit of exeption handling so we decided to create a “handleInternal” method which does the actual work and so we seperate the loops from the exception handling code.

This is a good example of when it is not so good to factor everything into seperate methods – it was actually more confusing for another person to look at – as we had to be sure to name all the methods right – in such a critical piece of code it is maybe easier to read if the loops are there.

I think.

Im still slightly undecided – sometimes i find it easier to read code if the details of looping etc are hidden away from me – and im just presented with a set of method names that are descriptive about the process.

In this case however maybe the clue was that we couldnt really find some unambiguous names for the methods and also you did actually care what they did somehow.

  • Share/Bookmark