Sunday, January 30, 2011

Software engineering on demand

I'm just about to finish Refactoring to Patterns and it made me think about experience with applying design patterns. I have attended a few university courses regarding design patterns and every time I learned something new - I was so eager to implement it that I probably have made some mistakes.

The main idea in this book is to apply design patterns only when you have to. Design patterns are great for solving well known problems and they are tool that every software engineer should have in its toolbox. But when it comes to solving problems that are not there you can really shoot yourself in the foot using design patterns. From my experience as a professional developer I often have to maintain and extend someone else's code. And this part of the job. Whether this colleague is no longer in the company or is currently working on a different project, you can't escape it. I've noticed that over-engineering is as frequent mistake as under-engineering. And it can cause a lot of damage to every project. I have caughted myself very eager to try some new technology or pattern where it is not actually necessary. As a result - the project gets harder to maintain and extend and probably there is a severe performance penalty.

The best way to avoid this problem is to apply patterns and technologies on demand. Do not try to predict future business requirements and do not fulfil them without any need. You can always refactor your code later when it is actually needed. And this book will give you some guidelines how to perform refactoring in some common cases.

Still, we are all human - how to overcome this affinity to try and implement new stuff as soon as you meet them. Use the sandbox pattern - make yourself a place where you can try, test and evaluate your new ideas. After all not every idea that you read can and should be applied - some are worthless, some are priceless and some - it depends.

The best things are as simple as they should be. We don't kill flies with nuclear weapons. So, don't use abstract factory and strategy pattern to write a "Hello, world!"