Clean Ruby

Retired

This book is no longer available for sale.

Clean Ruby

A guide to crafting better Ruby code

About the Book

This book is now Clean Ruby and can be purchased on APRESS's website! Read More

Messy code can cripple productivity and make life unpleasant for developers. Bad code is hard to test and is the source of bugs. Each day, we waste countless hours struggling with poorly written Ruby code. Clean Ruby will teach you how to make better decisions and have you writing cleaner code.

This book is the culmination of many years of experience across numerous codebases both large and small. You will learn from first-hand experience. Each chapter covers the topics you need to know to make better decisions. Many books will tell you how to do something, but this book will tell you why you should do it. Start writing code you love.

Books like Clean Code by Robert C. Martin or Code Complete by Steve McConnell are great resources for learning these concepts but are for developers who use compiled languages like C, C#, and Java. Clean Ruby is written for Ruby developers. There is no need to learn a new language or translate concepts to Ruby.

Is this book right for you?

  • You've graduated from one of many Ruby on Rails dev bootcamps
  • You've been programming for a couple of years in Ruby on Rails

What you will learn?

Build better classes to help promote code reuse. Create more straightforward methods to increase productivity. Improve your decision making and make better, smarter choices. These are the things you will learn when reading Clean Ruby:

  • Learn how to identify bad code and fixed it.
  • Learn how to create quality names for all of your variables, classes and modules.
  • Learn how to create better, concise classes.
  • Learn how to improve the quality of your methods.
  • Learn how to properly use modules.
  • Learn how to improve the clarity of your boolean logic.
  • Learn techniques to improve when and how you refactor.

How will you learn?

This book is filled with tons of code. You will see examples of common mistakes and how to fix them. Each example has been carefully considered based on real-world experience.

You will learn to think differently about your code. Every chapter will make your reconsider past coding decisions. Open your eyes to a new world of Ruby development by reading Clean Ruby.

What makes it ruby specific?

  • All the code examples are written in Ruby. No need to learn a new language.
  • Topics will highlight techniques specific to Ruby.
  • Topics factor in the dynamic nature of Ruby.

About the Author

Carleton DiLeo
Carleton DiLeo

Carleton is a founder, author, and developer who brings nearly two decades of experience working with technology. His expertise includes building high-traffic websites, big data systems, and video games. This wide base of knowledge provides Carleton with a unique perspective when working with Ruby.

Table of Contents

  • Forward
    • Who should read this book?
  • The Qualities of Clean Code
    • Readability
    • Extensibility
    • Simplicity
  • Naming Things
    • Variables
      • Naming conventions
      • The data
      • Length
      • Avoid unnecessary information
      • Avoid conjunctions
      • Only alpha characters
    • Methods
      • Use verbs
      • Return value
      • Bang methods
    • Classes
      • Purpose
      • Role
    • Modules
  • Creating Quality Methods
    • Parameters
      • Use fewer parameters
      • Parameter order
    • Return Values
    • Guard Clause
    • Length
      • How to shorten a method
      • Too short
    • Comments
      • Quality comments
      • Stale comments
      • Comments and refactoring
    • Limit Nesting
  • Using Boolean Logic
    • Using a Variable
    • Using a Method
    • Unless
    • Ternary operator
    • Double negative
    • Truthy and Falsy
      • Truthy Values
      • Falsy Values
    • & vs &&
  • Classes
    • Initialize Method
      • Keep it Simple
      • Avoiding Errors
      • Too many parameters
    • Class methods vs instance methods
    • Instance variables
    • Private methods
    • Method order
    • Moving methods to a module
    • Limiting Inheritance
  • Refactoring
    • No change too small
    • Tests
    • Single Responsibility Principle
  • Test-Driven Development (TDD)
    • Start with tests
    • Implement our code
    • More Tests
    • Clean Tests
  • Wrapping up
  • Notes

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub