Real World Functional Programming

Author: Tomas Petricek and Jon Skeet
Publisher: Manning, 2009
Pages: 500
ISBN: 978-1933988924
Aimed at: Advanced programmers
Rating: 4.5
Pros: Wide-ranging discussion of functional programming
Cons: Often difficult to read
Reviewed by: Mike James

The subtitle of this book is "with examples in F# and C#" and clearly this is a novel idea. Unfortunately it is one that is unlikely to work for many readers. The problem is that on a continuum of functional languages neither F# nor C# are strictly functional. F# is more functional than C# but even so there are purists who will discount its credentials.

Trying to explain functional ideas using a familiar language contrasted with a more appropriate language like F# might seem to be a good idea but it runs the risk of simply confusing the beginner. This is sadly what happens here, mainly because the main author tries to cover everything in the same sentence and doesn't appreciate how difficult it is for the functional novice to see the functions for the lambdas. This might partly be a desire to impress the reader with just how complete and impressive a langauge F# is. The attempt to showcase the language does little to help understanding.

The second problem is that the C# examples are often strained and generally involve niche areas of C# such as Linq or XAML which are arguably not really part of the language at all.

There are also places were the explanations are less than perfect. You might understand what is going on but only if you already know about functional programming. For example, on page 39 an example of converting a C# program from mutable to imutable objects is given with the change being brought about by simply introducing new variables every time a change is needed giving:

 int res0 = GetInitialValue();
int res1 = res0+ReadInt32();
int res2 = res1*ReadInt32();
WriteInt32(res2);

The book then says

"The key difference is that in the second example, we didn't use the assignment operator (written as an equal sign in C#)."

At this point the beginner might well just give up as clearly the equal sign is used three times in the example. I suppose that the author was trying to make the distinction between initialisation and assignment - both signified by an equals sign in C# - but couldn't find a clear way to express the idea. There are other places where the descriptions are just ambiguous enough to confuse and while the example given is extreme its not uncharacteristic of the style.

You might conclude that I didn't like the book but in fact I got quite a lot of pleasure from reading it. If you mostly ignore the C# examples and concentrate on the F# then what you have is an advanced book on using F#. Part 2 of the book is a good discussion of a range of functional techniques - values, lists, debugging, designing and behaviour-centric programs. Part 3 of the book deals with advanced F# - turning values into objects, efficiency of data structures, refactoring and  sequence expressions. The final part provides some good examples of F# and functional approaches in action - asynchronous and data driven programming, parallel functional programs, creating composable functional libraries and reactive functional programming.

I think that this would have been a better book if it had simply focused on advanced F# but if you are up to the challenge of reading it then you will get quite a lot from this book. It's for experts only and experts who aren't going to be confused by swapping between F# and C# and a fairly difficult style of presentation. Recommended but with a caution.

 

 

 

 

Last Updated ( Sunday, 14 February 2010 )
 
 

   
RSS feed of book reviews only
I Programmer Book Reviews
RSS feed of all content
I Programmer Book Reviews
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.