Real-World Functional Programming: Chapters 1 & 2

We had a great first meeting to discuss the first two chapters of our new book, Real-World Functional Programming. As one might expect, these chapters were largely introductory but did get into some pretty deep discussion.

Chapter 1 started out with the elevator pitch for functional programming: by specifying the “what” instead of the “how,” you end up with more readable, reliable, and maintainable code. From an implementation standpoint, you end up constructing programs by composing expressions instead of series of statements. What is an expression, you might ask? The best definition we could come up with is “something you can assign to a variable,” which seemed to click for everyone.

One of the first questions that came up is also one of the most important while diving into a new programming paradigm: how is this different from any other abstraction? At the end of the day F# and C# both compile down to imperative IL, so what’s the point of this extra complexity? I expect we’ll get a more complete answer as we move through the book, but to start out I tried to argue that it’s simply another approach to abstraction that is often simpler than object-oriented alternatives. For example, the Template Method Pattern is largely unnecessary in functional languages because varying behaviors within an algorithm are just passed into a method as functions instead of implemented in subclasses.

We also discussed the value of having functional libraries at our disposal. In addition to System.Linq, we discussed Jon Skeet’s EduLinq and MoreLinq, as well as System.Interactive (Ix) from Microsoft’s Reactive Extensions project. Most functional introductions use projection and filtering examples, but an example of grouping really seemed to resonate with the group as something that’s complicated enough to find real value in a functional abstraction.

We finished our discussion of Chapter 1 by discussing FP in relation to other object-oriented techniques, which can be summarized in one sentence:

Functional programming is dependency injection one method at a time.

We were short on time, so we breezed through Chapter 2 rather quickly. Which is fine because we’ll see all of this material again throughout the rest of the book. Those topics included:

  • Immutable data structures
  • Recursion and recursive data structures (F# list)
  • Expressions vs statements
  • Functions as values and higher-order functions
  • Discriminated unions
  • Pattern matching
  • Units of measure

One point of confusion was the section on “language-oriented programming,” which seemed to suggest that you should use the language to make your program more readable. No kidding! There are certainly opportunities for DSLs and fluent interfaces in a functional context, but I wasn’t quite sold on this point.

So far everyone seems pleased with the book and we’re looking forward to getting into some real code. Next up are Chapters 3 & 4 for Tuesday, October 18th.

Book club is held at Roasters Coffee House in Hiawatha on the third Tuesday of every month at 7pm.

This entry was posted in Book Club. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *