shouldn't override be obligatory?
Jonathan M Davis
jmdavisProg at gmail.com
Mon Mar 15 18:49:25 PDT 2010
div0 wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Jonathan M Davis wrote:
>> div0 wrote:
>>
>>> Strangely it doesn't give an error if A is an interface though.
>>
>> Interfaces aren't overridden; they're implemented. You're providing
>> functionality, not replacing it. By marking a function with override,
>> you're clearly marking that it's polymorphic and intended to be so. If
>> you force override for all cases when a function is overridden, then you
>> avoid issues where you unknowingly override a function, changing the
>> objects behavior. That's not a problem with interfaces since there's no
>> behavior to change. The problem with interfaces is when you don't
>> implement them completely, and they complain plenty when that happens.
>>
>> - Jonathan M Davis
>
> True, but using override clearly documents what you doing in that class.
> Otherwise you have to arse about looking through the interfaces to see
> if an unmarked function is an implementation, which is the same end
> result as unmarked overrides.
>
> I vote for requiring override in all cases; I think it makes things
> clearer. YMMV.
I know that that has caused problems in Java with their override attribute.
I don't want to see those in D. Unfortunately, I haven't been using Java
much lately, so I can't list the problems off the top of my head, but there
are definitely problems with using override on interface functions. As such,
I'd be highly opposed to doing so. If we wanted that, I think that it would
make far more sense to add an implements attribute for interface functions.
And on top of that, you're never going to run into a problem with a function
implementing an interface when you don't mean it to while you _are_ going to
run into problems with functions accidentally overriding other functions
(assuming that there's no check based on override). From the standpoint of
code correctness and bugs, and I see zero benefit in explicitly marking
functions which implement interfaces, while I see great benefit in having to
explicitly mark functions as overriding other functions.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list