Re: Creating framework for singleton pattern?
From: Nick Malik (nickmalik_at_hotmail.nospam.com)
Date: 10/22/04
- Next message: Anders Borum: "Shortened code here .."
- Previous message: MrNobody: "Re: Can I filter rows or create aggregate rows with DataTable?"
- In reply to: Daniel O'Connell [C# MVP]: "Re: Creating framework for singleton pattern?"
- Next in thread: Daniel O'Connell [C# MVP]: "Re: Creating framework for singleton pattern?"
- Reply: Daniel O'Connell [C# MVP]: "Re: Creating framework for singleton pattern?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 22 Oct 2004 15:21:54 GMT
> >> > The Wiki page that I linked is one of hundreds of pages that call
into
> >> > question the usefulness, in the long run, of the Singleton pattern.
> >> >
> >> Perhaps it is, but its probably among the worst. That page is little
more
> >> than semi-technical rambling by people who may or may not know
> >> what they are talking about.
> >
> > All of us are in the category of people who "may or may not know what
they
> > are talking about."
> >
> > The wiki page has a long quote from Kent Beck, creator of Extreme
> > Programming, discussing a major design issue that he refactored out
simply
> > by removing a badly used Singleton. > >
>
> That is supposed to be impressive, then?
Not particularly. However, you did note that these folks "may or may not
know what they are talking about". In my mind, you were implying that their
opinion was not useful because you were not aware of any potential
credentials that may lend them credibility. Maybe I misunderstood your
statement. I was only attempting to point out that this objection was
perhaps inconsistent with the content of the specific page.
>
> Opinion is the name of the game, and, IMHO, previously insufficent
evidence
> was presented to base an article warning off of. Y
I agree that the wiki page was, by itself, insufficient to make an argument.
It is a glimpse into a conversation that raged as a debate nearly two years
ago. It's kind of hard to pick up in the middle.
> Once I've read the other material I may change my mind, or I may not.
Your thoughtful consideration is more than enough reward for the effort that
comes from responding to a newsgroup, and I am glad of it.
> Common practices need to be built on a general consenus, which I have not
yet seen.
>
I agree that common practices need to built on general consensus. The
patterns community largely has reached consensus that the Singleton pattern
is often misused and should be described with sufficient cautions and
warnings to help new readers to avoid common mistakes. You do not need to
take my word on it. Perhaps some of the links I provided will help. You
can also google on the term "Singletons Are Evil" to find more.
> I don't particularly like the "NEVER USE GLOBAL VARIABLES OR
> ELSE" threats issued in best practices books and articles. They are
> inflammatory and without regard for reasons to use global variables and
> patterns beyond the OO purists point of view. OO simply isn't everything
and
> shouldn't(perhaps cannot) be shoehorned into every solution. The mere fact
> people use singletons and static members is a testimony to that.
I don't know whether to respond to this or not. I don't consider it harmful
for an author to warn their readers away from a practice that they feel will
produce code that is difficult to debug or maintain. Whether or not you
agree with their evaluation of the "offending" practice, we all benefit from
the discussion.
>
> Best practices are best only in the sense that they are ideal. Ideality
and
> the real world don't always coincide. Global variables are fine when they
> are appropriate, as are singletons and gotos. No one of them should be
> labelled as bad, just particular patterns using them.
Your statement is no more or less "opinion" than those of the people whom
you label "purists." The statement that "nothing is bad" is as much a
valid viewpoint as the statement that "globals are bad" or that "Singletons
are commonly misused." In that same vein, to leave a potentially harmful
practice without a warning is making a statement of opinion just as much as
placing a warning. It is an act of omission. It is still the expression of
an opinion. Ultimately, it is the opinion of the author that always
emerges, and it is the judgement of the reader to accept or reject that
opinion.
> > A warning is not a slippery slope, denying the
> > reader of valuable technical content. It is a door to
> > more knowledge that the
> > reader has the right to walk through, whenever they see fit. Heck...
it's
> > Jon's article, not mine! He's an excellent writer. Do you think he
can't
> > figure out how to strike a balance?
>
> Its actually potentially a prod in the direction of an authors opinion
> instead of prevailing opinion.
>
see my comment above about opinions.
> I merely stated that some caution
> and extra consideration would be a good idea.
I do not disagree with this statement.
> I simply
> replied that you hadn't offered much in way of suggesting that this is a
> warning thats anymore valid than say...a warning that the household
cleaner
> may smell bad. It may be true, but it may not really be a useful one. A
> warning is certainly merited if there are real problems, but it is not if
it
> is based entirely on a small selection of people and their particular view
> on the world.
>
It is kind of silly to warn people not to use a hair dryer while sitting in
the bathtub. However, people have done that, and injuries have occurred. A
warning is usually justified if even a small number of poorly educated
people do something that more educated people would scoff at. In
programming, we are not dealing with life and death quite so much, but that
doesn't mean we shouldn't consider using a similar standard.
>
> Yes, anyone can investigate further, they say that with regards to alot of
> things(like commercials, for example), but what percentage does? Much in
the
> same way as it would be to mention no negatives at all, it is rather
> unbalanced to only reference negative ideas about a given idea in an
> article(even if that articles entire purpose is to discredit or discourage
> an idea). An article that only points out the flaws in something or goes
out
> of its way to make a point in exposing flaws is particularly
untrustworthy,
> or should be considered as such, IMHO.
Can we move from a discussion of the wiki article itself to a discussion of
Singletons, please? I concede that the wiki article was not a good way to
introduce readers to a discussion that was VERY visible and very heated just
a few years ago. I thought I was reminding folks. I should have been more
careful in respect to people who had missed the earlier discussion
completely.
>
> Again, this isn't to say that Jon can't or won't balance his article well.
I
> am just saying that there is alot more to the picture than simply the
> negating side of the argument. I do think, however, that the best course
may
> be to write a seperate article lining out the points and making his
> recommendations and linking to *that* from the technical article rather
than
> trying to wedge warnings into the technical article itself and risk
> comprimising the article because of it. But, again, thats me.
>
That is a very good suggestion and one in which I would encourage any
author, including Jon, to consider.
This is a good note to end on.
Thanks for the discussion.
--- Nick
- Next message: Anders Borum: "Shortened code here .."
- Previous message: MrNobody: "Re: Can I filter rows or create aggregate rows with DataTable?"
- In reply to: Daniel O'Connell [C# MVP]: "Re: Creating framework for singleton pattern?"
- Next in thread: Daniel O'Connell [C# MVP]: "Re: Creating framework for singleton pattern?"
- Reply: Daniel O'Connell [C# MVP]: "Re: Creating framework for singleton pattern?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|