Review: The Rails 3 Way (Obie Fernandez)

Often enough in the Rails community you hear people saying that following the Rails way of doing things will make life much easier. As the title suggests, this is the book that teaches you how to develop Rails 3 applications in “the Rails way”.

This book is not for beginners. Readers should at least know how Rails works, and preferably even have developed one or two applications as well. The book is organized in the form of a reference, and so if you’re looking for a step by step tutorial, you will be disappointed.

On the other hand, readers who already can develop Rails applications would find this a very interesting book to read. I wasn’t expecting that I would be able to read this book from beginning to end, but I did manage that, although with the amount of information in the book, I can hardly remember a tenth of what I read.

Like Rails, this book is highly opinionated. You will be told that Rspec is the Rails way to test, and that Haml is the Rails way of writing templates, even though Test::Unit and erb templates are the Rails default. In fact, there’s an entire chapter dedicated to Rspec and all the view examples use Haml and not erb. Those who use erb for templates might find the Haml examples a tad distracting.

The content of the book is arranged like this:

The first chapter discusses Rails configurations (bundler, dveleopment/test/production environment etc.) and is followed by a chapter on routing. It’s mostly plain reference so far, telling you what and how Rails works and how to set up your application. The third chapter, on REST and its implementation in Rails, is where this book really started getting my attention. This chapter will tell you all you need to know about why REST is such a big deal in Rails.

Chapters 4 through 9 cover the M and C of Rails MVC — the models and the controllers. ActiveRecord is covered in great depth and the chapter on advanced ActiveRecord is amazing. Reading the section on single table inheritance left me despairing about the awkward ways in which I used to handle ActiveRecord objects that would have been better off being split off into subclasses referring to the same table.

Chapters 10-12 cover the V of MVC – the views and helpers and a chapter on Ajax on Rails. This part too is one that you might use more as a reference than as read-on-the-train-to-work material. Especially the chapter on helpers is rather dry, and Obie himself mentions that it is reference material. In fact, the different helper modules are even arranged alphabetically.

Chapter 13 is on sessions management, and is followed by a chapter covering Authlogic and Devise – the two most popular authentication plugins for Rails. Since Rails doesn’t have a built in authentication system, a quick look at the two most popular plugins makes a lot of sense.

Chapters 15-16 cover ActiveResource and ActionMailer respectively. Frankly, I never really got what ActiveResource is all about, and I’m afraid I still haven’t got the eureka moment after reading this book.

These are followed by a chapter on caching and performance, and one on the testing framework, Rspec — both incredibly useful chapters. The former explains how to use builtin mechanisms in Rails to improve performance and the latter gives a quick introduction to Rspec. Chapter 19 covers Rails plugins and chapter 20 is about background processing in Rails – specifically Delayed Job, Resque, and rails runner.

This 700+ page book covers the Rails framework comprehensively (although it does skip ERB and Test::Unit completely). Like its predecessor The Rails Way for earlier versions of Rails, this book will be one that you will find most Rails developers referring to and quoting over the next few years.

Are there any negatives about this book? I should point out once again that this is mainly a reference for the framework, so some chapters might seem dry if you’re reading cover to cover. (I should also point out that these are the very chapters that you will be turning to when you desperately need reference for how to do something.) For instance, the chapter on helpers should certainly have been cut short and the majority of the content moved to the appendix. But on the whole, I have very few complaints about the book.

So who should buy this book? If you’re completely new to Rails, don’t buy now. (Or better, buy it but read it after you’ve read an introductory book on Rails.) Newcomers will easily be overwhelmed with the in-depth coverage of Rails and the lack of example apps to work on while learning.

That doesn’t mean that beginner level Rails programmers won’t find this book useful. I’m only saying that this wouldn’t be the best book when you’re looking at Rails for the first time. If you have some understanding of Rails, even if it is only one or two toy apps, this book will help you make big leaps in productivity. And experienced Rails programmers will obviously find the exhaustive coverage of Rails very useful.

Review: Eloquent Ruby (Russ Olsen)

If you are new to Ruby programming, Eloquent Ruby should be the book you read right after you finish your introductory Ruby book. It’s not a beginner’s tutorial, but with a little background on Ruby, it would be easy to follow.

This is one of the better programming books I’ve read. It has plenty of short and clear example code snippets, a very conversational and humorous writing style and most importantly, covers exactly the kind of topics a newbie should understand about Ruby.

The book is divided into 4 parts – (1) The Basics, (2) Classes, Modules and Blocks, (3) Metaprogramming (4) Pulling It All Together.

The firsts section covers the basic Ruby idioms in a way that you wouldn’t normally get to read in most books. It has chapters like “Choosing the Right Control Structure”, “Write Specs”, “Embrace Dynamic Typing”.

The second section — the most useful one, in my opinion — covers classes, modules and blocks with chapters like “Use Class Instance Variables”, “Use Blocks to Iterate” and “Use Modules as Name Spaces”. This section does an excellent job of explaining how to effectively use blocks, which are probably Ruby’s most useful feature.

