Pattern based programming

anti-patternsdesign-patternsprogramming practices

Can somebody explain the obsession with patterns and anti-patterns in programming? I ask because I have absolutely no idea what any of the patterns mean. When faced with a programming task I think about the problem for a little bit, write down some data structures that I think will be relevant, prototype a solution, separate out some modules and iterate. Nowhere in the process do I think "Oh, I need FunkyLookyTastic pattern here".

Best Answer

A pattern is a common approach to solving a common type of problem; nothing more, and nothing less. By knowing and understanding them, you can make use of other people's experiences to guide you towards the kind of solution that's been shown to work well, avoid pitfalls that have been encountered in the past, and discuss the solution using terminology that's familiar to others who know that pattern.

Of course, you can come up with a fine solution without explicitly using a pattern, and equally well come up with a bad solution by trying to apply a pattern that doesn't really fit your particular problem. I think the "obsession" you observe generally comes from people who have just discovered the concept, and think that it is rather more powerful than it actually is. Most people will quickly recognise them for what they are: a useful tool, not a magic bullet.

Anti-patterns, on the other hand, are commonly observed behaviours that tend to reduce code quality. Again, it is useful to know and understand some of these so that you can avoid such behaviour, and try to correct it (with reasoned arguments) when you observe it in others. Some would describe the overuse of patterns as an anti-pattern.

Related Topic