Is it possible to request a code review?

IM 3di at gm.com
Thu Dec 14 06:28:11 UTC 2017


On Thursday, 14 December 2017 at 04:12:33 UTC, rikki cattermole 
wrote:
> On 14/12/2017 3:57 AM, IM wrote:
>
> snip
>
>>      - Is this the idiomatic way to define a singleton in D?: 
>> https://gitlab.com/3d_immortal/libdtasks/blob/master/src/tasks/TaskSystem.d#L24.
>
> You say singleton I think wrong.
>
> Use free-functions and globals instead.
>
> Singletons are always a code smell that OOP based languages 
> like to say are a 'good thing'.
>
> e.g.
>
> module taskmgr;
> import task;
>
> private __gshared {
> 	Task[] tasks;
> }
>
> Task[] getTasks() {
> 	return tasks;
> }
>
> void clearTasks() {
> 	tasks = null;
> }
>
> void addTask(Task t) {
> 	tasks ~= t;
> }

Sure, that works too, Thanks. However, we could leave the debate 
about the pros and cons of singletons for another day. That's not 
what my question was about though.


More information about the Digitalmars-d mailing list