Re: Singleton in Action?

2019-02-06 Thread Ron Tarrant via Digitalmars-d-learn
On Monday, 4 February 2019 at 19:23:26 UTC, Jacob Carlborg wrote: You can call it with or without parentheses. It applies to all functions that don't take any arguments or functions taking a single argument and are called using UFCS [1]. [1] https://dlang.org/spec/function.html#pseudo-member

Re: Singleton in Action?

2019-02-05 Thread kdevel via Digitalmars-d-learn
On Monday, 4 February 2019 at 10:17:53 UTC, bauss wrote: On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: [...] Here's the singleton code I've been playing with: [...] static bool instantiated_; // Thread global __gshared DSingleton instance_;

Re: Singleton in Action?

2019-02-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-02-04 11:36, Ron Tarrant wrote: I've seen comments similar to this in several examples. When you say "no one else" you're personifying callers? Yes. And so this means: No caller outside the object? Which really amounts to: Since no one INside the object WILL call this() and no one

Re: Singleton in Action?

2019-02-04 Thread Alex via Digitalmars-d-learn
On Monday, 4 February 2019 at 10:36:49 UTC, Ron Tarrant wrote: On Sunday, 3 February 2019 at 18:53:10 UTC, Jacob Carlborg wrote: You don't need to make it so complicated. Here's a simpler example: Excellent. Thank you. Simple is best. private __gshared auto instance_ = new

Re: Singleton in Action?

2019-02-04 Thread Ron Tarrant via Digitalmars-d-learn
On Sunday, 3 February 2019 at 22:25:18 UTC, Dejan Lekic wrote: I strongly suggest you find the thread started by Andrej Mitrovic many years ago. He compared several implementations of (thread-safe) singletons. I it an extremely helpful stuff, IMHO. Thanks. I'll see if I can find it.

Re: Singleton in Action?

2019-02-04 Thread Ron Tarrant via Digitalmars-d-learn
On Sunday, 3 February 2019 at 18:53:10 UTC, Jacob Carlborg wrote: You don't need to make it so complicated. Here's a simpler example: Excellent. Thank you. Simple is best. private __gshared auto instance_ = new DSingleton; My understanding is that in D, this line effectively says:

Re: Singleton in Action?

2019-02-04 Thread Ron Tarrant via Digitalmars-d-learn
On Sunday, 3 February 2019 at 15:33:15 UTC, Russel Winder wrote: There is a lot of good stuff (both positive and negative) on Singleton here, but there is also a bit of prejudice and bigotry. Many of the links are worth looking through.

Re: Singleton in Action?

2019-02-04 Thread bauss via Digitalmars-d-learn
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. Can someone show me a code example

Re: Singleton in Action?

2019-02-04 Thread Kagamin via Digitalmars-d-learn
On Sunday, 3 February 2019 at 14:42:13 UTC, Ron Tarrant wrote: This morning I was Googling "singleton replacement" and someone on another forum said Factory would do the job. Anyone have thoughts on that? It's usually replaced with inversion of control: the service instance is passed as an

Re: Singleton in Action?

2019-02-03 Thread Dejan Lekic via Digitalmars-d-learn
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. Can someone show me a code example

Re: Singleton in Action?

2019-02-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-02-02 17:56, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. Can someone show me a code example for how one would actually

Re: Singleton in Action?

2019-02-03 Thread Russel Winder via Digitalmars-d-learn
On Sun, 2019-02-03 at 14:42 +, Ron Tarrant via Digitalmars-d-learn wrote: > On Sunday, 3 February 2019 at 10:28:51 UTC, Alex wrote: > > > Isn't deriving a singleton even eviler as having one? ;) > > Perhaps this was meant as rhetoric, but I think you may be right. > > This morning I was

Re: Singleton in Action?

2019-02-03 Thread Ron Tarrant via Digitalmars-d-learn
On Sunday, 3 February 2019 at 10:28:51 UTC, Alex wrote: Isn't deriving a singleton even eviler as having one? ;) Perhaps this was meant as rhetoric, but I think you may be right. This morning I was Googling "singleton replacement" and someone on another forum said Factory would do the job.

Re: Singleton in Action?

2019-02-03 Thread Ron Tarrant via Digitalmars-d-learn
On Sunday, 3 February 2019 at 11:17:38 UTC, Jonathan M Davis wrote: I don't recall std.thread ever existing, and std.c.time hasn't been around for a while. Thread is in core.thread, and all of the C bindings for standard C and OS APIs are supposed to be in druntime. So, the equivalent to C's

