Book Review of "The Well-Grounded Rubyist"

For the last couple of months I've been working with Rails 3 in my spare time. Generally I've been productive, despite my lack of Ruby knowledge. Lately I've reached a point where I need a better understanding of Ruby to dive deeper into the Rails code and figure out how the magic is implemented.

Book Cover: The Well-Grounded Rubyist

I've been programming for years with static languages like C++ C# so I went looking for a book that introduces Ruby without being an introduction to programming in general. I started reading "The Ruby Programming Language" by David Flanagan and Yukihiro Matsumoto. Despite the positive reviews, I found the book a bit dry and gave up a couple of chapters in. To be fair, the intent of this book is to be more of an authoritative reference and less of an language introduction.

Next I started reading David A. Black's book "The Well-Grounded Rubyist" and didn't look back. The layout of the book is its greatest strength, making it easy to learn the language without being overwhelmed with details. It is divided into three parts, each progressively with more detail and longer code samples. The first part is a broad but shallow into the language and the environment: objects, classes, and modules. The second part circles back and gives more information on built-in classes: strings, collections, file I/O, regular expressions. The third part layers on the dynamic aspects of Ruby: object individualization, callable and runnable objects, callbacks, hooks, runnable objects.

Experienced developers new to Ruby will find the first part interesting and useful. The second part on built-in classes is tedious in some sections; however, the text is easy to skim, allowing the reader to focus on concepts more unique to Ruby like bang (!) methods, symbols, the enumerable module.

The third part is where the book really shines. The code samples are short but carefully chosen to showcase the power of Ruby. BasicObject is combined with method_missing to allow formatting of lists, in the spirit of the Builder library by Jim Weirich. The socket module is combined with threads to write a networked rock-paper-scissors game. Hooks provided by Ruby (such as inherited and method_added) are combined with runtime introspection to create a unit test framework in the spirit of MiniTest. These examples demonstrate the level of Ruby sophistication the reader has attained by completing the book.

"The Well-Grounded Rubyist" is relatively up-to-date, covering Ruby 1.9.1 (current version is 1.9.2). The production quality is high, with no obvious errors (unlike "Rails AntiPatterns" which I read recently). My only criticism would be that the book is a touch long at 470 pages (not counting the index).. In particular, the summary sections at the end of each chapter add little value and should have been cut. This is a minor quibble and overall I would recommend Black's book to developers wanting to learn Ruby.

Posted in  Book Review Ruby

Book Review of "Calculated Bets: Computers, Gambling and Mathematical Modeling to Win"

I recently read the book "Calculated Bets: Computers, Gambling and Mathematical Modeling to Win" written by Steven Skiena and published in 2001. The book follows the author, a professor of computer science at the University of New York at Stony Brook, as he develops a computer system to pick winners in the sport of jai alai.

Book Cover: Calculated Bets

Skiena explains how the computer system is built in stages, progressively incorporating different mathematical modeling techniques to improve its accuracy. Initially the Monte Carlo method is used to simulate the "Spectacular Seven" scoring system of jai alai. Next, the model is improved by accounting for the skill of the individual players using curve-fitting techniques. Since betting on jai alai in the United States is a pari-mutuel system, the payoffs from any given bet also need to be modeled, this time using statistical techniques. The explanations are clear and interesting, requiring a minimum of mathematical sophistication.

The excitement builds near the end of the book when the software reaches a working state. The final program, called "Jai Alai Maven" starts betting on actual matches with real money. Skiena deposits $250 in an off-track betting account and lets the program automatically pick winners for each day's jai alai matches. Maven is generally successful, growing the pot to close to $2000 in a couple of months before Skiena pulls the plug on the experiment. Maven even seems to develop a personality, winning big whenever it bets more than $100 in a day and giving back some of the gains on days when it bets less.

The book attempts to combine a number of different themes into a single volume and is generally successful. There is an overview of gambling, especially wagering on jai alai. There is the story of Skiena developing the "Jai Alai Maven" program and its eventually performance. Finally, there is an introduction to mathematical modeling and computer simulation. A few of the sections, such as the section entitled "Why Real Programmers Hate Microsoft" or the introduction to fractal curves seem out of place in the book as well as a bit dated. However, there are more than enough interesting, well-written sections to make the book a worthwhile read.

Posted in  Book Review Mathematical Modeling

Setting Up a Blog Using Jekyll and Heroku

I registered the domain in 2007 and now, in 2011, I finally decided to take the plunge and set up a personal website and blog. Recently, I been focusing on Ruby and Rails development in my spare time so I figured I could turn this into a learning opportunity by using Jekyll to generate the static content and Heroku to handle the hosting. The process was generally straightforward, but I did encounter a few small snags so it is worth documenting.

First, find an existing Jekyll site that you like from the list on github and fork it. Remove all of the files in the _posts directory. Create a test post in this directory called yyyy-mm-dd-test-post.markdown, replacing yyyy-mm-dd with the current date. The date that will appear on the displayed blog post will be parsed from this filename.

Comb though the content in the remaining files looking for any references to the author that you originally forked the site from. Remember to check for any hard-coded references to disqus, Google Analytics, FeedBurner, github, etc. accounts in the content.

Open a shell and type

gem install jekyll

Go into the directory containing your website and type

jekyll --server --auto

Open your browser and go to http://localhost:4000. Make sure everything looks good locally on your website.

Notice that Jekyll has created a new folder called _site which holds the statically-generated content. If you take a look at the .gitignore file, you should see this folder listed. This is correct behavior since we don't want redundant data polluting our source-code repository.

Now we need to get Jekyll working with Heroku. I found this post helpful for these steps. In the shell, type

gem install heroku

In the top level of your website, create a file containing

require "rack/jekyll"


Also create a file called .gems with the contents


Commit all of your changes with

git commit -am "Final changes before pushing to heroku"

Now issue the command

heroku create

Finally, we are ready to push the content to Heroku, but there is a subtle problem. The contents of the _site folder are be automatically generated by Jekyll so you don't want to add these to github; however, you do need to have the _site folder when you push to Heroku. I found a solution in this post. We need to create a new branch

git checkout -b production

Now edit the .gitignore file and remove the line referencing the _site folder. Commit your changes and then

git push heroku production:master

View your site on Heroku and make sure everything is working correctly. If you see "Your application has crashed", type

heroku logs

at the command line. If the stack trace has the message

.gems/gems/jekyll-0.10.0/lib/jekyll/site.rb:220:in `initialize': Permission denied

then you probably forgot to remove _site from the .gitignore file, or you didn't end up pushing this directory to Heroku. Fix the problem and try again.

Posted in  Jekyll Heroku

Fork me on GitHub