A little while ago I came across the following blog posts by John Kleijn at phpfreaks:
Both of the posts are good examples of good and bad sides to blogging about developing. First, the good parts:
- It's great to have someone list of a number of things that you can check your own code for. Am I committing these mistakes? Could I avoid the mentioned problems?
- It's also great to have some idea of where others are taking development. Is there cool new stuff I should be trying?
The medium of the numbered list makes these things very accessible - you glance through and read a bit closer if it catches your attention. You get motivated to find out more. However:
- Why 10 points? Are there only 10 signs of crappy PHP software? Are there just 10 ways to avoid writing crappy code?
- Is point 1 more important than point 10? Or?
In other words, these lists have the look of roadmaps: how to do this, how to avoid that, get laid in 5 easy steps, blah blah. Another blog I follow a bit, Boagworld, does this quite a lot. What they should do is give you an idea of things but instead they often end up looking like The Truth. Which leads me to a personal gripe.
1 sign that you're an arrogant coder thinking you know better than the rest when in fact you don't
- Yelling and screaming at people for using or advising others not to use singletons.
Singletons have to be the most misunderstood design pattern for all the wrath they're getting. It's absurd to see the amount of abuse it gets ... and for what? The singleton is a pattern to make sure only one instance of a class gets created. It is designed specifically to handle the situations WHERE ONLY ONE INSTANCE should exist. So you know instantly when you hear criticism like:
A database connection is probably the poorest example you could have possibly chosen. What if I need two simultaneous connections?
Well, then you bloody well wouldn't have chosen the singleton pattern would you now? ONLY ONE INSTANCE! HOW. HARD. IS. THAT. TO. UNDERSTAND??
I find it incredible that 'experienced' or 'senior' developers rail against this thing - it's as if they've never used it but only seen apparitions of the singletons evil brother. When you have a situation in which a given class should only be created once but access to it is needed in all parts of your app, the singleton pattern is not a bad design - on the contrary, it's a good design. The point about design patterns is not knowing them but knowing when and how to use them - railing about the evil of the singleton pattern shows lack of knowledge about it.
So please, if you're ever considering ranting on about how a given design pattern (or something else) is evil then please, take the time to actually understand it first. Then write your blog/article about how the thing is actually not evil but should be used with care. Or go ahead and write that guns kill people and if there were just no guns, there would be no dead people.