Patterns and Practices or use your brain?

There was a time when i thought you needed to use patterns and best practices to keep consistent and maintainable code. After all if everyone follows them then we are all building software in a similar way. New and existing team members and freelancers can all understand the code and maintain it. Problem solved, blog post over.

However do you end up forcing a pattern into an architecture for the sake of it? This could lead you to not build the best solution for the problem, but the solution with the best use of several patterns. Could your code be simpler and more maintainable without using the patterns?

Best practice treated like a magic bullet.
By applying “best practices” you limit the chances of failing from a certain point of view, but does it stop you thinking and using your brain? One of the many things I learnt working with @grumpydev was that if you use common sense and engage your brain then your code will more than likely be maintainable and others will understand what you are trying to achieve. Also when you come back to that code that you haven’t seen for months does applying common sense and engaging your brain mean you understand your own code easily.

Principles over patterns.
Patterns can be useful, but it depends on context. Just because the pattern worked in one instance does not mean it will always work for the code you are writing. Principles however should when applied well, assist you in writing quality code. My wife bakes cakes as one of many jobs she does (shameless plug – @itcakestwobaby) and started out using a recipe for cupcakes. It describes everything you need to do to make cupcakes just like her. Does this mean anyone can make them like her? Maybe…however I have watched her and she doesn’t stick to the recipe, it is all her own judgement from experience and knowing her ingredients and our oven. I don’t think you can add a spoonful of factory pattern and a dash of decorator pattern and create a perfect solution by keeping to them.

2 Comments

  1. Nice post.

    It might be a more backend thing than frontend but I think it’s good to use a pattern but I also like to do things my own way at times.

    I’ve found with some people that I’ve worked with it that they get very set in their ways and they don’t like change and it all goes to shit should you do something they are not used to or have been told not to like/do.

    You have to be able to adapt in life.

  2. Totally agree. The day that I can’t justify a design decision for a reason other than ‘best practice’ is the day that I give up development.

    Having said that I’ve seen ‘think for yourself’ used as as excuse, when the truth is they can’t be bothered to familiarise themselves with the literature.

    Learn from patterns, but don’t blindly apply them. They’re useful because similar problems do crop up over and over, but it’s the developers job to understand the details about what is different in every situation. Patterns are useful, but they are not rules.

Leave a Reply

Your email address will not be published. Required fields are marked *