D's greatest mistakes
Michel Fortin
michel.fortin at michelf.com
Mon Nov 29 10:56:09 PST 2010
On 2010-11-29 13:08:54 -0500, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> said:
> On 11/29/10 10:54 AM, Michel Fortin wrote:
>> The biggest problem I see is with generic programming. Say I pass
>> Rebindable!(const C) as a template argument, then the template wants to
>> make it const: should it become const(Rebindable!(const C)), or will
>> this be resolved to const(C)?
>
> const should follow normal logic, and const(Rebindable!(const C))
> should behave as expected.
I think we agree on that.
The problem is that you now have two distinct types to mean a const
reference to a const object. You have "const(Rebindable!(const C))" and
const "const(C)", whichever you get depends on where the type comes
from. Type equality won't work between the two, and you won't be able
to concatenate two arrays one containing rebindables and the other (for
instance). It's like a special case in the type system where constness
is implemented using a template while the rest is a language feature,
it it thus behave differently and code that might work for one
implementation of constness might break with the other, because the
don't play with each other very well. Add immutable to the mix and it
becomes even stranger.
For instance, here's a tricky question: should Unqual!(const C) give
you a const(C), a Rebindable!(const C), or simply C? Now, what should
const(Unqual!(immutable C)) give you?
I know most of the problems are going to be edge cases most people
don't care about. But on the whole, creating a fragile and complex
solution to work around the lack of an inspiring syntax seems rather
silly. I would immensely prefer having an ugly syntax that works as it
should. If it's too ugly, we can still hide that syntax behind
Rebindable by defining it as a simple type alias.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list