qunfeng wang wrote:Hi Author,
I took the coursera course Functional Programming Principles in Scala by professor Martin Odersky. It's a great learning experience. In the course, professor Martin Odersky mainly focused on functional programming. I'm wondering which paradigm to choose in the real world programming with Scala.
Thanks,
Qunfeng
You should choose the paradigm that works for the problem you're solving. A lot of teaching/training we do in Scala is *forced* to be functional style, because we assume students are unfamiliar/uncomfortable with functional-style and the only way to really learn is to force them to immerse themselves.
You will notice that Scala has more powerful OO features than
Java (traits, self types, early initializers, etc.) and also pulls in much of the functional concepts. It is a blend, and therefore in *practice* most of my code is blended as well. In my current project, I find myself using 3 paradigms:
Akka/Actors for the backend server, OO for exposing interfaces and Services, Functional Programming style inside Play for munging data around and sending it to the client.
When it comes down to it, each paradigm has different strengths, and is suited to different tasks. If you use the right paradigm in the right spot, it will serve you well.
For example, one frustration I have with a lot of FP languages is the lack of namespacing and "module systems". Scala actually provides a pretty nifty way to namespace functional code -> Objects. You can even extend full-on packages if you use nested objects/classes in traits. Some of the most advanced FP users in Scala are doing wonders with its OO system for packaging their software:
Bake Me A Cake - Precog.