The third section talks quite a lot about using, and of not misusing, the powerful method_missing method. Other Ruby metaprogramming topics such as monkey-patching are also covered.

The final section talks about one of Ruby’s greatest strengths — building DSLs — and also about creating and packaging gems. The book wraps up with a quick note on the the available ruby implementations.

At the end of each chapter there is a section “In the Wild” where the author points to real world code relevant to that chapter. Knowing where to look for real world examples will be especially useful for newbies who haven’t read a lot of other people’s code.

Another useful section in each chapter is “Staying Out of Trouble”, where the author explains the common pitfalls associated with the topic being discussed.

The examples that are used in the book make it extremely easy to understand. I often find books choosing overly elaborate examples and thereby distracting readers away from the language idiom being discussed. Eloquent Ruby doesn’t have that problem. The author starts with a simple Document class and uses the same example throughout the book, making it easy to focus on the idiom being discussed.

There are no real negatives I can point out, except for the slightly outdated chapter on packaging gems. However, I was reading the Safari’s Rough Cuts edition of the book, and it’s a work in progress, so it might get updated soon enough.

This book is a must read if you are a beginner to intermediate level Ruby programmer. It teaches the Ruby way of writing code, and answers many of the questions that one might have on the effective use of Ruby idioms.

You can read the Rough Cuts edition on Safari Books online.

Review: AOC F22 (22 inch widescreen monitor)

A month ago, I finally decided to switch to an LCD display, having been using CRT all this while. After looking around for a good but not too expensive monitor, I finally bought AOC’s recently released F22.

The F22 is a 21.5 inch widescreen monitor with a native resolution of 1920×1080, which means you can watch 1080p high definition video at 16:9 aspect ratio rather than the 16:10 available in most widescreen monitors.

So far I’ve been mostly satisfied with the monitor, and it is especially useful when I’m coding. Being able to use NetBeans with all that screen real estate feels great. This screenshot should give you an idea.

Apart from NetBeans, Photoshop is perhaps the only application I run in a maximized window. I’m not much of a designer, and I’ve only used it for minor tasks like slicing and resizing images, so I’m not really qualified to say whether or not it’s good for Photoshop work, but it’s definitely a huge step up from the two LCD monitors I’ve used at work (LG L1742S and Acer x153w) or my old CRT monitor.

Has it changed the way I use my desktop for browsing? I think so. I no longer run Firefox in a maximized window. Most websites out there aren’t really meant to look good at this resolution (including this blog) and some of them look outright hideous.

The only feature I can really use in a maximized window is the side-by-side multiple inboxes in gmail, but I stopped using that because I had to constantly switch it back because it looks terrible in the 1280×768 monitor I use at work. Now I’m resigned to using a window around 1280px wide so that the browser window looks the same as the one I have at work.

One category in which AOC definitely beats all competition is when it comes to the design and looks. The F22 monitor doesn’t have a conventional base like other monitors and instead has a base inspired by a photo frame with an adjustable single post stand that allows adjustment of the tilt angle. (see image below) This definitely has to be one of the best looking monitors I’ve seen.

When it comes to watching videos on this one, I’m happy with the colors and contrast. I played a high definition video to check what it would look like, and it exceeded my expectations in that regard. The clarity and the level of detail was stunning.

However, the brightness dips drastically at wider angles, and videos are almost unwatchable if I’m lying on my bed which is right next to my desk. I don’t really take the manufacturer’s viewing angle specs of 170/160 at face value, but unless I’ve really messed up the trigonometry calculations here, the viewing angle wouldn’t be more that 120-130 degrees at a 6ft distance from the desk. That for me is the major disappointment with this monitor. But then, I’m used to the CRT monitor’s viewing angle and that’s probably why I’m so harsh on this point.

Another drawback is that the pixels per inch is on the higher side at 102 PPI, (24″ displays have 91) which means fonts look smaller, but then that’s a trade off you have to make when you choose a 22″ monitor with 1080p resolution. This doesn’t normally bother me much, but when I visit websites that use smaller font sizes, I have to zoom in to be able to read comfortably.

AOC claims a dynamic contrast ratio (DCR) of 30,000:1 for this monitor, but in case of these specs, seeing is believing. (There are monitors claiming DCR of 1,000,000:1) There is a DCR mode in the luminance options of the OSD, but I would recommend wearing sunglasses to avoid being blinded by the extremely high brightness levels. I might be wrong here, but isn’t DCR all about reducing the illumination for the dark pixels rather than increasing it for the brighter pixels?

There are VGA and DVI inputs for the dislpay. Strangely enough, there is no HDMI port, which is fairly standard these days on monitors with this resolution. However, I don’t have any complaints ther as I only use it with my desktop. Also, it does not feature any USB ports, which are also standard on monitors these days.

Despite all that grumbling in the previous 2-3 paragraphs, I’m kind of happy with my choice of monitor. The viewing angle is the only thing that irks me about the display. The large screen area obviously helps a lot when I’m working, and it’s nice watching videos on it, even though I have to stay within a narrow viewing angle to enjoy it fully.

My rating: 8/10