2014-08-25

Book Review - Functional Programming in Scala (Part 1)

So I've worked my way through the first part of Functional Programming in Scala, and am restarting the section.

The first section of the book shows some of the building blocks of FP, how to loop functionally, pass functions as values, functional data structures, error handling, lazy-ness versus strictness, and functional state. It provides a fairly step by step introduction and should be workable for anyone with programming experience, for someone with at least some Scala these sections will be very approachable.

After working my way through the first part of the book without looking at the github project with the answers, I feel like the book has some great strengths and one or two drawbacks.

The exercises are great, they really push the reader to play with and understand the concepts behind the sections leading up to them. I decided to work my way back through the first part, and the associated exercises. This time I'm using the structure provided by the github project and checking my results against the official answers.

Through the first pass I felt like I wasn't really sure I had some of the assignments "right", in that there is often minimal examples of the use of the code. I feel like providing at least some of the answers and discussing the reasoning behind choices made would have been useful. For example, my  solutions to several exercises put the logic for the sub-types of several data structures into the implementation of the functions in the sub-types, whereas the book put them in the super-type and used pattern matching to decide what behavior to apply. I brought this up on the #scala IRC channel and the explanation I got was that, in FP, the sub-types of a sealed algebraic data type should be considered alternate constructors more than actual types. that made a lot of sense

I've started writing unit tests in ScalaTest for the exercises to help me understand and document the steps. I'm posting the tests to a fork, in case that's useful to anyone else.

It looks like I'll be moving back to the Toronto area in the next little while, I may try to setup a study group for the book if there's any interest.


No comments :