Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Static vs Single Pattern

 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Janeice wrote: 2: What, if any, are the problems with the Singleton pattern, exclusive of the issue of threadsafety (which is supposedly fixed by the "volatile" labeling)

All the other issues in the blog posts I already provided twice, and summarized above.

Regarding the double-locking/threading issue which appears to be a major focus for you:

If you'd read the IBM post you provided, you would have read this:

Editor's note: This article refers to the Java Memory Model before it was revised for Java 5.0; statements about memory ordering may no longer be correct. However, the double-checked locking idiom is still broken under the new memory model. For more information on the memory model in Java 5.0, see "Java theory and practice: Fixing the Java Memory Model" Part 1 and Part 2.

Part 1 of the reference includes the following:

It is worth noting that broken techniques like double-checked locking are still broken under the new memory model, and that "fixing" double-checked locking was not one of the goals of the new memory model effort. (However, the new semantics of volatile allow one of the commonly proposed alternatives to double-checked locking to work correctly, although the technique is still discouraged.)

Part 2 of the reference includes the following: http://www.ibm.com/developerworks/library/j-jtp03304/#3.2

I really, really hope this stops further discussion about the double-locking thing.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Janeice DelVecchio wrote:I never said singletons were good or bad. I just don't know. Actually, my very first post said I made no assertions whether or not they should be used or not. I said I understood the basic concept of why someone would use it over a static variable. Rather, I think I just compared the two, not even made an assertion of why it should be used over a static variable.

What I said was that no one could tell me (on a foundational level) what the heck is wrong with using them. Everyone here has said "they're bad," "don't use them," et cetera.

I got links to blog posts from several years ago. Are these people respected in the field? I have no idea. No one said, "please see Joe Shmoe's blog, he's a such and such person in the blah blah industry for x years. He did studies for blah company."

When I questioned the sources, on an academic level, no one could defend the fact that the sources were blogs. No one could find a reputable source (or at least define what makes the blogs reputable).

If someone could tell me, in normal person language:
1: Why doesn't the JDK5 "volatile label fix" work to fix the singleton problem?
2: What, if any, are the problems with the Singleton pattern, exclusive of the issue of threadsafety (which is supposedly fixed by the "volatile" labeling)

I am really through with feeling like I have to defend myself. Just because I ask questions doesn't mean I'm questioning anyone's judgement, it just means I'm not going to take advice on face value no matter how long you've been following it.



Well, to cut all the crap why don't you just ask people to come up with a better solution to my postoffice Singleton?

What I'm using here is a variation of the Occam's razor, or the simplest solution is the correct one. Show a simpler solution to the postoffice Singleton and Singleton itself is in question. But until then, Singleton rules.
 
Ulrika Tingle
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
To my previous post.

You can find anything on the internet, including that OO sucks. The fact that some people on the internet think that Singleton sucks is in itself not a proof that Singleton is bad.

The fact that it's hard to perfectly implement a Singelton is in itself not a proof that Singleton sucks. Lots of very useful things are hard to implement, many of them even harder than a Singelton.

The fact that people misuses Singelton is not a proof that Singelton sucks. People misuses all sorts of language elements in every programming paradigm all the time.

So the only real test of the usefulness of Singleton is to apply Occam's razor as I explained in my previous reply.
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Ulrika Tingle wrote:To my previous post.

You can find anything on the internet, including that OO sucks. The fact that some people on the internet think that Singleton sucks is in itself not a proof that Singleton is bad.

The fact that it's hard to perfectly implement a Singelton is in itself not a proof that Singleton sucks. Lots of very useful things are hard to implement, many of them even harder than a Singelton.

The fact that people misuses Singelton is not a proof that Singelton sucks. People misuses all sorts of language elements in every programming paradigm all the time.

So the only real test of the usefulness of Singleton is to apply Occam's razor as I explained in my previous reply.



I agree with the given post and in a kinder way:
yes, there are people who hate things, but its never justified that all should hate them because you hate them....
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Quite honestly I find this post to contain a variety of arguements,
but no one here has shaken up my beliefs in singletons,
not only that, no one has an alternative soln for the post office example...

and yes, many of the blogs are more opinions than facts as suggested by Janeice DelVecchio
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Then define a "fact". I don't see how anybody could argue in any reasonable way against what the blog posts say.

If you decide to try, please start a new thread in an appropriate forum; I'm locking this one.
 
    Bookmark Topic Watch Topic
  • New Topic