Another tour of Scala

 
 
 
 

Explcitly Typed Self References

Viewing old version bc71322516382805f4bf5a880862719339d4a001; View Current

The Gist

Explicitly Typed Self References is, no offense, incomprehensible. However, with some help from the Scala Book, and some coding, I think I might get what to use it for.

My Interpretation

I’m not sure I fully understand when this is needed, but I have identified one instance of using it. This is essentially a way around inheritance to compose classes.

I apologize for the long example, but this is not the easiest topic to understand.

One use of ScalaTraits is to better organize your code; you can logically group code that has separate concerns in different traits. At times, however, you will always use certain traits together. Consider a very simple web application framework design:

My Thoughts on this Feature

So, we start with a convoluted description of a Graph, and then glop on loads of other Scala features until…what? Something breaks and we require arbitrary syntax to fix it? I honestly can’t figure this out at all.

However, the fact that we are required to indicate the type of something makes me think that this is one of those dark, nasty corners of static typing that its proponents don’t want you to know about until it’s too late. I’m not judging static typing, but it’s clear that this is in aid of giving info to the compiler, not the programmer.


Last Updated 08/23/2009 at 08:19:42 PM by davec

blog comments powered by Disqus