Cleaning Code Practically Episode 1

8102009

Last Øredev I were at a presentation done by Robert Martin, author of the book Clean Code. I were really impressed by what his message where. So we are trying to follow his word at work and today a topic came up. So a colleague had this code:

Im not satisfied, but not sure it can be done more clean? And if you are wondering about why we are doing all this string manipulation, we are working with some legacy MQ. If we split up the code without parameters as above we lose the quick overview.. But could the code be simplified even more please come with your suggestion..

While your suggestion does optimize for speed, it does not bring much in terms of readability and overview. We do not have any performance issues on the system. However if one keep saying that then one will probably end up with issues.

Thanks for sharing ideas, the more the better 🙂 I’ll keep the builder pattern in the back of my mind.

Maybe bit late for that specific problem, but you may find it useful more generally: you may want to consider the nested function pattern, is hard to beat in terms of compactness and readability, only issue is making sure your IDE doesnt spoil it with the wrong formatting: