Index

Symbols and Numbers

_ (leading underscore), in function names, 386

== operator (Ruby), 255

A

add method (for collections), 170

Add Parameter. See Change Function Declaration

Agile software methods, 63

Algorithms, substituting, 195196, 230, 309

Alternative classes with different interfaces, 83

Ambler, Scott, 70

and logical operator, 264265

Application Programming Interfaces (APIs), refactoring, 126128

Architecture

decaying over time, 47

refactoring and, 6263

testability of, 99

Arrays, sorting, 173

Assertion libraries (Mocha framework), 92

Assertions

applicability of, 302, 304

introducing, 84, 98, 129, 208, 211, 249250, 302304

Assignments

removing to parameters, 112

Assumptions, for values, 302

Automated refactoring tools, 131

B

Babel, 37

Bazuzi, Jay, 60

Beck, Kent, 10, 44, 46, 48, 6567, 71, 77, 8687, 107

Boundary conditions, 97

Branch by abstraction tactic, 54

Brant, John, 68

Budgeting resources, 64

Bugs

finding, 93, 98

during refactoring, 46, 48

time spent on, 8586

fixing, 51, 85

introducing into code, 45, 59, 129

C

C# language, automated refactorings in, 68

C++ language, refactorings in

for framework development, 67

safe, 60

Calculations

repeated, 149151

vs. using variables, 248

Chai assertion library, 92

Change Function Declaration, 1213, 17, 36, 69, 72, 80, 8384, 124131, 141142, 147, 175176, 184, 214, 216, 218, 222, 245246, 253, 286, 310, 312, 325326, 332, 345346, 351352, 366, 376, 379, 403

Change Reference to Value, 76, 169, 175, 183, 185, 252255

Change Signature. See Change Function Declaration

Change Value to Reference, 175, 256258, 402

Chrysler Comprehensive Compensation, 65

Classes

abstract, 80

advantages of, 174

alternative, with different interfaces, 83

as data holders, 83

combining functions into, 74, 7677, 144148, 274, 281, 290, 293

containing their own tests, 85

context of, 198

creating, 142

extracting, 76, 7880, 82, 182185, 186, 199, 253, 319, 376

immutable, 330

inlining, 77, 80, 186188

large, 77, 82, 182

no fields in class definitions of, 354

polymorphic, 126

redundancy in, 82

renaming, 183

vs. transform functions, 144, 149, 153

Clock wrapper, 109

Code

adding functionality to, 46, 50, 53, 56

bad smells in, 7184

alternative classes with different interfaces, 83

comments, 84

data class, 83

data clumps, 78

divergent change, 76

duplicated code, 47, 72

feature envy, 77, 319

global data, 7475

insider trading, 82

large class, 82

lazy element, 80

long function, 7374

long parameter list, 74

loops, 79

message chains, 81

middle man, 81, 192

mutable data, 7576

mysterious name, 72

primitive obsession, 7879

refused bequest, 8384

repeated switches, 79

shotgun surgery, 76

speculative generality, 80

temporary field, 80

bad smells of:

type code, 336

branches of, 5759

cleaning up, 45, 52, 67

communicating what it is doing, 10, 18, 51, 7273, 107, 124125, 137, 260, 263, 267, 302

complexity of, 260

cost of production of, 65

dead, removing, 80, 237, 249250, 295, 320321, 345, 347, 366, 383

dependencies in, 324325, 327, 330

duplicated. See Duplicated code

easy to modify, 45, 43, 45, 47, 49

free of side effects, 75, 225, 306309

improving, 47

internal design of, 4, 49

legacy, 6061, 70, 133

length of, 33, 42

observable behavior of, 4546, 59

ownership of, 57

performance of, 14, 20, 6467

self-testing, 5, 5960, 63, 8587, 302

structure of, 2324, 124, 154155

adding, 272

changing, 46, 140

losing over time, 47

symmetrical, 373

thought as “done”, 53

understanding, 4, 7, 24, 33, 43, 45, 4748, 51, 54, 60, 119, 198, 207, 223, 244, 315, 327

Code analysis tools, 315

