Author: David B. Copeland
Publisher: Pragmatic Bookshelf
Audience: Ruby Developers
Reviewer: Mike James
Command-Line applications! If you think that the GUI is the only way to do it, this book might have something to teach you - or not..
Command-Line applications - either you think they are the best idea ever or you wonder why anyone could possibly be bothering with such old approaches.
There are command-line apps that do make life easy. They do exactly what you need, their defaults fit most cases and they are logical in the way that they use command line switches. So there is still room for a command line app. However, the big problem with command line apps is that they tend to be difficult to use for the casual user. If you need to do something about once a year then trying to remember command line options isn't something to look forward to. In this case, a nice GUI with drop down lists of options, check boxes and radio buttons is a blessing.
The only exception is when the command line app is written by you for your exclusive use. There is something of this idea in the book's subtitle - Control your computer, simplify your life. Yes there are a lot of non-programming users I can think of that this subtitle would attract. However, the book isn't an introduction to Ruby. You are expected to know how to program at a reasonable level and in Ruby specifically. This isn't a beginner's book but it raises the question of what it could tell an expert about the command line that wasn't already obvious? Overall, this doesn't seem like a book that needed to be written.
The first chapter starts off with an example of writing a backup utility. It's a nice example and it illustrates the command line idea but it isn't rocket science. Chapter 2 moves on to consider options and arguments in commands. This is an account of how Linux does things but this sort of makes sense. Chapter 3 is about documenting commands and this has a Linux/Unix orientation with Man pages and general help text. Chapter 4 deals with writing an app that plays well with others - use exit codes, use stdio, format for use further along the chain and trapping signals. There is no discussion of pipes or any other method of connecting command line apps together. It is assumed that the reader knows about how all of this works and it is used used in an example.
Chapter 5 seems to be about metaphysics - "Delight Casual Users". It deals with topics such as choosing names for options and picking defaults so that the app does what the user mostly wants. Chapter 6 goes on to consider configuration as read in from a file. The suggestion is to use YAML as it is the Ruby standard way of doing things. I would have like a little more discussion of why YAML and what the alternatives were.
At this point the book moves into increasingly general areas. Distributing Ruby apps as Gems, test driven development, code maintenance and modularity. All good topics but not particularly specific to command line applications.
The final chapter suggests adding color and clever formatting to the command line app to make it easier to use, look better and so on. At this point I couldn't help but think that a GUI interface would look even better, but...
Command line apps do have their place. They are right for one-off utilities that you alone are going to use and for highly technical apps that, again, are mostly going to be used by just you. The majority of command line apps never make it into the wider world because they are so specific. Given that Ruby is usually introduced via the command line, most Ruby programmers are going to be happy creating command line apps, but perhaps they should stop and think about best practices - what to call a command or option and what default to use.
This book does draw attention to these ideas but, apart from this, it really doesn't add much. Perhaps there is little to add and if you are considering the complete generality of a command line app this is probably true, which makes the book mostly redundant.
Given that many command line apps are essentially system maintenance macros or highly specify application macros, then perhaps there is a place for a book something like "Ruby Command Line Sys Admin" or something similar, and this presumably might show you how to take control of your machine. This particular book doesn't have enough information content and so doesn't really have a place.