Preface

Why I Wrote This Book

Some years ago I purchased the book Mastering Algorithms With C, but didn’t have time to read it. After leaving my computer programming job and moving across country, I found myself in 2003 with both time on my hands and my brain turning to mush. So I began reading the C book for stimulation. It introduced me to the world of “big-O” notation, data structures, hash algorithms, sorting algorithms, data compression algorithms, and so on. In other words, it introduced me not necessarily to computer programming, which I had been doing off and on since age 12, but to computer science. I wanted to play with the topics presented, but I didn’t want to install a C (or C++) compiler on my computer.

In the meantime, I ran across the book Python in a Nutshell at my local library and decided to borrow it. I knew nothing about Python except that it had a reputation for being a newfangled “scripting” language, akin to Perl. (You’re wondering when I’ll get to Ruby! Patience, patience.) Well, after reading a couple chapters I was amazed by how powerful yet simple the Python language appeared that I just had to try it. I downloaded and installed Python on my OS 9 Macintosh and looked around online for tutorials.

In addition to several good materials which I won’t go into here, I came upon How To Think Like a Computer Scientist: Learning With Python by Allen B. Downey, Jeffrey Elkner and Chris Meyers. Although written for people new to programming, it progresses very nicely to some of the topics addressed in the above-mentioned Mastering Algorithms With C. I also enjoyed its Old Maid game and I especially enjoyed creating my own Fraction class, complete with “overloaded operators”.

I joined a local group of “extreme programmers” via the C2 wiki in 2004. They had already begun a project using the Ruby programming language, which I had barely heard of. Hence, it was time for me to search the internet for Ruby tutorials and teach myself Ruby. The most helpful material I could find at the time was the online version of “the Pickaxe book”, Programming Ruby: The Pragmatic Programmer’s Guide. The Pickaxe is a good resource for people coming to Ruby after experience in other modern, high-level languages such as Python, Perl, Java, or Smalltalk. In fact, being a newfangled “scripting” language, Ruby is often compared with Python and Perl, especially Python.

Since working my way through the Pickaxe and writing Ruby software with the XP group, I’ve found a few other online resources teaching Ruby. Some are for programming novices and hardly cover much material at all. I found Chris Pine’s “Learn To Program” to be the best of that bunch. Then, the Pickaxe and the “Ruby User’s Guide” are suitable only if you already know how to program in other languages. And “Why’s (Poignant) Guide to Ruby” is intelligible only after you know some Ruby. On top of it all, I find the documentation on the Ruby language to be a bit frustrating. In summary, although Ruby is not a difficult language, my Ruby learning has not progressed nearly as easily as my Python—or even my Perl—learning. I’m just not terribly satisfied with the Ruby materials available for free online.

Well, for whatever reason, I’m an avid reader of computer programming books, especially when they’re free. I was reading Allen Downey’s How To Think Like a Computer Scientist: Java Version in the spring of 2006. As I read I recollected how enjoyable and instructive I had found the Python version to be, and I wondered whether there exists a version for Ruby. As well as I can discern, there does not. I inhaled and determined to start writing such a beast.

It is my hope that How To Think Like a Computer Scientist: Learning With Ruby will fill a niche sadly not filled by most other online Ruby resources. I hope that How To Think… will be suitable for beginning programmers looking for more than a quickie tutorial. And I hope that experienced and professional programmers will find How To Think… a refreshing change from the “pragmatic” emphasis of many Ruby books on the market.

Elizabeth Wiethoff, May 6, 2006

Typographical Conventions

This book uses a few typographical conventions:

Words in bold italics are terms you should add to your vocabulary. They are explained in the text and also defined in the end-of-chapter glossaries.

# A Ruby program or code snippet is displayed in an outlined box.
# A fixed-width font is used.
# The code often employs colored syntax highlighting.
# The boxed text resembles source code in a programmer's text editor.
Ruby output and interactive Ruby sessions are displayed in a dark box.
A fixed-width font is used.
The box resembles a command line window.

Text in funky maroon needs to be rewritten or deleted. When I’m finished writing the book, this text will be gone.

Tools Used

All pages are valid HTML 4.01 according to the “strict” definition. Most of this book was written using BBEdit 6.5, a commercial editor for Apple computers. Mathematical expressions were written in MathML using jEdit 4.2, an open-source, Java-based editor. I then snapped pictures of the mathematical expressions displayed in the Mozilla 1.3a browser (there’s a MathML bug in Firefox) and incorporated them as PNG files in the book. The Ruby code in this book was written with BBEdit and tested in Ruby 1.6.7. I wrote my own little Ruby script to convert the code to color-highlighted HTML. The HTML pages were tested in these browsers: Firefox 1.0PR, Mozilla 1.3a, Internet Explorer 5.2 for Mac, Internet Explorer 6 for Windows, Safari 1.0 and Lynx 2.8.5. Pages were uploaded to the web site using NetFinder 2.3. Except for testing pages in Internet Explorer 6, all work was done on an old lime iMac running Apple OS X 10.2. I don’t mind being a bit of a dinosaur. :-)

GNU Free Documentation License Valid HTML Valid CSS Built with BBEdit
Friendly links for Google “juice”