Code reviews, 54

Collapse Hierarchy, 80, 380

Collecting variables, 240

Collection pipelines, 171, 231236

Collections

empty, 96

encapsulating, 163, 169, 170173

immutable, 171

modifier methods for, 170

Combine Functions into Class, 74, 7677, 144148, 153, 199, 274, 281, 290, 293

Combine Functions into Transform, 7677, 144, 149153, 290, 297300

Command pattern, 338

Command-query separation principle, 225, 306, 338

Commands (command objects), 337343

naming, 338

replaced with functions, 344347

Comments, 84

for assumptions, 302

for dead code, 237

signaling code to extract, 73, 84, 107

turning into names, 125

Compilers

chain of phases in, 155

removing dead code in, 237

Compile-test-commit cycle, 9, 37

Compiling

after each change, 8

checks during, 108

Conditionals

consolidating, 263265, 267, 270

decomposing, 260262, 315318

nested, 264270

replacing with:

guard clauses, 266271

polymorphism, 3941, 79, 272288, 359, 363, 366

reversing, 269270

signaling code to extract, 74

sliding statements with, 226

symmetrical, 373

Consolidate Conditional Expression, 263265, 267, 270

Consolidate Duplicate Conditional Fragments. See Slide Statements

const keyword (JavaScript), 94, 242

Constants

creating, 242

renaming, 138139

Constructors

manipulating fields in, 331

naming, 334

pulling up body of, 355358, 376

replacing with factory functions, 39, 334336, 356, 363364, 370371, 382, 385

Continuous Delivery (CD), 60, 64

Continuous Integration (CI), 5860, 63

Coupling

between sub- and superclasses, 400

reducing, 125

removing, 330

Cunningham, Ward, 7, 51, 67

D

Data

clumps of, 78, 140

derived, 149153

detecting changes to, 135

duplicated, 249

encapsulating, 132136

global, 7475, 258

immutable, 133, 148, 153, 162

mutable, 7576, 132, 151, 162, 170, 248

Data classes, 83

Data structures, 162169

accessing, 223

copying, 169

immutable, 247, 252255

importance of, 207, 244

multiple copies of, 256

nested, 252

read-only proxy for, 168

updating, 167, 256

when to change, 207

Data transformation functions. See Transform functions

Databases, refactoring, 61, 70

Date.now method, 109

Dead code, removing, 80, 237, 249250, 295, 320321, 345, 347, 366, 383

Debugging

making easier, 48, 51

reducing, 5, 49

time spent on, 85

using:

assertions, 302, 304

variables, 119

Decompose Conditional, 260262, 315318

Deep copies, 168

Delegates

hiding, 8182, 189191, 192, 203

replacing:

subclasses with, 381398

superclasses with, 399404

Delegation, 81

unnecessary, 80, 115

vs. inheritance, 382, 389

Dependencies, in code, 324325, 327, 330

Derived variables, 75, 248251

Design stamina hypothesis, 50

Divergent change, 76

Duplicated code, 47, 72, 82, 213, 249

for common behavior, 289

for derived data, 149151

for fields, 353, 376, 378, 380

for methods, 350

for validation checks, 98

in tests, 94

replacing with function calls, 222, 310313

searching for, 108

E

Eclipse IDE, 6869

else statement, 267

Emacs text editor

macros in, 69

running tests in, 93

Encapsulate Collection, 163, 169, 170173

Encapsulate Field. See Encapsulate Variable

Encapsulate Record, 83, 133, 145146, 162169, 210, 245

Encapsulate Variable, 75, 132136, 137138, 163164, 166, 171, 175, 193194, 249, 364

Encapsulation, 81

applicability of, 189

Equality testing, 254255

equals method, 254

equals method (Object), 255

Errors

explicit vs. from a default branch, 40

using assertions for, 302, 304

vs. failures, 98

Evolutionary architecture, 63

execute method, 340

Expand-contract pattern, 61

Explicit methods, replacing parameters with, 314318

Expressions

complex, 119122

names for, 119

Extensible Markup Language (XML), 163

