From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Simple example on interfaces
Date: Tue, 26 Jan 2021 21:36:53 -0600 [thread overview]
Message-ID: <ruqn4m$s4e$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: rumtg6$j94$1@dont-email.me
"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message
news:rumtg6$j94$1@dont-email.me...
> On 1/25/21 5:08 PM, Mario Blunk wrote:
>> I'm trying to solve a problem of multiple inheritance. It seems to me
>> that an interface could be the solution although the interface is still a
>> mystery for me.
>
> "IMHO, Interfaces are worthless."
> Randy Brukardt
To qualify that a bit, they're worthless to me (and I suspect, most people).
For me, at least, OOP's benefits are mainly found in implementation
inheritance, which is not available for Interfaces. You have to use abstract
types to get those benefits.
For a single program, an interface doesn't buy anything, because it is very
unlikely that you'll have more than one implementation of the interface in
use. (Think the queue interface in Annex A.) So using dispatching just adds
complication but no benefit; most likely you'll statically bind everything
anyway.
Which pretty much leaves reusuable code. Here, dispatching probably does
have some benefit. But you can get similar benefits from generic units with
formal derived type parameters. The problem is that interface dispatching is
quite expensive (not just the indexing of single inheritance dispatching,
but also some sort of lookup of the appropriate table). Whereas the generic
solution does most of the binding at compile-time.
It may be my optimizer guru background, but indirect calls are pretty much
unoptimizable. Ergo, the cost of dispatching is even worse than it appears
on the surface, given that valuable optimizations like inlining, partial
evaluation (currying), and all of the things that they enable aren't
possible. So if the code performance matters, ultimately the interfaces will
have to go. (Of course, if it *doesn't* matter, one shouldn't be warping a
design for performance reasons. But it is *hard* to get rid of interfaces
that are too expensive, so I think it makes most sense to be sparing with
their use.)
Ultimately, I think one should only use interfaces IFF there is a clear
reuse case where the substantial cost of dispatching is not a concern. For
me, that is approximately never, but of course your mileage may vary.
Randy.
next prev parent reply other threads:[~2021-01-27 3:36 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 16:08 Simple example on interfaces Mario Blunk
2021-01-25 16:41 ` Dmitry A. Kazakov
2021-01-25 17:51 ` Mario Blunk
2021-01-25 22:06 ` Dmitry A. Kazakov
2021-01-26 7:33 ` G.B.
2021-01-26 8:07 ` Dmitry A. Kazakov
2021-01-26 8:17 ` Mario Blunk
2021-01-26 8:55 ` Dmitry A. Kazakov
2021-01-26 9:37 ` J-P. Rosen
2021-01-26 10:25 ` Dmitry A. Kazakov
2021-01-26 11:15 ` AdaMagica
2021-01-26 11:53 ` Dmitry A. Kazakov
2021-01-26 16:46 ` AdaMagica
2021-01-26 19:44 ` Dmitry A. Kazakov
2021-01-26 20:04 ` Shark8
2021-01-26 21:34 ` Dmitry A. Kazakov
2021-01-27 3:11 ` Randy Brukardt
2021-01-27 22:51 ` Shark8
2021-01-30 8:33 ` Randy Brukardt
2021-01-27 3:09 ` Randy Brukardt
2021-01-27 8:05 ` Dmitry A. Kazakov
2021-01-26 10:02 ` Stephen Leake
2021-01-25 17:00 ` Jeffrey R. Carter
2021-01-27 1:48 ` philip...@gmail.com
2021-01-27 8:06 ` Dmitry A. Kazakov
2021-01-27 3:36 ` Randy Brukardt [this message]
2021-01-27 23:04 ` Shark8
2021-01-25 19:05 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox