0%

Book Description

Discover various techniques to develop maintainable code and keep it in shape.

Key Features

  • Learn all about refactoring - why it is important and how to do it
  • Discover easy ways to refactor code with examples
  • Explore techniques that can be applied to most other programming languages

Book Description

Refactoring improves your code without changing its behavior. With refactoring, the best approach is to apply small targeted changes to a codebase. Instead of doing a huge sweeping change to your code, refactoring is better as a long-term and continuous enterprise. Refactoring TypeScript explains how to spot bugs and remove them from your code.

You'll start by seeing how wordy conditionals, methods, and null checks make code unhealthy and unstable. Whether it is identifying messy nested conditionals or removing unnecessary methods, this book will show various techniques to avoid these pitfalls and write code that is easier to understand, maintain, and test.

By the end of the book, you'll have learned some of the main causes of unhealthy code, tips to identify them and techniques to address them.

What you will learn

  • Spot and fix common code smells to create code that is easier to read and understand
  • Discover ways to identify long methods and refactor them
  • Create objects that keep your code flexible, maintainable, and testable
  • Apply the Single Responsibility Principle to develop less-coupled code
  • Discover how to combine different refactoring techniques
  • Learn ways to solve the issues caused by overusing primitives

Who this book is for

This book is designed for programmers who are looking to explore various refactoring techniques to develop healthy and maintainable code. Some experience in JavaScript and TypeScript can help you easily grasp the concepts explained in this book.

Table of Contents

  1. Preface
    1. About the Book
      1. About the Author
      2. Learning Objectives
      3. Audience
      4. Approach
  2. Chapter 1
  3. Introduction
    1. About TypeScript
      1. What Is It?
      2. What's All the Fuss About?
      3. TypeScript versus JavaScript
      4. Why I Chose TypeScript for This Book
    2. What Is Refactoring?
      1. Let's Define It
      2. Our Approach
      3. Design Patterns
    3. Why Refactor at All?
      1. Slow Development
      2. Saving Money
      3. Navy SEALS Get It
      4. Being a Craftsman
      5. Case Study #1
      6. Case Study #2
    4. When Should I Refactor?
      1. The Boy Scout Rule
      2. Repetitive Work
      3. Difficulty Adding Features
      4. In the End
  4. Chapter 2
  5. Null Checks Everywhere!
    1. Identification
      1. Billion-Dollar Mistake
      2. Example
      3. Is It That Bad?
      4. Non-Nullable Types
    2. Null Object Pattern
      1. Empty Collections
      2. Fixing It Up
      3. Take 2
      4. What About Objects?
    3. Special Case Pattern
      1. Situation
      2. An Order Class That Needs to Be Refactored
      3. Refactoring the Order Class
  6. Chapter 3
  7. Wordy Conditionals
    1. Identification
      1. A Little Bit of This, a Little Bit of That
      2. Misbehaving Conditionals
    2. Combining Conditionals
      1. Situation
      2. The Code
      3. Guideline
    3. Extracting Methods from Conditionals
      1. What's Wrong Here?
      2. The Fix
    4. Extracting Conditional Logic to Explicit Classes
      1. Let's Get Classy
      2. SRP
      3. Using It
    5. Pipe Classes
      1. Your Classes Might Be Doing Too Much...
      2. Piping Our Logic
      3. Bonus Refactor
  8. Chapter 4
  9. Nested Conditionals
    1. Identification
      1. A Monster
      2. A Closer Look
    2. Guard Clauses
      1. Scenario
      2. Fail Fast
      3. Fixing It Up
    3. Gate Classes
      1. Scenario
      2. Gate Classes to the Rescue
      3. Useful for Web APIs
  10. Chapter 5
  11. Primitive Overuse
    1. Identification
      1. What's Wrong Here?
    2. Value Objects
      1. Scenario
      2. Initial Refactor
      3. Addressing Primitives
      4. Creating Our Object
      5. Moving Along
      6. Immediate Validation
    3. Deceptive Booleans
      1. Scenario
      2. New Business Rules
      3. More Rules...
      4. Is It Really That Bad?
      5. Just Use Enums
      6. Strategy Pattern
  12. Chapter 6
  13. Lengthy Method Signatures
    1. Identification
      1. The Slippery Slope of Optional Parameters
      2. The Issue
      3. Guidelines
    2. Creating a Reusable Private Method
      1. A Simple Example
      2. Creating Semantically Meaningful Methods
      3. A Brief Look at Some Advanced Solutions
    3. Extracting Data Objects
      1. Extraction
  14. Chapter 7
  15. Methods That Never End
    1. Identification
      1. When Is a Method Too Long?
    2. Give It a Name
    3. Being Strategic
  16. Chapter 8
  17. Dumping Grounds
    1. Identification
      1. Object-Oriented?
      2. The Great Debate
      3. Coupling
      4. Warning Sign
    2. One of These Things Is Not Like The Others
      1. You Have Mail
      2. Breaking It Up
      3. Keep Separate Things Separate
    3. Speak or Listen
      1. CQRS
      2. Read and Write
      3. Next Steps
      4. Commands
      5. Queries
      6. Conclusion
      7. A Word of Caution
  18. Chapter 9
  19. Messy Object Creation
    1. Identification
    2. Factory Functions
      1. Functions versus Static Methods
    3. Combining Refactoring Techniques
      1. Complexity Remains...
      2. Building It
      3. The Builder Pattern
      4. One Last Improvement
  20. Chapter 10
  21. Conclusion
    1. This Is Just The Beginning!
18.208.172.3