Extract Class, 76, 7880, 82, 182185, 186, 199, 253, 319, 376

inversed. See Inline Class

Extract Function, 7, 1920, 24, 69, 7277, 81, 8384, 106114, 119, 126, 128, 130, 145147, 150152, 155156, 167, 181, 214215, 218219, 223224, 228229, 261, 263265, 273, 283284, 290, 292, 296, 299, 302, 304, 322, 325, 328329, 342, 344345, 356, 370372, 376, 388

automated, 9

inversed. See Inline Function

vs. Extract Variable, 122

Extract Method. See Extract Function

Extract Subclass. See Replace Type Code with Subclasses

Extract Superclass, 8283, 375379, 383, 395

Extract Variable, 119122, 130, 322, 328329, 345346

inversed. See Inline Variable

vs. Extract Function, 122

Extreme Programming (XP), 60, 63, 67

F

Factory functions, 275, 282

replacing constructors with, 334336, 356, 363364, 370371, 382, 385

returning superclass, 389

Failures

getting information about, 92

intermittent, 94

vs. errors, 98

Feathers, Michael, 70

Feature envy, 77, 319

Fields

duplicated in subclasses, 353, 376, 378, 380

encapsulating, 133, 364

immutable, 83, 331

moving, 77, 82, 183184, 188, 207212

naming, 137

persistent, 137

public, 83, 133

pulling up, 351, 353354, 376, 378, 380

pushing down, 83, 361, 363, 380

renaming, 72, 244247, 354

replacing subclasses with, 369374

self-encapsulating, 176, 193194, 209

temporary, 80

Fields, Jay, 70

Flag arguments, removing, 74, 314318

Foote, Brian, 80

Form Template Method, 351

Function as Object pattern, 145

Functional programming, 75

Functions

changing declaration of, 36, 124131, 253, 310, 312, 325326, 332, 345346, 351, 366, 376, 403

combining into:

classes, 74, 7677, 144148, 153, 199, 274, 281, 290, 293

transforms, 7677, 144, 149153, 290, 297300

communicating with functions from another module, 77, 198, 319

creating, 322

decomposing, 73, 196

delegating, 38, 203

deprecated, 126, 128

encapsulating, 337

explicit, replacing parameters with, 315316

extracting, 711, 21, 69, 7277, 81, 8384, 106114, 119, 126, 128, 130, 145147, 150152, 155156, 167, 181, 214215, 218219, 223224, 228229, 261, 263265, 273, 283284, 290, 292, 296, 299, 302, 304, 322, 325, 328329, 342, 344345, 356, 370372, 376, 388

after inlining, 115

factory, 275, 282, 334336, 356, 363364, 370371, 382, 385, 389

inlining, 38, 77, 8081, 115118, 126, 128130, 188, 193194, 199, 214, 216, 218220, 290, 294, 320321, 328329, 332333, 345347

when to avoid, 138

long, 7374, 77, 106, 260, 338343

decomposing, 622, 51, 178

matching up, 83

moving, 27, 37, 7683, 108, 145146, 148, 151, 167, 183184, 187, 198206, 323, 338339, 370, 372, 383, 387, 391394

between classes, 204206

to the top level, 200204

naming, 7, 18, 21, 73, 106107, 124, 130, 151, 222, 260, 284, 320

nested, 2223, 108, 114, 145, 179, 200204, 343

parameterizing, 51, 62, 310313, 351

parameters of:

adding, 127, 128129, 141142

changing, 129131

choosing, 125

flags, 74, 314318

length of lists of, 73, 74, 319, 324

removing, 126127, 143, 324326

referential transparency of, 327, 330

removing, 40

renaming, 21, 57, 69, 72, 80, 84, 125, 125, 127128, 130, 147, 175176, 184, 201, 203204, 214, 216, 218, 221222, 245246, 286, 321, 352, 379

replaced with commands, 73, 337343

replacing:

commands, 344347

inline code, 108, 222

restricting visibility of, 204

returning a value, 225, 306309

short, 106107, 137

side effects in, 225, 306309

syntax errors in, 37

testing, 145

using instead of variables, 178179

