retard wrote:
Mon, 08 Feb 2010 11:34:10 -0800, Andrei Alexandrescu wrote:
I know of Scala's traits. They are different from overridable methods in
interfaces, which are not nearly interesting enough to bring fame and
fortune to anyone.
I apologize for being so rude.
That's a nice surprise (what about the backlog? :o)). Just a note, to me
apologizing entails I plan to not repeat whatever it is I'm apologizing for.
If I read the proposal correctly, traits
are its generalization:
interface Stack(T)
{
void push(T);
void pop();
@property ref T top();
@property bool empty();
T belowTop()
{
auto t = top;
pop();
auto result = top;
push(t);
return result;
}
}
vs
trait Stack[T]
{
def push(t: T): Unit
def pop: Unit
def top: T // do not know how to port properties
def empty: Boolean
def belowTop: T
{
val t = top
pop
val result = top
push(t)
result
}
}
But with these kind of features D's interfaces are getting closer and
closer to traits. What's missing? The linearization system, type members,
and member variables inside interfaces. OTOH Scala is lacking the
contract system.
Traits indeed offer more than interfaces. We're looking at sensible
things to do within the time constraints we're having; traits would be a
major effort, whereas methods in interfaces are just eliminating an
artificial limitation. Traits are a possible addition to D3.
Andrei