- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Should the linearization order be changed to put the derived class first?
Hello,
The way I understand things right now, if I have a hierarchy:
trait A
trait B
class C extends B with A
The linearization order is C->A->B. This makes intuitive sense, but I
often find myself wanting to write code like
trait A {
def things: List[Int]
}
trait B {
abstract override def things = 7 :: super.things
}
val a = new B {
def x = List(1, 2, 3)
}
where a.x is now List(7, 1, 2, 3)
In fact, maybe I'm doing things wrong, but I actually want to do this
even more than I want to use regular mixins. As far as I can tell, the
only reason this is not possible is because the derived class comes
first in the linearization order. So what I do is manually change the
linearization order:
trait OneTwoThree extends A {
def x = List(1, 2, 3)
}
val a = new OneTwoThree with B
And this is not so bad, other than that it splits up my code in a way
that is different than how I feel the code should logically be
organized.
So what I'd like to know is,
1) Is my analysis of the problem correct?
2) If so, is there any chance that the linearization order could be change?
Best,
Owen









