DIP69 - Implement scope for escape proof references
via Digitalmars-d
digitalmars-d at puremagic.com
Mon Dec 15 03:34:13 PST 2014
On Monday, 15 December 2014 at 06:12:05 UTC, Walter Bright wrote:
> On 12/14/2014 7:41 PM, Dicebot wrote:
>> Being forced to duplicate every single function in two flavors
>> to actually make
>> scope system usable? This is as much critical as it can be.
>
> C++ seems to do fine without it for const. It's a convenience
> feature.
>
It's more than that. It has the potential (well, could have) to
be used for type erasure, which is a useful and worthwhile
concept by itself.
>> I know and this is why I am leaning toward it being qualifier
>> despite all
>> related issues.
>
> That would be a truly massive change to D, and I'm not at all
> sure it would be worth it. We've (i.e. Kenji) have been fixing
> bugs with inout for years, and idea that had seemed
> straightforward.
To be honest, I think one reason for those bugs is the awkward
implementation. I had a look at mtype.c to see how difficult it
would be to add another type modifier. It's no fun - the current
implementation requires a dozen groups of helper functions to be
written for every possible combination of type modifiers.
Therefore there are helpers like `makeConst`, `makeImmutable`,
`makeShared`, `makeSharedConst`, `makeWild` (this is `inout`),
`makeWildConst`, `makeSharedWild`, `makeSharedWildConst`, and
`makeMutable`. There are also some monster switch statements in
the same fashion.
No wonder this is error prone. I suspect that with a cleaner
implementation most of these problems will go away.
More information about the Digitalmars-d
mailing list