Home > Store

Refactoring in Ruby (Rough Cuts)

Rough Cuts

  • Available to Safari Subscribers
  • About Rough Cuts
  • Rough Cuts are manuscripts that are developed but not yet published, available through Safari. Rough Cuts provide you access to the very latest information on a given topic and offer you the opportunity to interact with the author to influence the final publication.

Not for Sale

Description

  • Copyright 2009
  • Dimensions: 7 X 9-1/8
  • Pages: 288
  • Edition: 1st
  • Rough Cuts
  • ISBN-10: 0-321-64792-0
  • ISBN-13: 978-0-321-64792-4

This is a working draft of a pre-release book. It is available before the published date as part of the Rough Cuts service.

The First Hands-On, Practical, All-Ruby Refactoring Workbook!

 

Refactoring–the art of improving the design of existing code–has taken the world by storm. So has Ruby. Now, for the first time, there’s a refactoring workbook designed from the ground up for the dynamic Ruby language.

Refactoring in Ruby gives you all the realistic, hands-on practice you need to refactor Ruby code quickly and effectively. You’ll discover how to recognize “code smells,” which signal opportunities for improvement, and then perfect your program’s design one small, safe step at a time.

The book shows you when and how to refactor with both legacy code and during new test-driven development, and walks you through real-world refactoring in detail. The workbook concludes with several applications designed to help practice refactoring in realistic domains, plus a handy code review checklist you’ll refer to again and again. Along the way, you’ll learn powerful lessons about designing higher quality Ruby software–lessons that will enable you to experience the joy of writing consistently great code.

Refactoring in Ruby will help you

  • Recognize why poor code design occurs, so you can prevent it from occurring in your own code
  • Master better design techniques that lead to more efficient, reliable, and maintainable software
  • Fix code that’s too long, large, or difficult to follow
  • Ferret out duplication, and express each idea “once and only once”
  • Recognize missing or inadequately formed classes
  • Simplify overly complex relationships between classes and their subclasses
  • Achieve the right balance of responsibilities among objects
  • Make your code easier to test and change
  • Cope with incomplete library modules, and fix runaway dependencies
  • Learn the next steps to take after you refactor

Sample Content

Table of Contents

Foreword xvii

Preface xix

About the Authors xxiii

Part I: The Art of Refactoring 1

 

Chapter 1: A Refactoring Example 3

Sparkline Script 3

Consistency 6

Testability 8

Greedy Methods 8

Greedy Module 9

Comments 10

Whole Objects 11

Feature Envy 12

Uncommunicative Names 14

Derived Values 15

Wabi-Sabi 17

Summing Up 18

What’s Next 18

Chapter 2: The Refactoring Cycle 19

What Is Refactoring? 19

Smells Are Problems 20

The Refactoring Cycle 21

When Are We Done? 21

Test-Driven/Behavior-Driven Development 22

Exercise 23

What’s Next 23

Chapter 3: Refactoring Step by Step 25

The Refactoring Environment 25

Inside a Refactoring 26

The Generic Refactoring Micro-Process 30

Exercises 33

What’s Next 33

Chapter 4: Refactoring Practice 35

Read Other Books 35

Practice Refactoring 35

Exercises to Try 36

Participate in the Community 37

Exercise 38

What’s Next 38

Part II: Code Smells 39

 

Chapter 5: Measurable Smells 41

Comments 42

Long Method 44

Large Module 46

Long Parameter List 48

Exercises 49

Chapter 6: Names 57

Type Embedded in Name 59

Uncommunicative Name 60

Inconsistent Names 61

Exercises 62

Chapter 7: Unnecessary Complexity 65

Dead Code 66

Speculative Generality 68

Greedy Method 70

Procedural Code 72

Dynamic Code Creation 74

Exercises 76

Chapter 8: Duplication 79

Derived Value 80

Repeated Value 81

Duplicated Code 83

Alternative Modules with Different Interfaces 85

Exercises 86

Chapter 9: Conditional Logic 93

Nil Check 94

Special Case 96

Complicated Boolean Expression 98

Control Coupling 100

Simulated Polymorphism 101

Updates

Submit Errata

More Information