varying behavior of, 217221

wrapping, 315, 318

See also Methods

G

Gamma, Eric, 86

Gang of Four, 67, 77

Generalization hierarchy, 278

Getters

naming, 134, 138, 176

returning a copy of data, 135, 171

Git version control system, 9

Global data, 7475, 258

mutable, 75

Graphical test runners, 93

Guard clauses, 266271

H

Harold, Elliotte Rusty, 70

Harvey, Shane, 70

hashcode method (Object), 255

Hashmaps, 162

Hide Delegate, 8182, 189191, 192

inversed. See Remove Middle Man

Hierarchy

changing, 8384

collapsing, 80, 380

Hypertext Markup Language (HTML), refactoring, 70

I

if statement, 267

nested, 264265

Immutability, 151, 162, 331

Immutable fields, 83

Incremental design, 63

Indirection, needless, 115

Inheritance, 82, 381382, 385

code logic and, 278287

indirect, 366368

planned in advantage, 376

vs. delegation, 382, 389

when to avoid, 399400

Inline Class, 77, 80, 186188

inversed. See Extract Class

Inline code, replacing with function calls, 108, 222

Inline Function, 38, 77, 8081, 115118, 126, 128130, 188, 193194, 199, 214, 216, 218220, 290, 294, 320321, 328329, 332333, 345347

inversed. See Extract Function

Inline Method. See Inline Function

Inline Temp. See Inline Variable

Inline Variable, 11, 14, 1920, 123, 130, 147, 152153, 181, 293, 328, 372

inversed. See Extract Variable

Input parameters, 242

Insider trading, 82

Instance variables, 82

Integrated Development Environments (IDEs)

refactoring capabilities in, 69

renaming functions automatically in, 127

running tests in, 92

IntelliJ IDEA, 6869

Interfaces

adjusting after extracting a class, 183

marking as deprecated, 57

published, 57

Intermittent failures, 94

Introduce Assertion, 84, 98, 129, 208, 211, 249250, 302304

Introduce Explaining Variable. See Extract Variable

Introduce Null Object. See Introduce Special Case

Introduce Parameter Object, 7374, 7879, 140143, 145, 319

Introduce Special Case, 81, 289301

J

Java language

accessing collections in, 171

automated refactorings in, 6869

constructors in, 334

equality testing in, 255

running tests in, 92

JavaScript language

accessing properties in, 389

constants in, 94

constructors in, 364

dynamic typing in, 291

error messages in, 98

exported variables in, 139

function visibility in, 204

getters and setters in, 134

mutability in, 148, 330

nested functions in, 343

no value-based references in, 254

polymorphism in, 278

restricting visibility of variables in, 134

self-references in, 319

shallow copies in, 27

sorting arrays in, 173

subclasses in, 291

JavaScript Object Notation (JSON), 163

Jeffries, Ron, 66

JetBrains, 68

Johnson, Ralph, 67

JUnit framework, 86

K

Kerievsky, Joshua, 70, 269

L

Language servers, 70

Large classes, 82

Law of Demeter, the, 192

Lazy elements, 80

Legacy code, 6061, 70

encapsulating data in, 133

Libraries, changing gradually, 5354

List-and-hash data structure, 168

Lists, 163

inheritance and, 399

returning a copy of, 135

Literal objects, 295

Local variables

advantages of, 119

passed as parameters, 108, 110111

reassigning, 108, 112114

Lodash library, 168

Long functions, 7374, 77, 106, 260, 338343

decomposing, 622, 51, 178

Long parameter lists, 73, 74, 319, 324

Loops, 79

repeating, 20

replacing with pipeline, 30, 79, 230, 231236, 372

signaling code to extract, 74

splitting, 21, 74, 227230

M

Managers, justifying refactoring for, 5455

Mercurial tool, 9

Message chains, 81

Methods

duplicated in subclasses, 350

explicit, replacing parameters with, 315316

getting. See Getters

polymorphic, 116, 126

pulling up, 72, 350352, 356, 358, 376380

pushing down, 83, 359360, 363, 366, 380

setting. See Setters

See also Functions

