DIP 1003 Formal Review
MysticZach via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 15 21:43:02 PDT 2017
On Tuesday, 16 May 2017 at 03:44:54 UTC, MysticZach wrote:
> It seems to me that the compiler could detect a presence or
> lack of a body simply by the presence or absence of any
> statement after the contracts, i.e.,
>
> interface D {
> // fun is implicitly overridable here
> int fun() {
> in assert(...);
> }
> }
>
> Also, does a final function with contracts, but no body, make
> any sense? What's the use case?
>
> Even if there were some use case for it, I can think of two
> solutions. One is to keep and require the current syntax for an
> interface function without a body. This is the natural way to
> install contracts anyway, for a function with no body.
>
> The other solution is to recommend the addition of an empty
> statement, for an empty final function, e.g.:
>
> // final
> int fun() {
> in assert(...);
> {}
> }
>
> Considering what Jonathan said about how he never uses
> contracts because they're so bulky, might it not be worth it to
> solve the interface problem in either of the above two ways?
I should have said *three* ways, because it's quite possible to
conclude that there will never be a use case for a final function
in an interface to have contracts, but no body, and therefore
assume that contracts plus a lack of statements --> an
overridable function.
More information about the Digitalmars-d
mailing list