Category: books

Coders at work. A short review

CodersAtWorkI was visiting my friend before Christmas and on his shelf I found “Coders at Work” by Peter Seibel1. It’s a collection of interviews with fifteen world-known programmers (assuming a programmer can be world-known). Among the names two have caught my eye: Simon Peyton Jones and Guy Steele. I borrowed the book and ended up reading interviews with these two researchers and Donald Knuth. Not surprisingly, interview with Simon Peyton Jones was the one that interested me the most. I found it very enjoyable to read accounts of how these people became programmers in times where computers where huge machines available only at universities. On the other hand I also found some parts of the interviews to be a bit dry, e.g. SPJ goes into the discussion of Software Transactional Memory in Haskell and I think that reader not familiar with STM will not get much out of this. Also, reader familiar with STM will probably not need this discussion.

There are two thoughts that stroke me during the reading. When reading interview with Knuth I realized that there are actually people that are unable to learn programming. I teach at the university and I’ve seen many first year students who completely don’t grasp programming but somehow it never occurred to me that some of them might not ever be able to learn this. Second thought, the more important one, is that all these famous programmers were extremely lucky guys. They all got the chance to develop their talents. I believe that there are even more very talented people who could have had even greater impact on computer science, but they just didn’t get their chance.

One last thing. SPJ mentions that his “Aha!” moment in functional programming was Arthur Norman’s demonstration of implementing double-linked list in a purely functional fashion, that is without any side effects. I tried to google more information on that but with no result. So if anyone has an idea how to implement such a list please tell me. The only thing that comes to my mind are zippers. They do allow traversal of list in both directions and modifying its elements so this might be it.

  1. In fact I found Polish edition. []

The Little Schemer. Book review

Exactly one year ago I was in the middle of reading “Seven languages in seven weeks” by Bruce Tate. This book introduced me to functional programming with languages like Erlang, Scala, Haskell and Lisp. Now, the Lisp part is the interesting one. I was googling some things about Lisp and somehow I landed on Paul Graham’s page. His essays on Lisp fascinated me so much that I decided to learn me some Lisp for great good. So when I reached the chapter about Clojure (Lisp dialect for JVM) I actually decided to skip it and learn more on my own. After some googling I settled on Scheme (another alternative was Common Lisp). I began with reading the official R5RS specification (only about 50 pages) but that definitely wasn’t enough. On various blogs and sites on the Internet I found people talking about this book The Little Schemer by Daniel P. Friedman and Matthias Felleisen, how great and different from other books it is and how it can change the way you think. I decided to give The Little Schemer a try.

The_Little_SchemerThe 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.

rwh_coverReal World Haskell – commonly referred to as RWH – was written by Bryan O’Sullivan, John Goerzen and Don Stewart and published in 2008 by O’Reilly. With 28 chapters on 670 pages it is the book about Haskell. There is no more comprehensive book on Haskell at this moment. The best thing is it is available on-line for free. I don’t like reading large amounts of text from a computer screen, so when I decided to learn Haskell 10 months ago I mailed my university’s library and asked if they could get the book for me. Three weeks later brand new copy of RWH was on my desk. Up till now I read chapters 1-11, 17 and 25 which is about half of the book. Perhaps a review should be based on reading the whole, but after over 300 pages I already have my opinion and I don’t think it will change much after reading remaining chapters.

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