Middle man, 81

removing, 192194

Mocha framework, 9092

Modifiers, separating from queries, 75, 179, 264, 306309

Modularity, 33, 49, 198

Modules

reducing coupling of, 125

referential transparency of, 327, 330

splitting, 154159

structuring, 82

Monetary values, storing as integers, 18

Move Field, 77, 82, 183184, 188, 207212

Move Function, 27, 37, 7683, 108, 145146, 148, 151, 167, 183, 187, 198206, 323, 338339, 370, 372, 383, 387, 391394

Move Method. See Move Function

Move Statements into Function, 213216

Move Statements to Callers, 117118, 155, 213, 217221, 285

Mutable data, 7576

encapsulating, 170

objects vs. records for, 162

Mysterious names, 72

N

Names

communicating what things are doing, 7, 10, 18, 51, 7273, 107, 124125, 137, 260, 284

deep design issues and, 72

temporary, 130

new operator, 334

NodeJS console, 91

now method (Date), 109

Null Object. See Introduce Special Case

O

Object-oriented languages

equality testing in, 255

inheritance mechanism in, 381

polymorphism in, 273

Objects

benefits of, 122

creating by creation script, 331

equality testing for, 254255

for mutable data, 162

initializing, 334

nested, 252

preserving whole, 7374, 78, 319323

replacing primitive types with, 79, 174177, 363, 367

Opdyke, Bill, 67

or logical operator, 264265

Overloaded getter setter practice, 134

P

Paracelsus, 75

Parallel change pattern, 61

Parameter lists, length of, 73, 74, 319, 324

Parameter objects

introducing, 7374, 7879, 140143, 145, 319

preserving whole, 7374, 78, 319323

Parameterize Function, 51, 62, 310313, 351

Parameterize Method. See Parameterize Function

Parameters

adding, 62, 127, 128129, 141142

changing, 129131

choosing, 125

extracting, 322

naming, 10, 137

removing, 1213, 126127, 143

replacing with queries, 74, 324326

unneeded, 80

Performance

accessing collections and, 171

improving, vs. cost of production, 65

large data structures and, 169

measuring, 6566

multiple copies of data and, 256

optimizing, 46, 6667

refactoring and, 14, 20, 6467, 228

Phases, splitting, 7677, 83, 154159

Pipelines, replacing loops with, 30, 230, 231236, 372

Polymorphism, 34, 3841, 79

changing methods/classes with, 126

replacing conditionals with, 3941, 79, 272288, 363, 366

Preserve Whole Object, 7374, 78, 319323

Primitive obsession, 7879

Primitive types, replacing with objects, 79, 174177, 363, 367

Productivity

and code base health, 55

and refactoring, 4850, 56, 67

and running tests, 86, 100

and writing tests, 100

Programming

functional, 75

object-oriented. See Object-oriented languages

productivity of, 4850

Programs. See Code

protected keyword, 354

Proxies, for data structures, 168

Public fields, 83, 133

Pull Up Constructor Body, 354, 355358, 376

Pull Up Field, 351, 353354, 376, 378, 380

Pull Up Method, 72, 350352, 356, 358, 376380

Push Down Field, 83, 361, 363, 380

Push Down Method, 83, 359360, 363, 366, 380

Q

Queries

replaced with parameters, 327330

replacing:

parameters, 74, 324326

temps, 178181, 325

separating from modifiers, 75, 179, 264, 306309

R

Records

changing, 210

encapsulating, 83, 133, 145146, 162169, 210, 245

nested, 165169

Refactoring

automated tools for, 131

comprehension, 51

definition of, 4546

embedded into code reviews, 54

exercises to practice, 70

first step in, 5

fitting into workflow, 50, 6364

impacting software architecture, 6263

in small steps, 8, 2021, 44, 46, 59, 102, 245

litter-pickup, 52

long-term, 53

of databases, 61, 70

of legacy code, 6061, 70

performance and, 14, 20, 6467, 228

planned vs. opportunistic, 5253

preparatory, 50, 56

preserving observable behavior of code, 4546, 59, 67, 98

productivity and, 4850, 56, 67

