Skip to main content
main-content

Über dieses Buch

Learn how to make better decisions and write cleaner Ruby code. This book shows you how to avoid messy code that is hard to test and which cripples productivity. Author Carleton DiLeo shares hard-learned lessons gained from years of experience across numerous codebases both large and small. Each chapter covers the topics you need to know to make better decisions and optimize your productivity. Many books will tell you how to do something; this book will tell you why you should do it. Start writing code you love.

What You Will Learn

Build better classes to help promote code reuse Improve your decision making and make better, smarter choicesIdentify bad code and fixed itCreate quality names for all of your variables, classes, and modules Write better, concise classesImprove the quality of your methodsProperly use modules Clarify your Boolean logic See when and how you refactorImprove your understanding of TDD and write better tests

Who This Book Is For

This book is written for Ruby developers. There is no need to learn a new language or translate concepts to Ruby.

Inhaltsverzeichnis

Frontmatter

Chapter 1. The Qualities of Clean Code

Abstract
So what is clean code? If you ask three different developers, you will get three different answers. It’s a hard concept to define. You know clean code when you see it, as if written by a programming wizard from a distant land. We all want to write good code that others admire. Sometimes we don’t know where to start. How do we take our messy, unorganized code and turn it into something beautiful?
Carleton DiLeo

Chapter 2. Naming Things

Abstract
Coming up with names for the variables, classes, and methods in a program is not an easy task. We must be gurus to think of a name at a moment’s notice. It’s part of our everyday coding lives, and we can’t let down our guard. Choosing the wrong name has significant implications and can determine whether code is easy to read or confusing and cryptic. It doesn’t end there, because poor-quality names have a compounding effect. One bad name encourages creating more bad names; those bad names promote even more bad names. Progress crawls to a halt because these bad names make our code impossible to understand.
Carleton DiLeo

Chapter 3. Creating Quality Methods

Abstract
A method is the smallest block of code in an application. Methods can be reused, which helps prevent duplication. A method hides the details of an operation, so refactoring will not affect the calling code. This takes careful planning to achieve. In this chapter, we will discuss different techniques used to create quality methods: parameters, return values, guard clauses, length, comments, and nesting.
Carleton DiLeo

Chapter 4. Using Boolean Logic

Abstract
Software consists mostly of testing data and determining whether certain conditions are true or false. Every program makes thousands of these decisions. Since boolean logic is so vital to an application, it’s important to take care when programming them. A single boolean statement is easy to understand, but complex logic with two or more boolean statements can be hard to understand, making it hard to maintain and the source of bugs. Even small improvements to boolean logic can help prevent misunderstandings. In this chapter, we will discuss different techniques you can use. Each method has pros and cons. Check each option before choosing the one correct for a situation.
Carleton DiLeo

Chapter 5. Classes

Abstract
In this chapter, we cover several techniques you can use to make high-quality classes.
Carleton DiLeo

Chapter 6. Refactoring

Abstract
Every new application starts with the purest intentions. A new codebase means an opportunity to create simple, clean code and avoid past mistakes. Even with our best efforts, deadlines and platform constraints will impede these goals and give way to suboptimal solutions and hacks. It’s not anyone’s fault, it’s just something developers do.
Carleton DiLeo

Chapter 7. Test-Driven Development (TDD)

Abstract
Test-driven development is a scary topic for many new developers, but the concepts are simple. Once you get the hang of TDD, the benefits become clear. Your code will be simpler, cleaner, and easier to refactor. With TDD, we only write the code we need to write, and avoid adding unnecessary fluff. It will no longer be a scary prospect to make changes to your code. You have tests to verify that your changes won’t break existing code. If something goes wrong, you’ll know where the break occurred.
Carleton DiLeo

Backmatter

Weitere Informationen

Premium Partner

    Bildnachweise