Re: Singleton in Action?

2019-02-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 3, 2019 2:41:48 AM MST Ron Tarrant via Digitalmars-d- learn wrote: > On Saturday, 2 February 2019 at 19:40:25 UTC, Andre Pany wrote: > > https://rosettacode.org/wiki/Singleton#D > > Do you know if this is for a current version of D? The compiler > is choking on the import

Re: Singleton in Action?

2019-02-03 Thread Alex via Digitalmars-d-learn
On Sunday, 3 February 2019 at 09:46:20 UTC, Ron Tarrant wrote: On Saturday, 2 February 2019 at 20:30:15 UTC, Neia Neutuladh wrote: And consider putting the class in its own source file. Yes, by all means. Speaking of which... Considering the nature of a singleton such the one in the top

Re: Singleton in Action?

2019-02-03 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 2 February 2019 at 20:30:15 UTC, Neia Neutuladh wrote: And consider putting the class in its own source file. Yes, by all means. Speaking of which... Considering the nature of a singleton such the one in the top post, I can't see it being possible to use one as a base class

Re: Singleton in Action?

2019-02-03 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 2 February 2019 at 19:40:25 UTC, Andre Pany wrote: https://rosettacode.org/wiki/Singleton#D Do you know if this is for a current version of D? The compiler is choking on the import statements, complaining that it can't read std/thread.d and std/c/time.d

Re: Singleton in Action?

2019-02-03 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 2 February 2019 at 19:40:25 UTC, Andre Pany wrote: I found here an example: https://rosettacode.org/wiki/Singleton#D Kind regards Andre Thanks, Andre. Exactly what I was hoping for.

Re: Singleton in Action?

2019-02-02 Thread Tony via Digitalmars-d-learn
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: So, my big question is, do I instantiate like this: DSingleton singleton = new DSingleton; Or like this: DSingleton singleton = singleton.get(); And subsequent calls would be...? The same? Using get() only? This seems to be

Re: Singleton in Action?

2019-02-02 Thread Norm via Digitalmars-d-learn
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. Can someone show me a code example

Re: Singleton in Action?

2019-02-02 Thread Norm via Digitalmars-d-learn
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. [...] If you haven't already been

Re: Singleton in Action?

2019-02-02 Thread angel via Digitalmars-d-learn
On Saturday, 2 February 2019 at 19:23:58 UTC, Ron Tarrant wrote: Thanks for the replies, fellow programmers. (generic, unisex, PC, and all-encompassing) If I could trouble someone for a complete working example so I have something to study, that would be excellent. I think that's what you

Re: Singleton in Action?

2019-02-02 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 02 Feb 2019 17:34:11 +, Eugene Wissner wrote: > For creation get() should be always used, since it is the most > convenient way to ensure that there is really only one instance of the > singleton. Just make this() private, so only you can create new > instances: > > private this() > {

Re: Singleton in Action?

2019-02-02 Thread Andre Pany via Digitalmars-d-learn
On Saturday, 2 February 2019 at 19:23:58 UTC, Ron Tarrant wrote: Thanks for the replies, fellow programmers. (generic, unisex, PC, and all-encompassing) If I could trouble someone for a complete working example so I have something to study, that would be excellent. I found here an example:

Re: Singleton in Action?

2019-02-02 Thread Ron Tarrant via Digitalmars-d-learn
Thanks for the replies, fellow programmers. (generic, unisex, PC, and all-encompassing) If I could trouble someone for a complete working example so I have something to study, that would be excellent.

Re: Singleton in Action?

2019-02-02 Thread Eugene Wissner via Digitalmars-d-learn
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. Can someone show me a code example

Re: Singleton in Action?

2019-02-02 Thread Russel Winder via Digitalmars-d-learn
On Sat, 2019-02-02 at 16:56 +, Ron Tarrant via Digitalmars-d-learn wrote: > Hi guys, and gals. > I ran into another snag this morning while trying to implement a > singleton. I found all kinds of examples of singleton > definitions, but nothing about how to put them into practice.

Singleton in Action?

2019-02-02 Thread Ron Tarrant via Digitalmars-d-learn
Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. Can someone show me a code example for how one would actually use a singleton pattern in D? When I