Programming Performance and Complexity

oracle.gifThere’s an interesting interview with Joshua Bloch on Oracle’s site. Joshua is the author of "Effective Java" that I happen to already have on my bookshelf. Joshua says some profound things about optimisation…

"It’s easy to feel like the general warnings about premature optimization don’t apply to you, because you just know which code is time-critical and how to make it fast. But no one can determine this without measuring before and after each attempted optimization."

It’s true some developers love optimising things they don’t need to. However, it’s also possible to go in the other direction and totally ignore performance. I’d say that if it’s easy to optimise something AND the code becomes clearer then there’s always a case for spending a moment for a quick read through the code to see if it can be simplified. If it’s complicated to optimise OR the code becomes less readable then we are in the usecase Joshua describes.

Joshua also says…

"In order to stay sane, most developers have a can-do attitude, and some take it too far. They say to themselves, ‘Yes, there’s a library, but I can do better.’ Maybe you can, but that doesn’t mean you should."

This is another problem with some developers. They love to invent or use mechanisms that might not be needed. I worked at a large company a long time ago, that happens to be source of this article, where there were tens of implementations of ‘String’ in the same product just because developers thought they could do better. I have also worked on others’ code that has been over ‘Design Patterned’ that has led to a technical debt.

As Leonardo da Vinci said, “Simplicity is the ultimate sophistication.”