Even if you’re unaware of patterns, you’re using them
Ignoring patterns is a great way to repeat past mistakes
Any type of code you’ve written or are thinking of writing has likely already been done by someone, somewhere. Someone has already identified the pattern you’re implicitly using and gave it a name and formal definition.
How we write code today is not innovative. People just keep forgetting and rediscovering patterns that have existed for 50 to 75 years, or even more considering much of software is mathematics.
Patterns are a shorthand that gets everyone on the same page quickly. If I say “event actor model” or “repository pattern,” even if you don’t know them, you can look them up and know what I mean without me having to explain it in detail.
Know that everything you are about to write likely has a pattern.
Understanding that, instead of starting off designing or writing something from scratch, look for a pattern that matches your use case. You will be able to learn from the mistakes and successes of others. Maybe it’s the right pattern. Maybe it’s the wrong pattern.
At the very least, you will know what not to do. How else will you know that a Singleton is generally a bad idea if you don’t know what one is? You’ll just make one and not know its name.
By writing code, ignorant of patterns, you’re more likely to repeat the mistakes of others who learned the pros and cons of a particular pattern.
That’s good for learning, but bad for productivity.
Phases Of Pattern Usage
I see developers go through phases with patterns:
1. No idea about patterns
2. Starts seeing patterns
3. Realizes others recognized these patterns too
4. Sees many more patterns and starts applying them wrongly or too much
5. Realizes they went overboard
6. Shuns patterns as overkill
7. Thinks “hm, this looks like that pattern I used before”
8. Realizes patterns are good if applied to the problem they were meant to solve when needed
9. Realizes patterns, used pragmatically, are simpler than not using patterns
Typically, for people to learn phase 9, they have to go through all the phases. The sooner you understand this, the sooner you can use patterns to make things simpler, more quickly, and with a shared understanding.
Dev Details is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.