Re: [scala-language] The cake’s problem, dotty des ign and the approach to modularity.
Rex Kerr <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <CAP_xLa2QokmL7cxTukE69ZFvNf5QcNNuAw6MTqtvyta_Tjd3Kw@mail.gmail.com> |
On Wed, Jun 17, 2015 at 7:58 PM, Shelby <[email protected]> wrote: > Apologies I realized my myopia. If the call site is receiving a manifest > of types at runtime, then it can't know which types to compile into > match-case boilerplate at compile time. Thus we still need some sort of > vtable. > Yes, I was about to comment that you were just reinventing a vtable. > > But why can't we make a vtable for types that is global and thus not tied > to each instance of a type, a.k.a. not virtual inheritance nor subclassing? > That's approximately how it works already (unless you allow monkeypatching). The vtable for each type is global, and the instance only contains a pointer to the vtable which doubles as the way to perform run-time type identification. (Or, at least, this is one way to implement it.) If you're suggesting to rip the vtable pointers out of the objects so you need to mirror your data and dispatching data structures for every operation--well, yes, you could do that. But the key of OO is that you don't need to; the information you need is carried along locally. This is vastly more convenient, so you need to have a good reason for separating the two. And there may be such a reason: if you don't lose track of your types at compile-time, you don't need to carry along a pointer to the vtable at runtime. (This is true in C++, incidentally--only virtual methods are in the vtable.) Regarding squares and rectangles--doing it the way you stated violates LSP. That there are oodles of OO tutorials that violate LSP with their very first example is depressing, though, and in a way is one of the most damning indictments of OO. (Or maybe it's just a case of poor naming: real objects gain and lose properties willy-nilly, and our names for the various groupings violate LSP like crazy. --Rex -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.