Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #3703 > unrolled thread

Singleton quintessence

Started bybob <bob@coolfone.net>
First post2013-09-07 18:36 -0700
Last post2013-09-14 11:34 -0700
Articles 11 — 9 participants

Back to article view | Back to comp.programming


Contents

  Singleton quintessence bob <bob@coolfone.net> - 2013-09-07 18:36 -0700
    Re: Singleton quintessence Geoff <geoff@invalid.invalid> - 2013-09-07 18:49 -0700
      Re: Singleton quintessence Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-09-07 22:12 -0700
    Re: Singleton quintessence Ney André de Mello Zunino <zunino@softplan.com.br> - 2013-09-09 14:17 -0300
      Globals/"static" access in OO languages. (Was: Singleton quintessence) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-09-09 15:09 -0700
        Re: Globals/"static" access in OO languages. (Was: Singleton quintessence) Richard Damon <Richard@Damon-Family.org> - 2013-09-14 14:14 -0400
          Re: Globals/"static" access in OO languages. (Was: Singleton quintessence) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-09-14 11:31 -0700
            Re: Globals/"static" access in OO languages. (Was: Singleton quintessence) Robert Miles <milesrf@Usenet-News.net> - 2013-09-14 23:50 -0500
              Re: Globals/"static" access in OO languages. (Was: Singleton quintessence) Ian Collins <ian-news@hotmail.com> - 2013-09-15 17:18 +1200
    Re: Singleton quintessence "Charles Richmond" <numerist@aquaporin4.com> - 2013-09-10 17:34 -0500
    Re: Singleton quintessence Öö Tiib <ootiib@hot.ee> - 2013-09-14 11:34 -0700

#3703 — Singleton quintessence

Frombob <bob@coolfone.net>
Date2013-09-07 18:36 -0700
SubjectSingleton quintessence
Message-ID<179c6d53-7d84-438d-8047-b7fd8038a2cf@googlegroups.com>
So, I was asked in an interview to name a situation where you would use a singleton.  I was at a loss for coming up with a "good" answer.

Anyone know of a "good" answer as to when you would use a singleton?

Thanks.

[toc] | [next] | [standalone]


#3704

FromGeoff <geoff@invalid.invalid>
Date2013-09-07 18:49 -0700
Message-ID<bkln291pdrsb15dk4pejf2j4kndtb2a7kt@4ax.com>
In reply to#3703
On Sat, 7 Sep 2013 18:36:39 -0700 (PDT), bob <bob@coolfone.net> wrote:

>So, I was asked in an interview to name a situation where you would use a singleton.  I was at a loss for coming up with a "good" answer.
>
>Anyone know of a "good" answer as to when you would use a singleton?
>
>Thanks.

So, you are interviewing for a job in which it is important to know a
technical subject in which you have no expertise and you want someone
to feed you the answers so you can pass the test?

Is this what you did in school too?

I'm so glad you're working hard at cribbing and cheating on your
exams. It makes me so happy for the future of the world to see
induhviduals like you getting highly paid jobs in engineering.

[toc] | [prev] | [next] | [standalone]


#3705

FromDaniel Pitts <newsgroup.nospam@virtualinfinity.net>
Date2013-09-07 22:12 -0700
Message-ID<BGTWt.14386$tv5.8908@fx29.iad>
In reply to#3704
On 9/7/13 6:49 PM, Geoff wrote:
> On Sat, 7 Sep 2013 18:36:39 -0700 (PDT), bob <bob@coolfone.net> wrote:
>
>> So, I was asked in an interview to name a situation where you would use a singleton.  I was at a loss for coming up with a "good" answer.
>>
>> Anyone know of a "good" answer as to when you would use a singleton?
>>
>> Thanks.
>
> So, you are interviewing for a job in which it is important to know a
> technical subject in which you have no expertise and you want someone
> to feed you the answers so you can pass the test?
>
> Is this what you did in school too?
>
> I'm so glad you're working hard at cribbing and cheating on your
> exams. It makes me so happy for the future of the world to see
> induhviduals like you getting highly paid jobs in engineering.
>

There is rarely a good reason to use a singleton.  There are some 
though. In resource-constrained environments, a singleton can reduce 
footprint.  If you have a class whose state must exist only once in a 
running instance of your program, then a singleton is what you would use.

This is almost never the case, and it would be better to have a 
framework that manages the lifecycle of that object, such as any of the 
common IoC containers (Spring, Symfony, and more).

