Transitive const sucks
Carsten Sørensen
cso at rift.dk
Wed Sep 12 11:46:08 PDT 2007
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
More information about the Digitalmars-d
mailing list