Formal optional interfaces
Paul Backus
snarwin at gmail.com
Wed Mar 6 02:00:23 UTC 2019
On Tuesday, 5 March 2019 at 20:03:30 UTC, Jacob Carlborg wrote:
> The next Objective-C integration feature that will be
> implemented will probably be support for "protocols" (this is
> what Objective-C calls "interfaces"). Objective-C protocols
> supports optional methods. To call an optional method on a
> Objective-C protocols you're supposed to do a runtime check to
> see if the object actually implements the method.
>
> This got me thinking if this needs to be supported as well.
> Regular D interfaces do not support optional methods. I asked
> on Slack how people would think about this feature and I got a
> reply mentioning Andrei's C++ talk "The Next Big Thing" [1].
> This talk includes informal optional interfaces.
>
> I see a couple of problems with informal optional and
> non-optional interfaces:
>
> [...]
Atila Neves's `concepts` library on dub [1] already addresses
most of these issues, without requiring new language features or
invasive changes to existing code.
What you propose might have been a good idea if it were part of D
from the start (or if you were designing "D 3.0"), but trying to
retrofit it now, after so much code (e.g., all of Phobos) has
already been written using the existing "informal" style, seems
like the worst of both worlds to me. It won't save us from having
to deal with the shortcomings of "informal" interfaces, because
code that uses them will still exist, but it *will* make the
language more complicated and difficult to learn, and force
programmers to waste their time dealing with incompatibilities
between "formal" and "informal" code instead of solving actual
problems.
[1] https://code.dlang.org/packages/concepts
More information about the Digitalmars-d
mailing list