Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you suggest any good intro to Scala philosophy and programs design?

Tags:

scala

In Java and C++ designing program's objects hierarchy is pretty obvious. But beginning Scala I found myself difficult to decide what classes to define to better employ Scala's syntactic sugar facilities (an even idealess about how should I design for better performance). Any good readings on this question?

like image 631
Ivan Avatar asked Aug 31 '10 23:08

Ivan


1 Answers

I have read 4 books on Scala, but I have not found what you are asking for. I guess you have read "Programming in Scala" by Odersky (Artima) already. If not, this is a link to the on-line version:

http://www.docstoc.com/docs/8692868/Programming-In-Scala

This book gives many examples how to construct object-oriented models in Scala, but all examples are very small in number of classes. I do not know of any book that will teach you how to structure large scale systems using Scala.

  • Imperative object-orientation has been around since Smalltalk, so we know a lot about this paradigm.
  • Functional object-orientation on the other hand, is a rather new concept, so in a few years I expect books describing large scale FOO systems to appear. Anyway, I think that the PiS book gives you a pretty good picture how you can put together the basic building blocks of a system, like Factory pattern, how to replace the Strategy pattern with function literals and so on.

One thing that Viktor Klang once told me (and something I really agree upon) is that one difference between C++/Java and Scala OO is that you define a lot more (smaller) classes when you use Scala. Why? Because you can! The syntactic sugar for the case class result in a very small penalty for defining a class, both in typing and in readability of the code. And as you know, many small classes usually means better OO (fewer bugs) but worse performance.

One other thing I have noticed is that I use the factory pattern a lot more when dealing with immutable objects, since all "changes" of an instance results in creating a new instance. Thank God for the copy() method on the case class. This method makes the factory methods a lot shorter.

I do not know if this helped you at all, but I think this subject is very interesting myself, and I too await more literature on this subject. Cheers!

like image 168
olle kullberg Avatar answered Oct 07 '22 10:10

olle kullberg