Link Details

Link 66052 thumbnail
User 111696 avatar

By bloid
via sitepoint.com
Published: Feb 15 2008 / 11:13

It’s a good question, for it is true that global variables are often demonised and more recently the Singleton has befallen the same fate. Perhaps a bit surprising, it is remarkably hard to find good arguments to support this common knowledge — Googling turns up a lot of confusion.
  • 10
  • 5
  • 1885
  • 903

Comments

Add your comment
User 107114 avatar

daniel replied ago:

2 votes Vote down Vote up Reply

I think his conclusion is absolutely wrong, but it's a good article. Singletons (properly applied) are a way to *reduce* coupling, not increase it. Global state is a fact of life in imperative languages. Unless you want to write things completely functionally, you will have to deal with side-effects at some point. Using global state wrapped within a singleton gives you a way to mitigate the consequences of such side-effects and avoid code duplication.

User 236137 avatar

dzonelurker replied ago:

0 votes Vote down Vote up Reply

Rather, global state is a fact of life for inexperienced programmers. There is no inherent necessity for global state.

User 209464 avatar

willcode4beer replied ago:

0 votes Vote down Vote up Reply

Hasn't the singleton horse been beat to death and then some already?

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.