Efficient Coding

Not sure what to dub this… But here’s the situation. I have been doing some EJB/JSP/JSTL coding. Partly looking at some existing source and refactoring, and designing and coding a better mousetrap myself.

One chunk of source code was full of code in triplicate (including repeating all of the fields in multiple JSPs), or code that was 99% the same as a base class/action. Mind you, this code is for handling displaying, editing, and creating new objects for a 50+ class model. If it were for one or two classes, I almost could care less how it was written.

Maybe I am old school. Maybe it is from years of C++ and early Java. Maybe I am lazy. I don’t know. But to me, I look to eliminate these design smells and reduce repetitive code. It is also a factor in making the code easier to understand and maintain down the road. I scratch my head wondering why the developer thought that this was the easiest and best solution. I would beat myself with a stick if, as I got into implementing a design of mine, it turned out to be a nightmare. I’d go back and try to improve it. A matter of pride? Not at all. A matter of trying to do it more efficiently (or call me lazy).

While refactoring is a way to catch this, it is also a matter of when to refactor. Doing it after 50 things are already triplicated is much more difficult (and budget busting) than catching it early on in the design and testing phase.

This work was done in a distributed team. Name of the game here — if the developer had no pair — is to have a point in the process where the code design is reviewed. Another pair of eyes might have spotted this early on.