## The Little Schemer. Book review

The first thing I noticed after opening the book is that it is indeed unlike anything I have read so far. Instead of explaining things directly, the book presents a dialogue between the authors and a reader. There are no paragraphs, just two columns of text – left with authors’ questions, the second with reader’s responses. This dialogue is very informal and usually ends up with talking about food. Sounds strange? Well, it was at first but as I went on I found this style very fun. Of course reading is not enough – you have to actually work through the code on your own and I admit that I found that part very entertaining and rewarding, especially when I was able to figure out solutions before reading them.

The book consist of ten chapters. Eight of them are dedicated to general lisp programming. Book starts with simple concepts like basic operations on lists and moves on to more and more advanced aspects of recursion. I feel that it has learned me how to think in a recursive way, which in turn made learning Haskell much easier. Last two chapters of the book are quite difficult though. Chapter 9 gives a step by step derivation of the Y-combinator. Well, almost step by step – I had a feeling that some parts were actually left out and I had problems understanding what is going on. Luckily Peteris Krumins has written a great post in which he derives Y-combinator and fills the gaps present in The Little Schemer. Even after reading that post I still needed about 3 days to understand what’s going on in the Y-combinator, but once things clicked it was my “Aha!” moment. That’s probably the most fascinating thing I’ve learned so far in computer science. Chapter 10 pursues the goal of writing Lisp interpreter in Lisp. The beauty of Lisp lies in the fact that it is actually a relatively easy task requiring surprisingly little lines of code. Check out this article by Paul Graham to see for yourself. Solution from The Little Schemer is actually a bit more complex than the one given by Graham and again it took me some considerable effort to work my way through this chapter.

At the end of The Little Schemer there are some references to books that in the authors’ opinion are worth reading. This is not only computer science stuff – among references is The Annotated Alice: Alice’s Adventures in Wonderland and Through the Looking Glass by Lewis Carroll – and I found one of the listed books to be very fascinating: To Mock a Mockingbird by Raymond Smullyan. It’s an introduction to combinatory logic given in a form of riddles. I’m somewhere in the middle and will hopefully finish reading it some day.

I guess the opinions on the internet were right – The Little Schemer is a great book and it really teaches how to think in a recursive way. I suggest reading it to anyone who is interested in being a better programmer, functional or not. This will be a good investment, especially that reading the book doesn’t take much time (authors warn the reader not to read it in less than three sittings).

Finally, there’s a sequel to The Little Schemer called The Seasoned Schemer. Unfortunately I was unable to find it so if any of you has a spare copy and would be willing to send it to Poland just let me know :-)

## Real World Haskell – impressions after initial chapters

December was a busy month for me with not much time for blogging. It looks that January will be even more busy, but I want to write some posts I didn’t have time to finish for the last couple of months. I have some book reviews on my mind and today I will begin with Real World Haskell.

The book assumes no prior knowledge of Haskell or functional programming. It starts off with simple, introductory topics and explains concepts of functional approach to programming. While the first examples of code are rather simple the book quickly moves to real-world applications (as the title rightly suggests). Aside from standard Haskell topics like lazy evaluation, typeclasses or monads, the book covers also parsing, databases, GUI programming, testing, profiling or interfacing with C. There are also many case studies. The good thing about the book is that chapters about particular technologies (that would be from 16 onwards) are self-contained and can be read in any order. On the other hand initial chapters seem to be a bit messy – they contain lots of valuable information scattered around in completely unexpected places.

While the book is a great source of information there are some reasons not to be happy with it. First of all I think that it is not suitable for most beginners. While RWH assumes no prior knowledge, the examples quickly get complicated and it might be hard to figure out what is really going on in the code. Authors often use top-down approach, that is they present a lot of code out of nowhere and then go into explaining what it does (this is the analytical approach). For that reason I had a lot of hard time with parsing described in chapter 10 and after reading the chapter twice I still don’t understand all of it. I think that in some cases bottom-up (a.k.a synthetic) approach to algorithm construction would be more suitable. This is of course very subjective – some people might be able to understand everything without problems. Anyway, the book is demanding and the reader should be prepared for it. Also, be prepared that chapters about more advanced technologies give mostly an overview and are not comprehensive treatment of the subject. After reading chapter about FFI I wasn’t able to write my own C bindings and only after reading the official FFI specification things became clear.

I was disappointed with the lack of discussion of GHC internals. I think it would be useful to explain things like thunks, WHNF as well as lazy evaluation model and possible performance issues related to it (memory leaks for example). There is one chapter about performance and profiling in general but it doesn’t go into details of how the compiler and runtime system works.

Speaking of the performance chapter, RWH is also affected by changes made to GHC since the book was published. Luckily this is not a major issue as almost all examples work as they should. Chapter about performance is seriously affected though. I wasn’t able to reproduce any of the presented results with GHC 7.4.2, but of course authors can’t be blamed for that. Also, one code snippet does not work because of changes made in GHC but again this is not a big problem.

I had a feeling that some basic concepts are not explained clearly enough. For example the book shows usage of `if` instruction in place where a more experienced functional programmer would probably use pattern matching (page 30). This might be fine since at this point the reader was not yet introduced to pattern matching. The problem is that this is only clarified on page 207, way too late in my opinion, especially that patterns are introduced on page 50. I also had a feeling that currying was not explained clearly and stressed enough. Moreover the book does not mention the term “referential transparency” (might be a good thing to teach wannabe Haskell programmers some jargon they are likely to encounter) and from the comments on the web I noticed that people not familiar with the concept of “side effects” are confused by the book’s explanation of that term. I also found that omitting type signatures in some function definitions makes the code harder to understand. Finally, one note about editorial side of the book. The book uses different kinds of crosses, stars, paragraphs and other signs to denote footnotes. It looks as though editors have decided not to use the same mark twice which is a bit annoying for me, but this is of course very subjective and definitely not related to the quality of the book itself.

Although I complained that some concepts could have been explained in a different way I still think that RWH is a must-read for any serious Haskell programmer. Mostly because it gathers a lot of practical information in one place. I hope to find more time to finish reading it as I’m very curious about chapters on monads and monad transformers.

Staypressed theme by Themocracy