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_xLa3uB=uzTVwk3O6-XubhenSUfZg0AHJ0JyjeL+DV88Ydbw@mail.gmail.com> |
On Tue, Jun 16, 2015 at 12:53 AM, Shelby <[email protected]> wrote: > > Am I homing in on the generative essence? Nobody has been able to > succinctly and concretely explain to me why I need Scala and not Haskell > disregarding the Java compatibility or lazy by default differences. > > This is kind of off-topic for the original thread, but: Inheritance provides a way to automatically assemble chains of mutually-dependent functionality without having to worry about the details. It's a somewhat fragile solution, but nothing other than extremely late binding via (something computationally equivalent to) vtable lookup really does the trick. So if you have, for example, a bunch of drawable windowing components with all sorts of elaboration therein, you can still have a xs: List[Component] and get something sensible with xs.sortBy(_.zDepth).foreach(draw). It's not the only way to solve the problem at all, since any problem you can solve with inheritance you can also solve with composition, but with OO it's really easy to make most everything overridable so you have to go back and modify your library less often. (Unfortunately, due to a lack of a really robust way to specify logical dependencies, you often need the source code to the library anyway so you know what is safe to override alone, what must be overridden in pairs, etc.). It also doesn't play terribly nicely with immutability because you lose track of which constructor you ought to use. The whole _point_ of OO is to lose track so you don't have to worry about it, but then when you need to worry...well...you're stuck. A classic example is List(new A, new A{ override def foo = "different" }).map(x.asCapitalA) If `asCapitalA` has mutating side-effects, you retain the distinct `foo` behavior. If, in contrast, it creates a new immutable A, your unique `foo` behavior is lost. So you might just reject OO as a tool that helps you most in a situation that you avoid anyway. But that doesn't mean that there are equivalently easy functional or monadic or other ways to do the same thing. Everything else is harder. --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.