Confident Ruby is Finished!

Confident Ruby 3DI am thrilled to announce that my book Confident Ruby is now finished. I even hit my target of releasing by September 1st… if by “September 1st” I had meant “of the following year”.

So what is this book and why should you buy it? Confident Ruby is, first and foremost, a book about joy. It’s about the joy I found when I first discovered how elegantly and succinctly I could state problems in Ruby code. It’s about the joy I gradually lost as the “real world” snuck in and gradually cluttered my code with distracting edge case scenarios, error handling, and checks for nil. And it’s about how I came to recapture that joy, by employing small patterns and stylistic choices to make each method tell a  coherent story.

The structure of the book is that of a patterns catalog. But these are not the large, heavy-weight architectural patterns of a Design Patterns or a Patterns of Enterprise Application Architecture. These patterns are small, most of them taking place at the level of an individual method or even a single line of code. They are related by a single organizing principle: removing the uncertainty that leads to code that is riddled with conditionals, and constantly second-guesses itself; and replacing it with a confident, clear focus on the task at hand.

In these pages you’ll find:

  • 32 patterns for writing confident code.
  • How to avoid the “MacGyver method”–a step-by-step guide to thinking about methods in terms of the story they tell rather than the building blocks that happen to be lying around.
  • The most comprehensive coverage anywhere of Ruby’s conversion methods and protocols. You’ll learn not just how to convert built-in objects from one to another, and when to use #to_a vs. #to_ary vs. Array(); but also how to adopt Ruby’s conversion conventions to make your own objects powerfully extensible.
  • How to streamline your code and eliminate repetitive conditionals with the Special Case and Null Object patterns… and how to avoid the gotchas that can come with naive implementations of these patterns.
  • Simple habits to eliminate the dreaded “NoMethodError for NilClass” exception.
  • How to make your methods more flexible by passing in behavior instead of data.
  • How to helpfully deliver results from your methods when the possible outcomes are more nuanced than “success” or “failure”.
  • An applied demonstration of refactoring two Open-Source Ruby projects using patterns from the book.
  • And much, much more… nearly 300 pages of material and hundreds of code listings.

Want a taste of the book? Click here for a PDF sample, containing the introduction and three patterns.

Confident Ruby is is available in three different editions.

[cta size=”medium” action=”Buy Confident Ruby Gold Label Edition ($55)” url=”https://shiprise.dpdcart.com/cart/add?product_id=67241&method_id=69387″]

The Gold Label edition comes with:

  • Confident Ruby in PDF, EPUB, and Kindle formats.
  • naught-boxshotA 30 minute Confident Ruby companion screencast, in which you can watch “over my shoulder” as I apply concepts and patterns from the book to the Discourse codebase.
  • Much Ado About Naught: An Adventure in Metaprogramming.  This ebook follows the step-by-step, test-driven development of the “Naught” gem for constructing Null Object classes. Much Ado About Naught CoverIt covers most of the metaprogramming techniques, tricks, and gotchas I’ve picked up over the years, and comes complete with whimsical Paintbrush illustrations by Lauren Shepard! (aka my mom)
[cta size=”medium” action=”Buy Confident Ruby Black Label Edition ($45)” url=”https://shiprise.dpdcart.com/cart/add?product_id=67243&method_id=69389″]

The Black Label edition comes with:

  • Confident Ruby in PDF, EPUB, and Kindle formats.
  • The Confident Ruby companion screencast.
[cta size=”medium” action=”Buy Confident Ruby Red Label Edition ($35)” url=”https://shiprise.dpdcart.com/cart/add?product_id=67244&method_id=69390″]

The Red Label edition comes with:

  • Confident Ruby in PDF, EPUB, and Kindle formats.

Finally, as always if you don’t have the scratch for any of these editions, you can still send me a postcard!

(Beta buyers: keep an eye on your inbox for a way to get the Gold Label extras at a special discount.)

Oh yeah, one more thing. One of the things that held up the release of this book was that I wrote a completely new publishing toolchain called Quarto. It’s still early days, but it already has a number of unique capabilities. It’s written in Ruby and is open source, so if you’re a Ruby programmer and interested in publishing ebooks, feel free to check it out and start hacking on it.

22 comments

  1. Avdi, the PDF preview is really promising! Also, I think I’m going to contribute to quarto in the next few weeks when I finish an ebook project. I’m really glad I subscribed to your feed 🙂 Congratulations for finishing the book!

    The example PDF’s table of contents doesn’t show the actual book’s contents, though. I scanned your post twice to see whether there’s another preview of the ToC alone. I’d love to have a look at that!

      1. Wouldn’t it be feasible to just copy & paste the real ToC from your final PDF and save it as a new file? Then you needn’t worry about keeping the real ToC and the excerpt’s pages aligned. That’d work for me at least.

  2. I read until the 100th page, it is full of weird patterns. Even though I haven’t finished yet I strongly recommend. Well done keep the great work!

  3. Hi Avdi,

    I have to say that I’m really enjoying putting the principles and patterns in Confident Ruby into practice in an existing project which until now was not so much confident as much as a gibbering wreck on the inside that was just about holding it together to the outside world 🙂

    I’ve just noticed a couple of small errata – well, one that gets repeated, really – and didn’t see anywhere else to report it. Hope you don’t mind me doing it here.

    In section “4.5 Return a status object”, the ImportStatus object listing on page 227 defines self.failed as setting @status to a value of :failed – but the instance method failed? checks for a value of :error. This is replicated in the yielding version on p231.

    Like I said, small 🙂 Thanks again for a great book.

  4. “You want to ensure that inputs are of a specific core type. For instance, you are
    writing a method with logic that assumes Integer inputs.”

    The question is why would you want to do that. If an object doesn’t respond to messages you send to it, it’ll fail sooner or later. I’ve found only two reasons for doing that:
    1. You want to ensure it’s integer because an object responding to * and / would still lead to a disaster. As in:
    class FakeInteger
    def *(other); 42; end
    def /(other); 24; end
    end
    2. To give a good error message. I think doesn't respond to to_int' is a better message thandoesn’t respond to *’.

    It may be out of scope of the book to explain that.

  5. Point.new(*args.first.split(‘:’).map(&:to_i))

    Was it intentional that ‘:10 and ‘:’ and ’10:0:0′ would be converted w/o an error? I’m enjoying the book, but don’t like this.

  6. Errata: Page 72 at bottom of page (PDF) “input values form external sources” s/b ‘input values from external sources’ IMHO.

  7. Love it! FYI, another errata: Page 136 at top of page (PDF): “If it’s possible to for a variable” s/b “If it’s possible for a variable”

  8. Dig the PDF preview.

    What do you think about using ensure for bouncer methods?

    def filter_through_pipe(command, message)
      __checked_popen(command, "w+", ->{message}) do |process|
        ____process.write(message)
        ____process.close_write
        ____process.read
      __end
    ensure
      __unless $?.success?
        ____raise ArgumentError, " $?.exitstatus}"
      __end
    end
    
  9. Great stuff, Avdi. This will definitely make more effective in my work.

    One possible erratum…on page 83, where you rewrite the example to use named objects STOP, CAUTION, and PROCEED, the next_state method doesn’t use them for the return values. Shouldn’t it?

    For example: when STOP then PROCEED, rather than when STOP then ‘proceed’?

Comments are closed.