Monday, April 09, 2007

is not about the pattern, it's about the practice

There's a discussion going on in the blogosphere about "bashing patterns", Corneliu (parallel thinking) says:

This month seems to be the month of bashing the singletons and some of the other design patterns.

From posts like Singleton Considered Stupid to Singleton – the most overused pattern and Criticism on one the Patterns (Blog 3), the blogo-sphere is full of comments about why singleton is bad or evil.


I don't think the problem is with the use of the pattern, but with the abuse of them; but this has always been the problem in programming in general, most of the time programmers learn a few things just to "get things working", and as long as it works "if is not broken why fix it".
Is it all the programmers fault? I don't think so, I think it has to do a lot with management requesting things to be done by yesterday (bad estimates), but that's another topic which has been discussed quite a lot already

so this is not a new problem, is the same old problem (abuse of techniques) applied to the patterns, the patterns are good, the implementation may be correct, but the usage (the practice) of them is the problem

why the singleton? I think because that's one of the "easiest" ones, you can pretty much copy and paste it, you don't even need to understand the inner workings, you just know that "it will be a single instance of your class", and that's something you can't do with other patterns

we need to teach better usages, better practices.

1 comment:

Anonymous said...

Hi Eber,

Part of the discussion came from an acknowledgement that people absorb the 'design' part of a pattern much easier than they absorb the 'guidance' part.

There's also the issue (in the case of singleton) that misapplication can cause severe performance issues in production environments. That was my initial motive for blogging about abuses of singleton - I was aworking on code where this had happened at some time in the past.

Corneliu misunderstood my intent and assumed I was bashing singleton _in_general_, when in fact I was knocking its foolish use in controlling access to what should be stateless business logic components.

My post was in agreement of your point - that singleton are easy, and beginners use it so they can claim they have design pattern experience...

Andrew