[toc] | [prev] | [next] | [standalone]


#3710

FromNey André de Mello Zunino <zunino@softplan.com.br>
Date2013-09-09 14:17 -0300
Message-ID<l0kvqd$gqn$1@speranza.aioe.org>
In reply to#3703
On 07/09/2013 22:36, bob wrote:
> So, I was asked in an interview to name a situation where you would use a singleton.  I was at a loss for coming up with a "good" answer.
>
> Anyone know of a "good" answer as to when you would use a singleton?
>
> Thanks.

<mild-irony>
     When you feel like giving globals an OO treatment.
</mild-irony>

-- 
Ney André de Mello Zunino

[toc] | [prev] | [next] | [standalone]


#3714 — Globals/"static" access in OO languages. (Was: Singleton quintessence)

FromDaniel Pitts <newsgroup.nospam@virtualinfinity.net>
Date2013-09-09 15:09 -0700
SubjectGlobals/"static" access in OO languages. (Was: Singleton quintessence)
Message-ID<iGrXt.29592$PB4.5568@fx03.iad>
In reply to#3710
On 9/9/13 10:17 AM, Ney André de Mello Zunino wrote:
> On 07/09/2013 22:36, bob wrote:
>> So, I was asked in an interview to name a situation where you would
>> use a singleton.  I was at a loss for coming up with a "good" answer.
>>
>> Anyone know of a "good" answer as to when you would use a singleton?
>>
>> Thanks.
>
> <mild-irony>
>      When you feel like giving globals an OO treatment.
> </mild-irony>

This got me thinking. Would a language be utterly incapacitated if you 
were to eliminate static/globals from its capabilities?

I'm thinking of a case where you replace static/global access with a 
"container" pattern (for example from Spring or Symfony).

The container object would have to be passed around everywhere, or 
accessible through objects that were passed around. Some developers 
might be annoyed by this, but would it be enough to kill the language as 
a general purpose language?

[toc] | [prev] | [next] | [standalone]


#3727 — Re: Globals/"static" access in OO languages. (Was: Singleton quintessence)

FromRichard Damon <Richard@Damon-Family.org>
Date2013-09-14 14:14 -0400
SubjectRe: Globals/"static" access in OO languages. (Was: Singleton quintessence)
Message-ID<rI1Zt.83896$5r1.40610@en-nntp-14.dc1.easynews.com>
In reply to#3714
On 9/9/13 6:09 PM, Daniel Pitts wrote:
> This got me thinking. Would a language be utterly incapacitated if you
> were to eliminate static/globals from its capabilities?
> 
> I'm thinking of a case where you replace static/global access with a
> "container" pattern (for example from Spring or Symfony).
> 
> The container object would have to be passed around everywhere, or
> accessible through objects that were passed around. Some developers
> might be annoyed by this, but would it be enough to kill the language as
> a general purpose language?
> 
> 

Excessive use of global information is bad, because it can hid data
dependencies. Totally eliminating it is probably impossible without
somewhat redefining the terms or resorting to a "God" object to replace
it. The fundamental problem is that there are some resources that are
naturally global to the system, like dynamic memory and the file system,
that really need globals to access.

You can fake hiding global data by having global access functions that
access the data for you, but this really isn't that different than
exposing the global data, which is sort of what is done with the file
system and dynamic memory.

[toc] | [prev] | [next] | [standalone]


#3733 — Re: Globals/"static" access in OO languages. (Was: Singleton quintessence)

FromDaniel Pitts <newsgroup.nospam@virtualinfinity.net>
Date2013-09-14 11:31 -0700
SubjectRe: Globals/"static" access in OO languages. (Was: Singleton quintessence)
Message-ID<lY1Zt.36438$Dw7.6438@fx31.iad>
In reply to#3727
On 9/14/13 11:14 AM, Richard Damon wrote:
> On 9/9/13 6:09 PM, Daniel Pitts wrote:
>> This got me thinking. Would a language be utterly incapacitated if you
>> were to eliminate static/globals from its capabilities?
>>
>> I'm thinking of a case where you replace static/global access with a
>> "container" pattern (for example from Spring or Symfony).
>>
>> The container object would have to be passed around everywhere, or
>> accessible through objects that were passed around. Some developers
>> might be annoyed by this, but would it be enough to kill the language as
>> a general purpose language?
>>
>>
>
> Excessive use of global information is bad, because it can hid data
> dependencies. Totally eliminating it is probably impossible without
> somewhat redefining the terms or resorting to a "God" object to replace
> it. The fundamental problem is that there are some resources that are
> naturally global to the system, like dynamic memory and the file system,
> that really need globals to access.
>
> You can fake hiding global data by having global access functions that
> access the data for you, but this really isn't that different than
> exposing the global data, which is sort of what is done with the file
> system and dynamic memory.
>

