In the Scala actor examples I have seen where a parameterless message is sent to an actor (such as this), case classes (or case objects) have been created and then used as messages. Symbols work just as well and look a bit neater and, after reading a book on Erlang, seem more natural. I assume that symbol equality would work for remote actors.
For messages with parameters case classes would be the obvious choice, so perhaps consistency between message types is one issue?
Are there any reasons to go for either approach?
I don’t think that
Symbols are a substitute for usingcaseclasses. In fact, I’m not entirely sure what useSymbolis at all, given it lacks the power of symbols in other languages (e.g. Ruby, Smalltalk) – it’s just an interned String.For example, in the standard auction example, it’s difficult to see how you would represent the complexity of a bid / offer using symbols alone.
As for
caseobjects, I also believe that these are preferable to symbols. For example, they can be instances oftraits etc, and hence supply functionality.