Coming back, Unique, opDot and whatever else

Jacob Carlborg doob at me.com
Thu Jan 16 23:34:57 PST 2014


On 2014-01-17 02:12, Stanislav Blinov wrote:
> Hello everyone! It's been a long time since I last posted here, I've
> been away from all things D, only being able to take an occasional peek
> from time to time. It's so good to be back. I'm now finding a bit of
> time to commit to learn D, more relearn as it would seem.
>
> I've started my rediscoveries with exploring of concurrency,
> parallelism, threading in D, and after some time I found myself thinking
> "I need a unique encapsulator". Don't ask why, I may not even be able to
> answer it in a month. But that helped me solve some problems before in
> C++, so I thought why not try it here? In a couple of page views I came
> upon std.typecons and its Unique type. And I thought "why that is
> exactly what I want!". And it was, too. But after taking a closer look
> at its general implementation I just couldn't help myself but think
> "well, it seems it was done in a hurry, never finished, left as it was
> because this of that and whatnot". I mean, those sparse comments, things
> like "doesn't work yet", etc... I thought well, since I'm learning the
> language again, why not make it an exercise and fill those blanks? It'd
> certainly help me, because it would improve the abstraction I'm using,
> and because it's a learning experience.
>
> So, here's what I came up with for now:
>
> http://codepad.org/S4TfIdxc
>
> Granted, not a complete implementation, keeping not very far from the
> original. But right now I think it's a good time to ask you guys what do
> you think? Where have I went wrong, what did I do incorrectly, what
> potential issues can you spot in this? I mean, I'm not asking about
> using opDot(), which, as I understand it, could be going away anytime
> now. At least I think I managed to fill in most of the "blanks" of the
> current implementation while keeping (almost?) to the same interface. In
> short, please destroy this with Big Fat Phazerz so I could take the
> remaining ashes and contemplate on the next iteration :)

opDot has been replaced with opDispatch [1] and "alias this" [2]. Why 
can't @safe be used, can you use @trusted instead? You should probably 
use template constraints for "createUnique" as well. As for coding 
style, especially if you're aiming for including in Phobos:

* Function names never start with underscore and always starts with a 
lowercase letter

* I would prefer the same for instance variables as well, but I know 
there are several cases in Phobos where instance variables starts with 
an underscore

[1] http://dlang.org/operatoroverloading.html#Dispatch
[2] http://dlang.org/class.html#AliasThis

-- 
/Jacob Carlborg


More information about the Digitalmars-d-announce mailing list