Hmm, I could see the entry point of the program accepting a "System" 
object, which provides access to those resources.

At the same time, I'm not really sure those are the same concept as 
static.  Perhaps behind the scenes they are. So system calls may need to 
access "static" data, but the application itself wouldn't directly 
access static/global data.

[toc] | [prev] | [next] | [standalone]


#3736 — Re: Globals/"static" access in OO languages. (Was: Singleton quintessence)

FromRobert Miles <milesrf@Usenet-News.net>
Date2013-09-14 23:50 -0500
SubjectRe: Globals/"static" access in OO languages. (Was: Singleton quintessence)
Message-ID<52353ca9$0$44511$862e30e2@ngroups.net>
In reply to#3733
On 9/14/2013 1:31 PM, Daniel Pitts wrote:
> On 9/14/13 11:14 AM, Richard Damon wrote:
>> On 9/9/13 6:09 PM, Daniel Pitts wrote:
[snip]
> Hmm, I could see the entry point of the program accepting a "System" 
> object, which provides access to those resources.
>
> At the same time, I'm not really sure those are the same concept as 
> static.  Perhaps behind the scenes they are. So system calls may need 
> to access "static" data, but the application itself wouldn't directly 
> access static/global data.
>
At least in C, "static" means that the value(s) of the object never 
change as the program runs; this is used mainly to tell the compiler 
that it can use optimizations that depend on these values never changing.

Of course, if you don't care how fast your program runs or how much 
memory it uses, you don't need to bother with optimizations.

[toc] | [prev] | [next] | [standalone]


#3737 — Re: Globals/"static" access in OO languages. (Was: Singleton quintessence)

FromIan Collins <ian-news@hotmail.com>
Date2013-09-15 17:18 +1200
SubjectRe: Globals/"static" access in OO languages. (Was: Singleton quintessence)
Message-ID<b9ku9fF16ooU1@mid.individual.net>
In reply to#3736
Robert Miles wrote:
> On 9/14/2013 1:31 PM, Daniel Pitts wrote:
>> On 9/14/13 11:14 AM, Richard Damon wrote:
>>> On 9/9/13 6:09 PM, Daniel Pitts wrote:
> [snip]
>> Hmm, I could see the entry point of the program accepting a "System"
>> object, which provides access to those resources.
>>
>> At the same time, I'm not really sure those are the same concept as
>> static.  Perhaps behind the scenes they are. So system calls may need
>> to access "static" data, but the application itself wouldn't directly
>> access static/global data.
>>
> At least in C, "static" means that the value(s) of the object never
> change as the program runs; this is used mainly to tell the compiler
> that it can use optimizations that depend on these values never changing.

s/static/const/

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#3715

From"Charles Richmond" <numerist@aquaporin4.com>
Date2013-09-10 17:34 -0500
Message-ID<l0o6oq$j17$1@dont-email.me>
In reply to#3703
"bob" <bob@coolfone.net> wrote in message 
news:179c6d53-7d84-438d-8047-b7fd8038a2cf@googlegroups.com...
> So, I was asked in an interview to name a situation where you would use a 
> singleton.  I was at a loss for coming up with a "good" answer.
>
> Anyone know of a "good" answer as to when you would use a singleton?
>

Sorry, I don't play bridge...  ;-)

--

numerist at aquaporin4 dot com

[toc] | [prev] | [next] | [standalone]


#3728

FromÖö Tiib <ootiib@hot.ee>
Date2013-09-14 11:34 -0700
Message-ID<2710e6ca-3f6a-44c6-b3ab-8f1620959579@googlegroups.com>
In reply to#3703
On Sunday, 8 September 2013 04:36:39 UTC+3, bob  wrote:
> So, I was asked in an interview to name a situation where you would use
> a singleton.  I was at a loss for coming up with a "good" answer.
> 
> Anyone know of a "good" answer as to when you would use a singleton?

Lot of good programmers answer "nowhere". Some good programmers suggest
it for things that are assumed to be and stay as single instance forever.

Examples depend on program. Popular examples like configuration, input
stream, output stream, debug log etc. may be single in one program and
multiple in other.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.programming


csiph-web