Jump to page: 1 2 3
Thread overview
singleton classes
Jan 13, 2004
imr1984
Jan 13, 2004
davepermen
Jan 13, 2004
imr1984
Jan 13, 2004
davepermen
Jan 13, 2004
Matthias Becker
Jan 13, 2004
davepermen
Jan 14, 2004
Matthias Becker
Jan 16, 2004
Sean L. Palmer
Jan 13, 2004
Ant
Jan 13, 2004
J Anderson
Jan 13, 2004
davepermen
Jan 13, 2004
J Anderson
Jan 13, 2004
Andy Friesen
Jan 13, 2004
imr1984
Jan 14, 2004
Ilya Minkov
Jan 15, 2004
Sean L. Palmer
Mar 08, 2004
Manfred Nowak
Jan 13, 2004
J Anderson
Jan 13, 2004
Matthew
Jan 13, 2004
Phill
Singleton classes using templates
Jan 14, 2004
Matthew
Jan 17, 2004
Matthew
Jan 22, 2004
Sean L. Palmer
Jan 22, 2004
Matthias Becker
Jan 24, 2004
Matthew
January 13, 2004
Often programmers make classes that are only intended to have one instance for the duration of the whole program. These are called singleton classes. D should have built in support for them so that a singleton object will have its own methods generated for it, without the use of a this pointer. This would save on a this parameter being pushed on stack to a singleton class method.

Walter, what da ya say?


January 13, 2004
singletons are one of the most stupid trend-programming-idioms.

most people just use them because they don't know how to design else..

in D, i'd suggest you bether write a module. this _is_ what a singleton _should_be_.

a.k.a.

mySingleton.d
--------------
module mySingleton;

private int data;

void set(int value) {
data = value;
}

int get() {
return data;
}
--------------

main.d
--------------
import mySingleton; // private import? :D

int main(char[][] args) {
mySingleton.set(10);
printf("%i" \n,mySingleton.get());
}
--------------

like this

In article <bu0da8$1qic$1@digitaldaemon.com>, imr1984 says...
>
>Often programmers make classes that are only intended to have one instance for the duration of the whole program. These are called singleton classes. D should have built in support for them so that a singleton object will have its own methods generated for it, without the use of a this pointer. This would save on a this parameter being pushed on stack to a singleton class method.
>
>Walter, what da ya say?
>
>


January 13, 2004
ar cheers for that. So D already has support for it then, you just use global private variables. cunning.

In article <bu0ef1$1sds$1@digitaldaemon.com>, davepermen says...
>
>singletons are one of the most stupid trend-programming-idioms.
>
>most people just use them because they don't know how to design else..
>
>in D, i'd suggest you bether write a module. this _is_ what a singleton _should_be_.
>
>a.k.a.
>
>mySingleton.d
>--------------
>module mySingleton;
>
>private int data;
>
>void set(int value) {
>data = value;
>}
>
>int get() {
>return data;
>}
>--------------
>
>main.d
>--------------
>import mySingleton; // private import? :D
>
>int main(char[][] args) {
>mySingleton.set(10);
>printf("%i" \n,mySingleton.get());
>}
>--------------
>
>like this
>
>In article <bu0da8$1qic$1@digitaldaemon.com>, imr1984 says...
>>
>>Often programmers make classes that are only intended to have one instance for the duration of the whole program. These are called singleton classes. D should have built in support for them so that a singleton object will have its own methods generated for it, without the use of a this pointer. This would save on a this parameter being pushed on stack to a singleton class method.
>>
>>Walter, what da ya say?
>>
>>
>
>


January 13, 2004
as singletons are nothing more than that (globals), yes.. the real module support of D makes it possible to have them more easy than in c++

but always remember. singletons ARE just globals. if you don't need them, bether don't make them.

