Library Typedefs are fundamentally broken

Jakob Ovrum via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 19 04:43:38 PDT 2014


On Friday, 19 September 2014 at 11:14:06 UTC, Dicebot wrote:
> On Friday, 19 September 2014 at 04:44:07 UTC, Jakob Ovrum wrote:
>> On Wednesday, 17 September 2014 at 16:32:04 UTC, Dicebot wrote:
>>> On Wednesday, 17 September 2014 at 10:00:31 UTC, Jack 
>>> Applegame wrote:
>>>> You can use module name and line number as unique tag.
>>>
>>> This is exactly what I would have expected as default 
>>> behaviour. Is anyone aware why this counter appoach was used 
>>> instead?
>>
>> It's a deceivingly bad default. See the comments in the PR 
>> that introduced Typedef[1].
>>
>> [1] https://github.com/D-Programming-Language/phobos/pull/300
>
> Yes, this is a problem. But how is that possibly worse than 
> existing implementation which gives wrong results in 100% of 
> cases? file/line cookie approach has issues but it is best we 
> can get with existing language support.

`Typedef` clearly comes with a big caveat that isn't apparent 
from just reading user code. The documentation has to be read, 
and the documentation clearly states that the cookie parameter 
has to be used to get unique types. It's much less surprising to 
have it generate unique types only when explicitly given a cookie 
than having it sometimes make unique types and sometimes not 
depending on complex conditions.

Maybe `Typedef` could be neatly fixed by making it a mixin 
template?


More information about the Digitalmars-d mailing list