Reputation: 305
I have started experimenting with Clojure, and I am impressed by what it can do. However, I don't think I have really 'got' functional programming design. My background is in Smalltalk, and that colours how I think about design. I would like to really understand how FP differs from OO, and one approach would be to have a good side-by-side comparison of a solution.
I don't think the problem needs to be that complex. Maybe it is would be enough to show how FP would implement the typical bank account problem?
Does anyone know of a suitable resource?
Upvotes: 1
Views: 259
Reputation: 13483
A few random observations on Clojure from a Smalltalker's perspective.
do
and its relatives to abbreviate control structure. You'll find that the sequence library (map
, reduce
, and the rest), with laziness offer you another level of power and concision. But
If you like Smalltalk, you'll love Clojure.
Upvotes: 0
Reputation: 8854
I think that most books on Clojure will have something like a simple bank account program, which I view as a little database in which states get updated. For example, Halloway and Bedra's Programming Clojure has a program that keeps track of music recordings. When you read through a description of that program, you'll immediately see how to map it into an OO solution. However, I don't think you're going to "get" FP from such a simple example. Programming Clojure also has functional snake game. You could compare that to an OO snake game. (I'm not promoting Programming Clojure; it's a worthwhile book but I think it has a number of flaws. It just happens to be the Clojure book that I know best. A lot of people seem to like it, though.)
I'd suggest another strategy, maybe as a supplement to yours, for grokking FP: Read something introductory that immerses you in an FP worldview. My favorite is Friedman and Felleisen's The Little Schemer. It uses Scheme, not Clojure, but the ideas translate. There is a Clojure website devoted to it, but I recommend working through the original book in the way that it recommends, covering parts of the page as you go. I think the book that gave me an understanding of parts of FP that go beyond The Little Schemer, extending to much of what you find in the Clojure world, was Bird's Introduction to Functional Programming using Haskell. I feel funny suggesting a Haskell book, though. Why not a Clojure book? Well, maybe one of the Clojure books will have the same effect of giving you a pure baptism in the FP Way of Thinking, but the Clojure books I've read (P.C, The Joy of Clojure), though very good books, are somehow less immersive--maybe because they're more practical. On the other hand, P.C (and probably some other Clojure books) is (are) largely targeted toward OO programmers, so that might actually be what you want.
Upvotes: 1