reasons to perform, 5, 4344, 4750, 5657

separating from optimization, 6467, 228

when to avoid, 55

when to do, 5055, 7184

Refactoring Browser (Smalltalk), 68

Refactorings

automated, 9, 59, 6870, 194

catalog of, 101103

definition of, 45

naming, 101

References

changing to values, 76, 169, 175, 183, 185, 252255

changing values to, 175, 256258, 402

Referential transparency, 327, 330

Refused bequest, 8384

remove method (for collections), 170

Remove Assignments to Parameters. See Split Variable

Remove Dead Code, 80, 237, 249250, 295, 320321, 345, 347, 366, 383

Remove Flag Argument, 74, 314318

Remove Middle Man, 81, 192194

inversed. See Hide Delegate

Remove Parameter. See Change Function Declaration

Remove Setting Method, 75, 83, 171, 173, 253, 255, 331333

Remove Subclass, 369374

inversed. See Replace Type Code with Subclasses

Rename Field, 72, 244247, 354

Rename Function, Rename Method. See Change Function Declaration

Rename Variable, 72, 137139

Repeated switches, 79

Repetitive code. See Duplicated code

Replace Command with Function, 344347

Replace Conditional with Polymorphism, 34, 39, 79, 272288, 359, 363, 366

Replace Constructor with Factory Function, 39, 334336, 356, 363364, 370371, 382, 385

Replace Constructor with Factory Method. See Replace Constructor with Factory Function

Replace Data Value with Object. See Replace Primitive with Object

Replace Derived Variable with Query, 75, 248251

Replace Function with Command, 73, 337343

Replace Inheritance with Delegation. See Replace Superclass with Delegate

Replace Inline Code with Function Call, 108, 222

Replace Loop with Pipeline, 30, 79, 230, 231236, 372

Replace Method with Method Object. See Replace Function with Command

Replace Nested Conditional with Guard Clauses, 266271

Replace Parameter with Explicit Methods. See Remove Flag Argument

Replace Parameter with Method. See Replace Parameter with Query

Replace Parameter with Query, 74, 324326

Replace Primitive with Object, 79, 174177, 363, 367

Replace Query with Parameter, 327330

Replace Subclass with Delegate, 8182, 84, 381398

Replace Subclass with Fields. See Remove Subclass

Replace Superclass with Delegate, 8182, 84, 376, 399404

Replace Temp with Query, 11, 19, 73, 108, 114, 119, 178181, 325

Replace Type Code with Class. See Replace Primitive with Object

Replace Type Code with State/Strategy. See Replace Type Code with Subclasses

Replace Type Code with Subclasses, 38, 79, 82, 362368

inversed. See Remove Subclass

Repository objects, 257

Resharper plug-in, 68

Responsibility, shifting, 324, 327328

Restructuring, 46

Roberts, Don, 50, 68

Ruby language

equality testing in, 255

refactoring in, 70

Rule of three, the, 50

S

Sadalage, Pramod, 61, 70

Self Delegation tactic, 77

Self-Encapsulate Field. See Encapsulate Variable

Self-encapsulation, 133, 364

Self-references, 319

Separate Query from Modifier, 75, 179, 264, 306309

Setters

naming, 134, 176

removing, 75, 83, 171, 173, 253, 255, 331333

returning a copy of data, 135136

Shallow copies, 27

Shotgun surgery, 76

Side effects, 75, 225, 306309

Simple design, 63

Slide Statements, 1820, 72, 75, 112, 210, 214, 217, 223226, 229, 356357

See also Swap Statement

Smalltalk, 67

Refactoring Browser, 68

subclass responsibility errors in, 352

using short methods in, 107

Smells. See Code, bad smells in

Software. See Code

Special cases, introducing, 81, 289301

Speculative generality, 80

Split Loop, 18, 20, 74, 227230

Split Phase, 24, 7677, 83, 154159

Split Temp. See Split Variable

Split Variable, 75, 108, 112, 114, 225, 240243, 249250

State design pattern, 382

Statements

moving:

into functions, 213216

to callers, 117118, 155, 213, 217221, 285

