From: Mikkel Damsgaard Date: 2001-09-21T23:37:09+09:00 Subject: [ruby-talk:21491] SV: Re: Ruby/objects book in style of The Little Lisper > Fra: Kevin Smith [mailto:kevinbsmith@yahoo.com] > --- Christopher Sawtell wrote: > > > The question is: can I pull it off? To see, I wrote the > > first chapter, > > > which you can find here: > > > > > > > I think it's promising. I do think you could pull it off, > but it's definitely not "there" yet, for me. I haven't read > the original, so I have no idea how this compares in style. > > A few comments, which you can take or leave as you wish: > > 1. Pet peeve #1: factorial should not be implemented using > recursion. It's just a loop. Simpler. Faster. Safer. > > # warning: untested code ahead! > def factorial(n) > result = 1 > n.downto(2) do | value | > result *= value > end > return result > end > Hey! Ruby is proper tail recursive, so since the recursive factorial is much easier to understand and runs as fast, it is a nice starting example. It would be cool to get back to it later to explain tail recursiveness. > 2. Pet peeve #2: programming books that focus on math. I > don't mind having factorial in there somewhere, but putting > numbers first will turn off a lot of non-math folks, I > think. > Math is a nicely simple extrepsion of abstract ideas. Ideally to start off a book with imho. > 3. The first function in your book is pretty complex. I > would tend towards something simpler. In the numbers realm, > a method that returns n*n, or n*2. In the words realm, a > method that always returns "Bob" or something, perhaps? > Factorial is a excellent starting example, because it computes something non trivially in a few lines. > 4. The persona on the right seems more knowlegable than I > would expect. Describing the factorial function in English > would be reasonable, for a math-person, I suppose. But a > non-math person won't be able to relate. > The right person does seem to know a little bit to much about programming ruby for my taste, but it seems reasonable to expect a person learning ruby to express factorial in text. > 5. Naming a method factorial2 is confusing. I thought it > might be factorial 2 aka factorial(2) at first. > Me too. This point is very good. In general I'm pretty pleased with the first chapter. It reminds me of a Don Knuth book on infinitisimals. (But I suspect he "borrowed" the style from Sochrates. /Mikkel