Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Singletons

Name: Anonymous 2009-01-09 5:18

A toast for one of my favorite ways to create and interact with things. I love you, singleton. And there's only one of you.

Name: Anonymous 2009-01-09 5:20

NO EXCEPTIONS

Name: Anonymous 2009-01-09 5:21

A toast for one of my favorite ways to create and interact with things. I love you, global. And there's only one of you.

Name: Anonymous 2009-01-09 5:23

A toast for one of my favorite ways to create and interact with things. I love you, (unsigned char*). And there's only one of you.

Name: Anonymous 2009-01-09 5:25

In Java, everything is a singleton.

Name: Anonymous 2009-01-09 7:50

Just use globals and stop being a fag

Name: Anonymous 2009-01-09 9:56

>>6
Some languages have such retarded scoping rules that a singleton can be much easier. Java being the obvious example.

Name: Anonymous 2009-01-09 10:55

>>7
Bullshit. There's nothing stopping you from having a class definition filled with public static members in Java -- effectively a global scope but without the .getInst() instantiation faggotry.

Name: Anonymous 2009-01-09 11:17

A toast for one of my favorite ways to create and interact with things. I love you, Haskell. And there's only one of you.

Name: Anonymous 2009-01-09 11:21

>>9
But Haskell can't interact with things!

Name: Anonymous 2009-01-09 13:16

Using globals is for fags as the object does not belong in the global namepsace. Also, there is little you can do with resource allocation with a global.

Using static members is super faggy as the singleton pattern is poorly named. Its aim is to not just restrict the number of instances to 1. Its aim is to just restrict the number of possible instances to some number. Sometimes that number will be 1.

Name: Anonymous 2009-01-09 13:26

>>11
Somegleton?

Name: Anonymous 2009-01-09 13:39

>>10
Oh no? I see you're not familiar with Zoonecrophilia.

Name: Anonymous 2009-01-09 13:56

>>7
Just use c and stop being a fag

Name: Anonymous 2009-01-09 14:22

>>14
C? Not faggotry?
laughingelfman

Name: Anonymous 2009-01-09 15:22

>>15
C is the most heterosexual programming language in existence.

Name: Anonymous 2009-01-09 15:58

>>16
Then maybe it should go out and get fucked.

Name: Anonymous 2009-01-09 16:11

>>17
That's how Sepples came to be.

Name: Anonymous 2009-01-09 17:52

public Singelton() {
  static Class clase;
  public Singelton(Base clase) {
    this.clase = clase.
  }
}

Name: Anonymous 2009-01-09 18:05

>>19
Crass class clase!

Name: Anonymous 2009-01-09 19:16

public class EnterpriseSingleton extends java.lang.Object {
  private static EnterpriseSingleton _enterpriseSingleton;

  private EnterpriseSingleton() {
    /* Empty constructor */
  }

  /**
   * Enterprise thread safety
   */
  public static EnterpriseSingleton getInstance() {
    if (_enterpriseSingleton == null) {
      synchronized (EnterpriseSingleton.class) {
        _enterpriseSingleton = new EnterpriseSingleton();
      }
    }
    return _enterpriseSingleton;
  }

}

Name: Anonymous 2009-01-10 14:38

>>21
BEWARE /prog/ THIS IS NOT THREAD SAFE, DO NOT INCLUDE THIS IN ANY ENTERPRISE APPLICATIONS.

Fixed:
public class EnterpriseSingleton {
  private static EnterpriseSingleton enterpriseSingleton;

  private EnterpriseSingleton() {
  }

  public static EnterpriseSingleton getInstance() {
    if (enterpriseSingleton == null) {
      synchronized (EnterpriseSingleton.class) {
        if (enterpriseSingleton == null) {
          enterpriseSingleton = new EnterpriseSingleton();
        }
      }
    }
    return enterpriseSingleton;
  }
}

This version also alleviates the performance overhead associated with using synchronized blocks.

Name: Anonymous 2009-01-10 15:08

>>8
You'd be surprised how poorly that plays with inner classes.

Name: Anonymous 2009-01-10 15:15

>>22
Your version is still not thread safe. Due to the JAVA memory model, one thread may acquire the lock, see that enterpriseSingleton is null, and begin instantiating it. Before the instantiation has finished, another thread may observe the enterpriseSingleton as being non-null, and so attempt to use the object when it is only partly initialized.

Here is a version that fixes the problem.

public class EnterpriseSingleton {
  private static EnterpriseSingleton enterpriseSingleton;

  private EnterpriseSingleton() {
  }

  public static EnterpriseSingleton getInstance() {
    if (enterpriseSingleton == null) {
      EnterpriseSingleton temp;
      synchronized (EnterpriseSingleton.class) {
        if (enterpriseSingleton == null) {
          temp = new EnterpriseSingleton();
        }
        synchronized (EnterpriseSingleton.class) {
          enterpriseSingleton = temp;
        }
      }
    }
    return enterpriseSingleton;
  }
}

Name: Anonymous 2009-01-10 18:36

>>24
What?  How could the assignment complete before the constructor returns?

Name: Anonymous 2009-01-10 19:50

>>25
ninjas

Name: Anonymous 2009-01-11 12:36

Name: Anonymous 2009-01-11 13:03

>>24
hint: use volatile

Name: Anonymous 2009-01-11 13:16

Wait a minute, guys. I'm getting the impression that WHBT in this thread!

Name: Anonymous 2009-01-11 13:21

>>27
There are lots of reasons it doesn't work. The first couple of reasons we'll describe are more obvious. After understanding those, you may be tempted to try to devise a way to "fix" the double-checked locking idiom. Your fixes will not work: there are more subtle reasons why your fix won't work. Understand those reasons, come up with a better fix, and it still won't work, because there are even more subtle reasons.

OH WOW.

Name: Anonymous 2009-01-11 14:08

It's subtle reasons all the way down.

Name: Anonymous 2009-01-11 14:31

JAVA is clean and simple to use

Name: Anonymous 2009-01-12 3:33

>>29
By whom?

Name: Anonymous 2009-01-12 6:19

>>32
see
>>33

Name: Anonymous 2009-01-12 7:59

>>32,34
Sarcasm is not trolling.

Name: Anonymous 2009-01-12 8:14

>>35
/prog/ considers everything thats more advanced then memes "trolling"

Name: Anonymous 2009-01-12 10:45

>>36
Go back to using your tripcode so I can ignore you, FrozenVoid.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-12 13:56

>>37
If you think this these posts are because of your script which blocks me, the explanation can be much simpler:
 I need to select my tripcode from the autocomplete drop-down list everytime i post, and i sometimes omit this step.

Name: Anonymous 2009-01-12 15:44

>>38
Can you write a script to automate that step?

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-12 15:52

>>39
/prog/ is not significant enough for it. It got like 20-40 users.
If i decide to stay here longer,i'll write it,but i don't really care if I posted anonymously on accident or by laziness. When i write a post long enough i would surely check name autocomplete before hitting reply.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List