sliding, 72, 75, 112, 210, 214, 217, 223226, 229, 356357

Static typing, 127

Strategy design pattern, 77, 382

Subclass responsibility errors, 352

Subclasses

creating, 3839, 282

duplicated code in, 72

overriding methods in, 116, 282

pulling up:

fields, 353354, 376, 378, 380

methods, 350352, 358, 376380

refusing implementations, 84

replacing:

type code with, 79, 82, 362368

with delegates, 8182, 84, 381398

with fields, 369374

Substitute Algorithm, 195196, 230, 309

Superclasses

defining constructors for, 356

extracting, 8283, 375379, 383, 395

pushing down:

fields, 361, 363, 380

methods, 359360, 363, 366, 380

replacing with delegates, 8182, 84, 376, 399404

role of, 278

with interfaces not supported in subclasses, 84

Swap Statement, 226

See also Slide Statements

Switches

repeated, 79

signaling code to extract, 74

System clock, calls to, 109

T

Teardown, 95

Telephone numbers

adding logic to, 174

behavior of, separated into a class, 183185

formatting, 125

programming for, 253255

Temporary fields, 80

Temporary variables (temps), 16

replacing with queries, 73, 108, 114, 119, 178181, 325

Test coverage analysis, 99

Test-Driven Development, 87

Tests, 85100

adding to legacy code, 60

affecting productivity, 86, 100

choosing how many to write, 93, 98, 100

duplicated code in, 94

evolving over time, 99

failing, 21

intermittently, 94

where they should, 9192, 99

for boundary conditions, 97

for setters, 95

importance of, 5

in IDE, 92

nondeterministic, 94, 109

running:

after each change, 8

frequently, 86, 92

self-checking, 5, 5960, 63, 8587, 302

teardown between, 95

unit, 99, 302

this keyword (JavaScript), 319

Thomas, Dave, 85

Transform functions, 7677, 149153

vs. classes, 144, 149, 153

Trunk-Based Development, 58

Type code

passing as a literal string, 336

replacing with:

classes, 174177

subclasses, 79, 82, 362368

Type-instance homonym, 400

U

undefined property (JavaScript), 389

Underscore (_), in function names, 386

Understanding code, 4, 7, 24, 33, 43, 45, 4748, 51, 54, 119, 223

and flag arguments, 315

growing over time, 198, 327

importance of data structures for, 207, 244

in legacy systems, 60

removing dead code for, 237

Uniform Access Principle (UAP), 147

Unit tests, 99, 302

V

Validation checks, 98

Value objects, 141, 185, 252255

Values

changing references to, 76, 169, 175, 183, 185, 252255

changing to references, 175, 256258, 402

encapsulating, 135

free of side effects, 225, 306309

immutable, 162

self-references to, 319

Variables, 240

bundling in a class, 82

declared as input parameters, 242

declaring/initializing, 21, 223, 241

derived, 75, 248251

encapsulating, 75, 132136, 137138, 163164, 166, 171, 175, 249

extracting, 119122, 130, 322, 328329, 345346

global, 133

highlighting in text editors, 241

immutable, 120, 123, 241242

inlining, 11, 14, 19, 21, 123, 130, 147, 152153, 181, 293, 328, 372

instance, 82

local, 108, 110114

naming, 119, 137138

out-of-scope, 108

passed by value, 108, 112114

references to, 137138

removing, 1014

renaming, 910, 16, 22, 51, 69, 72, 134, 137139, 241

replacing with:

declared functions, 1618

queries, 75, 248251

restricting visibility of, 134

scope of, 78, 11

splitting, 75, 108, 114, 225, 240243, 249250

temporary, 16

useful for debugging, 119

Version control systems

committing:

after each refactoring, 9

separately for refactorings and feature additions, 53

retrieving deleted code in, 237

working on branches in, 5759

Visitor design pattern, 77

Visual Studio, refactoring in, 68

W

Wake, Bill, 70

Wrapping functions, 315, 318

X

XML (Extensible Markup Language), 163

Y

Yagni (“you aren't going to need it”), 6364