Transitive const sucks
Bruce Adams
tortoise_74 at yeah.who.co.uk
Wed Sep 12 12:02:33 PDT 2007
Carsten Sørensen Wrote:
> Alex Burton wrote:
> > While const is being reexamined....
> >
> > I create an interface :
> >
> > interface Server
> > {
> > Data getData() const;
> > };
>
> Hello, world! I'm fairly new to the world of D, but a minor detail like
> that has never stopped me from butting in so far ;) I'm sorry if any of
> my points have been made before, but I don't really feel like trawling
> through all 50.000 posts (although I have made an effort to dig into the
> more recent ones)
>
> First of all, I think specifying an interface method to be const is bad
> practice. The interface is assuming things about a possible
> implementation that is really not its business. As you describe, this
> will hinder your implementation.
>
> I understand you're not able to specify your particular getData()
> implementation as const due to const's transitivity, but as far as I'm
> concerned them's the breaks. I'm a bit of a const purist, sorry.
>
> What I would like to see regarding const and interfaces, is that the
> _implementation_ should be able to guarantee const-correctness even if
> the interface doesn't, much like covariant return types. The
> implementation should be free to guarantee more than its interface. That
> doesn't help you though...
>
>
> Best regards,
> Carsten Sørensen
Someone correct me if I'm wrong but I thought D doesn't / wasn't going to support overloading methods on whether they are const or not. So this part of the discussion is almost moot.
Bruce.
More information about the Digitalmars-d
mailing list