Wanna buy a book? Ruby+Rails+mySQL == my private bookstore

Although I had some problems getting mySQL installed and talking to Ruby/Rails (all my fault!), once that was resolved, it took less than an hour or so to get the sample storefront up and running.


I’ve always been a fan of incremental development and “scaffolding”, and Rails is the very first programming system I’ve seen that really, really supports this model, and damn well.


The book is generally well-written but I found one minor “gotcha” that is worth mentioning. First of all, the source code for all the sample applications is available online at http://pragmaticprogrammer.com/titles/rails. This is good, but since this book is really about incremental development, each file exists in dozens of versions, evolving as the project proceeds.


They’ve made finding the right file pretty easy most of the time. In most cases, when a file is being created or modified, there’s a file number (“file 70”) in the margin that refers to the file list in Appendix C.3. Each file number leads to a pathname in the downloaded source tree. So far, so good. Sometimes, like in Chapter 7, pp. 72-73 it’s not obvious which file you’re supposed to be editing unless you follow the file number to the path name. A minor thing, but one that can slow you down sometimes. In Chapter 7, each file goes through multiple versions, each one with a new file number. I found it easier to keep track if I copied each file from the downloaded source into my project, and then checked it off in the margins.


One more thing: the image files. There are image files referred to implicitly in the examples, but they aren’t referenced using the file number system that is used for source files. In fact, they aren’t really referenced at all. But you can find them in the downloaded source…


So, now back to Rails…


I’m finding that one of the beauties of rails is the invisible, implicit mapping from the Ruby objects to database tables and records. I’m really programming as if I just had a big pile of persistent objects, and the fact that there’s a database behind it is just a (well-hidden) implementation detail. I’m just not having to think in terms of tables and records, just objects and instances. I’ve never been a big fan of OO programming, but I think it’s because I’ve not used an OO system as natural as this one. (That doesn’t mean that there aren’t perfectly wonderful and natural OO systems out there, it’s just that I havent used them.)


So, after less then two or three hours of reading a book and editing some files, I’ve got the beginnings of a storefront. I can add and edit products, and I can show the available products to a prospective buyer. I’ve written (or copied) less than 150 lines of code in maybe a half-dozen files. The rest is just inheritance and some really good base classes!


Next stop, a shopping cart. Shouldn’t take more than an hour, at this rate.