Re: How to use globals correctly?

2018-03-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 06, 2018 11:52:05 H. S. Teoh via Digitalmars-d-learn wrote: > On Tue, Mar 06, 2018 at 11:46:04AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > > On Tuesday, March 06, 2018 18:34:34 bauss via Digitalmars-d-learn wrote: > [...] > > > > Singletons are always smelly code

Re: How to use globals correctly?

2018-03-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 06, 2018 at 11:46:04AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Tuesday, March 06, 2018 18:34:34 bauss via Digitalmars-d-learn wrote: [...] > > Singletons are always smelly code tbh. > > > > Especially in D with thread-local storage. > > > > I can't think of a

Re: How to use globals correctly?

2018-03-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 06, 2018 18:34:34 bauss via Digitalmars-d-learn wrote: > On Monday, 5 March 2018 at 19:51:33 UTC, Steven Schveighoffer > > wrote: > > On 3/5/18 2:25 PM, Marc wrote: > >> Can __gshared be used instead of static in the singleton > >> pattern? I, comming from C++, ignorantly, have

Re: How to use globals correctly?

2018-03-06 Thread bauss via Digitalmars-d-learn
On Monday, 5 March 2018 at 19:51:33 UTC, Steven Schveighoffer wrote: On 3/5/18 2:25 PM, Marc wrote: Can __gshared be used instead of static in the singleton pattern? I, comming from C++, ignorantly, have never used _gshared so I went to static instead of (being static also means

Re: How to use globals correctly?

2018-03-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/5/18 2:25 PM, Marc wrote: Can __gshared be used instead of static in the singleton pattern? I, comming from C++, ignorantly, have never used _gshared so I went to static instead of (being static also means thread-safe, as far I know)... static in D is thread safe, because it's

Re: How to use globals correctly?

2018-03-05 Thread bauss via Digitalmars-d-learn
On Monday, 5 March 2018 at 19:39:35 UTC, Robert M. Münch wrote: On 2018-03-05 18:57:01 +, Steven Schveighoffer said: If you want to have methods, shared kind of sucks. But this at least tells the type system that it's shared between threads. Why does it suck? Because your code will

Re: How to use globals correctly?

2018-03-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/5/18 2:39 PM, Robert M. Münch wrote: On 2018-03-05 18:57:01 +, Steven Schveighoffer said: On 3/5/18 1:35 PM, Robert M. Münch wrote: 1. Are myMemb1..N TLS or __gshared as well? No, they are on the heap. Only the reference is __gshared. But effectively it is __gshared, since you

Re: How to use globals correctly?

2018-03-05 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-03-05 18:57:01 +, Steven Schveighoffer said: On 3/5/18 1:35 PM, Robert M. Münch wrote: 1. Are myMemb1..N TLS or __gshared as well? No, they are on the heap. Only the reference is __gshared. But effectively it is __gshared, since you can reach those items via the global

Re: How to use globals correctly?

2018-03-05 Thread Marc via Digitalmars-d-learn
On Monday, 5 March 2018 at 18:57:01 UTC, Steven Schveighoffer wrote: On 3/5/18 1:35 PM, Robert M. Münch wrote: If I use VisualD and add a watch on myObj, I don't see anything just a "identifier myObj is undefined". Not sure if this is because of some threads running (using the D RX

Re: How to use globals correctly?

2018-03-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/5/18 1:35 PM, Robert M. Münch wrote: If I use VisualD and add a watch on myObj, I don't see anything just a "identifier myObj is undefined". Not sure if this is because of some threads running (using the D RX framework). Can't answer your visual D questions... So, some questions: 1.

How to use globals correctly?

2018-03-05 Thread Robert M. Münch via Digitalmars-d-learn
Hi, I'm feeling a bit dumb but anway... For hacking prototypes I mostly create a class to store all kind of values. Then I create one global instance of this class and use it everywhere. Pseudocode looks like this: class myClass { myMemb1; myMembN; this(){...} }