In article <bu0eol$1su2$1@digitaldaemon.com>, imr1984 says...
>
>ar cheers for that. So D already has support for it then, you just use global private variables. cunning.
>
>In article <bu0ef1$1sds$1@digitaldaemon.com>, davepermen says...
>>
>>singletons are one of the most stupid trend-programming-idioms.
>>
>>most people just use them because they don't know how to design else..
>>
>>in D, i'd suggest you bether write a module. this _is_ what a singleton _should_be_.
>>
>>a.k.a.
>>
>>mySingleton.d
>>--------------
>>module mySingleton;
>>
>>private int data;
>>
>>void set(int value) {
>>data = value;
>>}
>>
>>int get() {
>>return data;
>>}
>>--------------
>>
>>main.d
>>--------------
>>import mySingleton; // private import? :D
>>
>>int main(char[][] args) {
>>mySingleton.set(10);
>>printf("%i" \n,mySingleton.get());
>>}
>>--------------
>>
>>like this
>>
>>In article <bu0da8$1qic$1@digitaldaemon.com>, imr1984 says...
>>>
>>>Often programmers make classes that are only intended to have one instance for the duration of the whole program. These are called singleton classes. D should have built in support for them so that a singleton object will have its own methods generated for it, without the use of a this pointer. This would save on a this parameter being pushed on stack to a singleton class method.
>>>
>>>Walter, what da ya say?
>>>
>>>
>>
>>
>
>


January 13, 2004
imr1984 wrote:

>Often programmers make classes that are only intended to have one instance for
>the duration of the whole program. These are called singleton classes. D should
>have built in support for them so that a singleton object will have its own
>methods generated for it, without the use of a this pointer. This would save on
>a this parameter being pushed on stack to a singleton class method.
>
>Walter, what da ya say?
>
>  
>
This should probably be an optimisation issue.

January 13, 2004
davepermen wrote:

>singletons are one of the most stupid trend-programming-idioms.
>
>most people just use them because they don't know how to design else..
>
>in D, i'd suggest you bether write a module. this _is_ what a singleton
>_should_be_.
>
>a.k.a.
>
>mySingleton.d
>--------------
>module mySingleton;
>
>private int data;
>
>void set(int value) {
>data = value;
>}
>
>int get() {
>return data;
>}
>--------------
>
>main.d
>--------------
>import mySingleton; // private import? :D
>
>int main(char[][] args) {
>mySingleton.set(10);
>printf("%i" \n,mySingleton.get());
>}
>--------------
>
>like this
>  
>
But you can't extend that singleton.

January 13, 2004
"imr1984" <imr1984_member@pathlink.com> wrote in message news:bu0da8$1qic$1@digitaldaemon.com...
> Often programmers make classes that are only intended to have one instance
for
> the duration of the whole program. These are called singleton classes. D
should
> have built in support for them so that a singleton object will have its
own
> methods generated for it, without the use of a this pointer. This would
save on
> a this parameter being pushed on stack to a singleton class method.
>
> Walter, what da ya say?

Since the only hard thing about singletons - ensuring that the creation and destruction happens deterministically - is handled in D, by virtue of the module initialisation, where's the need?



January 13, 2004
In article <bu0i1p$21m1$2@digitaldaemon.com>, J Anderson says...
>But you can't extend that singleton.
>
hm? show me how to extend a normal one?

anyways, i don't use singletons myself at all. they are 100% useless imho


January 13, 2004
davepermen wrote:

>In article <bu0i1p$21m1$2@digitaldaemon.com>, J Anderson says...
>  
>
>>But you can't extend that singleton.
>>
>>    
>>
>hm? show me how to extend a normal one?
>  
>
I don't know, parhaps by using static members from a class. But then you don't get virtual functions ;(.  It'd be nice if you could extend namespaces (and templates), which included static virtual functions -> it might help solve the free operators problem.

>anyways, i don't use singletons myself at all. they are 100% useless imho
>
>  
>

But your right, most of the time I change singletons into classes as I realism their more useful that way.  What's an extra memory access on the stack at that level anyway? the compiler probably wouldn't beat an eyebrow.  It's the inner code you've gota worry about.

January 13, 2004
davepermen wrote:

> In article <bu0i1p$21m1$2@digitaldaemon.com>, J Anderson says...
> 
>>But you can't extend that singleton.
>>
> 
> hm? show me how to extend a normal one?
> 
> anyways, i don't use singletons myself at all. they are 100% useless imho

interface FileSystem {
   File openFile(char[] fileName);
   char[][] getFileList();
}

class ZipFileSystem : FileSystem {
   ...
}

class FtpFileSystem : FileSystem {
   ...
}

class PhysicalFileSystem : FileSystem {
   // This could reasonably be a singleton.
}

A singleton implemented as a module can't be extended, sure, but more importantly, they can't implement an interface.

 -- andy
« First   ‹ Prev
1 2 3