└── Code
├── Chapter 07 Naming
├── 7.12 Converting Plural Classes to Singular
│ ├── plural.sc
│ ├── singular.sc
│ ├── plural.scala
│ ├── singular.scala
│ └── README.md
├── 7.06 Renaming Long Names
│ ├── context.java
│ ├── longName.java
│ └── README.md
├── 7.08 Correcting Spelling Mistakes
│ ├── mispell.js
│ ├── spellcheck.js
│ └── README.md
├── 7.03 Renaming MyObjects
│ ├── myWindow.cs
│ ├── salesWindow.cs
│ └── README.md
├── 7.18 Avoiding Data Naming
│ ├── data.js
│ ├── entity.js
│ └── README.md
├── 7.13 Removing Collection from Names
│ ├── customers.js
│ ├── customerCollection.js
│ └── README.md
├── 7.04 Renaming the Result
│ ├── insdictinct.js
│ ├── goodNames.js
│ └── README.md
├── 7.15 Renaming Arguments According to Role
│ ├── first.py
│ ├── roles.py
│ └── README.md
├── 7.04 Renaming Result Variables
│ ├── result.js
│ ├── blockchain.js
│ └── README.md
├── 7.09 Removing Class Name from Attributes
│ ├── prefix.java
│ ├── contextual.java
│ └── README.md
├── 7.10 Removing the First Letter from Classes and Interfaces
│ ├── prefixes.java
│ ├── real names.java
│ └── README.md
├── 7.07 Renaming Abstract Names
│ ├── realNames.php
│ ├── abstractNames.php
│ └── README.md
├── 7.01 Expanding Abbreviations
│ ├── short.go
│ ├── declarative.go
│ └── README.md
├── 7.16 Removing Redundant Parameter Names
│ ├── sayitonce.cr
│ ├── redundant.cr
│ └── README.md
├── 7.05 Renaming Variables Named After Types
│ ├── type coupling.java
│ ├── role coupling.java
│ └── README.md
├── 7.02 Renaming and Breaking Helpers and Utils
│ └── JavaScriptHelpers.js
├── 7.17 Removing Gratitous Context from Names
│ ├── cleannames.rs
│ ├── Gratuitous.rs
│ └── README.md
├── 7.11 Renaming Basic Do Functions
│ └── README.md
└── 7.14 Removing Impl PrefixSuffix from Class Names
│ ├── addressImpl.java
│ ├── README.md
│ └── Address.java
├── Chapter 06 Declarative Code
├── 6.04 Removing Double Negatives
│ ├── positive.js
│ ├── doubleNegation.js
│ └── README.md
├── 6.03 Removing Versioned Methods
│ ├── versionControlIsYourFriend.js
│ ├── versioned.js
│ └── README.md
├── 6.10 Documenting Regular Expressions
│ ├── smart.pl
│ ├── declarative.pl
│ └── README.md
├── 6.07 Documenting Design Decisions
│ ├── explicit.c
│ ├── implicit.c
│ └── README.md
├── 6.12 Removing Comedian Methods
│ ├── professional.js
│ ├── unprofessional.js
│ └── README.md
├── 6.06 Replacing Explicit Iterations
│ ├── explicitIteration.js
│ ├── implicitIteration.js
│ └── README.md
├── 6.08 Replacing Magic Numbers with Constants
│ ├── magicNumbers.php
│ ├── semanticMagic.rb
│ └── README.md
├── 6.11 Rewriting Yoda Conditions
│ ├── hitchhiker.js
│ ├── joda.js
│ └── README.md
├── 6.15 Avoiding Magic Corrections
│ ├── smarty.php
│ ├── failFast.php
│ └── README.md
├── 6.14 Generating Good Error Messages
│ ├── genericError.js
│ ├── empathy.js
│ ├── balance0.py
│ ├── balanceError.py
│ └── README.md
├── 6.02 Removing Empty Lines
│ ├── extracted.php
│ └── README.md
├── 6.01 Narrowing Reused Variables
│ ├── temp.java
│ ├── notreuse.java
│ └── README.md
├── 6.09 Separating What and How
│ ├── README.md
│ └── coupled.js
├── 6.13 Avoiding Callback Hell
│ └── README.md
└── 6.05 Changing Misplaced Responsibilities
│ └── README.md
├── Chapter 18 Globals
├── 18.05 Changing Global Date Creations
│ ├── globalDate.js
│ └── README.md
├── 18.03 Replacing GoTo with Structured Code
│ ├── structured.cs
│ ├── goto.cs
│ └── README.md
├── 18.02 Reifying Static Functions
│ ├── static.js
│ ├── nonstatic.js
│ └── README.md
├── 18.04 Removing Global Classes
│ ├── globalClasses.php
│ └── README.md
└── 18.01 Reifying Global Functions
│ ├── context.php
│ ├── global.php
│ └── README.md
├── Chapter 15 Null
├── 15.02 Removing Optional Chaining
│ ├── elvis.kt
│ ├── exploded.kt
│ ├── chaining.js
│ └── README.md
├── 15.01 Creating Null Objects
│ └── README.md
├── 15.03 Converting Optional Attributes to a Collection
│ ├── optional.js
│ └── README.md
├── 15.04 Using Real Objects for Null
│ └── README.md
└── 15.05 Representing Unknown Locations without using Null
│ └── README.md
├── Chapter 05 Mutability
├── 5.03 Forbidding Changes in the Essence
│ ├── essenceOnCreation.js
│ ├── mutator.js
│ └── README.md
├── 5.01 Changing var to const
│ ├── var.js
│ ├── let.js
│ └── README.md
├── 5.04 Avoiding Mutable const Arrays
│ ├── spread.js
│ ├── mutableConst.js
│ └── README.md
├── 5.05 Removing Lazy Initialization
│ ├── lazy.rb
│ ├── nonLazy.rb
│ └── README.md
├── 5.07 Removing Side Effects
│ ├── transparential.ts
│ ├── sideeffect.ts
│ └── README.md
├── 5.08 Preventing Hoisting
│ ├── hoisting.js
│ ├── const.js
│ └── README.md
├── 5.02 Declaring Variables to Be Variable
│ ├── variable.php
│ ├── constant.php
│ └── README.md
└── 5.06 Freezing Mutable Constants
│ └── README.md
├── Chapter 12 YAGNI
├── 12.01 Removing Dead Code
│ ├── alive.js
│ ├── dead.js
│ └── README.md
├── 12.03 Refactoring Classes with One Subclass
│ ├── noHierarchy.py
│ ├── README.md
│ └── boss.py
├── 12.02 Using Code Instead of Diagrams
│ └── README.md
├── 12.04 Removing One-Use Interfaces
│ ├── car.java
│ ├── README.md
│ └── vehicle.java
├── 12.05 Removing Design Pattern Abuses
│ ├── goodnames.java
│ ├── abuser.java
│ └── README.md
└── 12.06 Replacing Business Collections
│ └── README.md
├── Chapter 14 IFs
├── 14.01 Replacing Accidental Ifs with Polymorphism
│ ├── longChain.js
│ └── encapsulated.js
├── 14.17 Removing Gratuitous Booleans
│ ├── Nongratuitous.py
│ ├── gratuitous.py
│ └── README.md
├── 14.11 Preventing Return Boolean Values for Conditions Checks
│ ├── negation.js
│ ├── ifnegated.js
│ └── README.md
├── 14.16 Reifying Hardcoded Business Conditions
│ ├── nospecial.sol
│ ├── alameda.sol
│ └── README.md
├── 14.07 Adding Implicit Else
│ ├── implicit else.js
│ ├── explicit else.js
│ └── README.md
├── 14.03 Reifying Boolean Variables
│ ├── boolean.php
│ ├── noflags.php
│ └── README.md
├── 14.12 Changing Comparison Against Booleans
│ ├── explicit.bash
│ └── README.md
├── 14.10 Rewriting Nested Arrow Code
│ ├── extracted.js
│ └── README.md
├── 14.11 Preventing Return Boolean Values for Condition Checks
│ ├── boolean.java
│ ├── declarative.java
│ └── README.md
├── 14.15 Changing Equal Comparison
│ ├── comparison.js
│ ├── good responsibiliy.js
│ └── README.md
├── 14.06 Changing Boolean to Short Circuit Conditions
│ ├── short evaluation.php
│ ├── full evaluation.php
│ └── README.md
├── 14.09 Avoiding Short Circuit Hacks
│ ├── explicit.js
│ ├── README.md
│ └── masked IF.js
├── 14.18 Rewriting Nested Ternaries
│ ├── nested.js
│ └── README.md
├── 14.02 Renaming Flag Variables for Events
│ ├── uselessFlag.php
│ ├── declarativeFlag.php
│ └── README.md
├── 14.08 Rewriting Conditional Arrow Code
│ ├── business.py
│ └── README.md
├── 14.14 Converting Nonpolymorphic Functions to Polymorphic
│ ├── semanticDifferent.php
│ └── README.md
├── 14.13 Extracting from Long Ternaries
│ ├── README.md
│ └── polymorphic.js
├── 14.05 Replacing Hardcoded If Conditions with Collections
│ ├── hardcoded.cs
│ └── README.md
└── 14.04 Replacing SwitchCaseElseif Statements
│ ├── README.md
│ └── converters.js
├── Chapter 03 Anemic Models
├── 3.02 Identifying the Essence of Your Objects
│ ├── mutator.js
│ ├── ImmutableDate.js
│ └── README.md
├── 3.07 Completing Empty Constructors
│ ├── empty.js
│ ├── empty.java
│ ├── complete.js
│ ├── essence.java
│ └── README.md
├── 3.05 Removing Automatic Properties
│ ├── automatic.cs
│ ├── good.cs
│ └── README.md
├── 3.01 Converting Anemic Objects to Rich Objects
│ ├── anemic.java
│ ├── rich.java
│ └── README.md
├── 3.10 Removing Dynamic Properties
│ ├── defined.py
│ ├── dynamic.py
│ └── README.md
├── 3.06 Removing DTOs
│ └── README.md
├── 3.08 Removing Getters
│ ├── README.md
│ └── getters.php
├── 3.09 Preventing Object Orgy
│ ├── intimate.php
│ └── README.md
└── 3.04 Removing Anemic Code Generators
│ └── README.md
├── Chapter 23 Meta Programming
├── 23.03 Removing Preprocessors
│ ├── preprocessor.c
│ ├── behavior.c
│ └── README.md
├── 23.01 Removing Meta-programming Usage
│ ├── Magic.php
│ ├── DynamicName.php
│ ├── FindMagic.php
│ └── testMagicNumber.php
├── 23.04 Removing Dynamic Methods
│ ├── explicit.rb
│ └── README.md
└── 23.02 Reifying Anonymous Functions
│ └── README.md
├── Chapter 09 Standards
├── 9.02 Standardizing Indentations
│ ├── correct.js
│ ├── incorrect.js
│ ├── formatted.py
│ ├── badformat.py
│ └── README.md
├── 9.05 Unifying Parameter Order
│ ├── coherence.js
│ ├── mixed.js
│ └── README.md
├── 9.06 Fixing Broken Windows
│ ├── sloppy.c
│ ├── tidier.c
│ └── README.md
├── 9.03 Unifying Case Conventions
│ ├── mixedCases.json
│ ├── standard.json
│ └── README.md
├── 9.04 Writing Code in English
│ └── README.md
└── 9.01 Following Code Standards
│ └── README.md
├── Chapter 16 Premature Optimization
├── 16.03 Removing Bitwise Premature Optimizations
│ ├── Readable.js
│ ├── birwise.js
│ └── README.md
├── 16.06 Removing Anchor Boats
│ ├── yagni.php
│ └── README.md
├── 16.09 Removing Queries from Constructors
│ ├── constructor with sql.java
│ ├── constructor.java
│ └── README.md
├── 16.02 Removing Premature Optimization
│ ├── declarative.js
│ ├── premature.js
│ └── README.md
├── 16.04 Reducing Overgeneralization
│ ├── speculative.rs
│ ├── duplication.rs
│ └── README.md
├── 16.08 Removing Callback Events Based On Implementation
│ ├── cuopledEvent.js
│ ├── domainAgnostic.js
│ └── README.md
├── 16.05 Changing Structural Optimizations
│ ├── optimizedforloop.js
│ ├── README.md
│ └── forloop.js
├── 16.10 Removing Code from Destructors
│ ├── destructor.cpp
│ └── README.md
├── 16.01 Avoiding IDs on Objects
│ └── README.md
└── 16.07 Extracting Caches from Domain Objects
│ └── README.md
├── Chapter 17 Coupling
├── 17.03 Breaking God Objects
│ ├── mortal.js
│ ├── global.js
│ ├── god.js
│ ├── broken.js
│ └── README.md
├── 17.10 Moving Default Arguments to the End
│ ├── firstMandatory.php
│ ├── optional.php
│ └── dafaults.py
├── 17.17 Converting Fungible Objects
│ ├── fungible.java
│ ├── README.md
│ └── non fungible.java
├── 17.08 Preventing Feature Envy
│ ├── external.js
│ ├── internal.js
│ ├── envy.java
│ └── README.md
├── 17.04 Breaking Divergent Change
│ ├── divergent.js
│ └── README.md
├── 17.01 Making Hidden Assumptions Explicit
│ ├── hidden.py
│ └── README.md
├── 17.09 Removing the Middleman
│ ├── nowhereman.java
│ ├── README.md
│ └── middleman.java
├── 17.15 Refactoring Data Clumps
│ ├── dataclump.cs
│ └── README.md
├── 17.02 Replacing Singletons
│ ├── Singleton.php
│ └── README.md
├── 17.11 Avoiding Ripple Effect
│ ├── README.md
│ └── ripple.js
├── 17.06 Removing Shotgun Surgery
│ └── README.md
├── 17.07 Removing Optional Arguments
│ └── README.md
├── 17.14 Changing Coupling to Classes
│ ├── README.md
│ └── coupled.java
├── 17.16 Breaking Inappropriate Intimacy
│ └── README.md
├── 17.05 Converting 9999 Special Flag Values to Normal
│ └── README.md
├── 17.12 Removing Accidental Methods on Business Objects
│ ├── README.md
│ └── safecar.py
└── 17.13 Removing Business Code from the User Interface
│ └── README.md
├── Chapter 11 Bloaters
├── 11.04 Removing Excessive Parenthesis
│ ├── no parentheses.js
│ ├── parentheses.js
│ └── README.md
├── 11.08 Breaking 'And' Functions
│ ├── glued.rs
│ ├── and.py
│ ├── separated.py
│ ├── split.rs
│ └── README.md
├── 11.01 Breaking Too Long Methods
│ ├── extractedMethod.php
│ ├── README.md
│ └── longMethod.php
├── 11.05 Removing Excess Methods
│ ├── largeClass.java
│ ├── smallclasses.java
│ └── README.md
├── 11.07 Reducing Import Lists
│ ├── README.md
│ └── hiddenlayers.java
├── 11.02 Reducing Excess Arguments
│ └── README.md
├── 11.03 Reducing Excess Variables
│ └── README.md
├── 11.09 Breaking Fat Interfaces
│ └── README.md
└── 11.06 Breaking Too Many Attributes
│ └── README.md
├── Chapter 10 Complexity
├── 10.09 Removing Poltergeist Objects
│ ├── justDrive.cs
│ ├── driver.cs
│ └── README.md
├── 10.07 Extracting a Method to an Object
│ ├── beforeMethod.java
│ └── README.md
├── 10.04 Removing Cleverness from Code
│ ├── clever.js
│ ├── README.md
│ └── intelligent.js
├── 10.05 Breaking Multiple Promises
│ ├── fetchall.js
│ ├── firstoneatonce.js
│ └── README.md
├── 10.02 Removing SettingsConfigs
│ ├── pluggable.js
│ ├── README.md
│ └── configs.js
├── 10.01 Removing Repeated Code
│ └── README.md
├── 10.03 Changing State as Properties
│ └── README.md
├── 10.08 Looking After Array Constructors
│ └── README.md
└── 10.06 Breaking Long Chains of Collaborations
│ ├── README.md
│ └── direction.js
├── Chapter 20 Testing
├── 20.13 Learning a New Programming Language
│ └── README.md
├── 20.05 Refining Generic Assertions
│ ├── specific.py
│ ├── tooGeneric.py
│ └── README.md
├── 20.07 Changing Float Number Assertions
│ ├── assertFloat.java
│ ├── assertDelta.java
│ └── README.md
├── 20.12 Rewriting Tests Depending on Dates
│ ├── turnFlagff.java
│ ├── fixedAssert.java
│ └── README.md
├── 20.06 Removing Flaky Tests
│ └── README.md
├── 20.01 Testing Private Methods
│ └── README.md
├── 20.11 Adding Coverage for Every Merge Request
│ ├── orphanMergeRequest.ts
│ └── README.md
├── 20.02 Adding Descriptions to Assertions
│ ├── README.md
│ └── assertEquals.php
├── 20.04 Replacing Mocks with Real Objects
│ └── README.md
├── 20.08 Changing Test Data to Realistic Data
│ └── README.md
├── 20.10 Removing Irrelevant Test Information
│ └── README.md
├── 20.09 Protecting Tests Violating Encapsulation
│ └── README.md
└── 20.03 Migrating asserttrue to Specific Assertions
│ └── README.md
├── Chapter 08 Comments
├── 8.02 Removing Obsolete Comments
│ ├── deleted.cpp
│ ├── widget.cpp
│ └── README.md
├── 8.05 Converting Comments to Function Names
│ ├── declarative.php
│ ├── README.md
│ └── commentAbusers.php
├── 8.04 Removing Getter Comments
│ ├── nogetter.sol
│ ├── getterComment.sol
│ └── README.md
├── 8.03 Removing Logical Comments
│ ├── real code.js
│ └── README.md
├── 8.01 Removing Commented Code
│ └── README.md
├── 8.07 Replacing Comments with Tests
│ └── README.md
└── 8.06 Removing Comments Inside Methods
│ └── README.md
├── Chapter 25 Security
├── 25.01 Sanitizing Inputs
│ ├── not sanitized.py
│ ├── sanitized.py
│ └── README.md
├── 25.03 Removing Packages Dependencies
│ ├── isOddReal.js
│ ├── isOdd.js
│ └── README.md
├── 25.05 Protecting Object Deserialization
│ ├── unserializejson.py
│ └── README.md
├── 25.02 Changing Sequential Ids
│ ├── README.md
│ └── integerIDs.java
└── 25.04 Replacing Evil Regular Expressions
│ ├── evilregex.go
│ └── README.md
├── Chapter 13 Fail Fast
├── 13.03 Using Strict Parameters
│ ├── strict.php
│ └── README.md
├── 13.07 Refactoring Without Functional Changes
│ ├── renameAndChange.kt
│ ├── renameThenChange.kt
│ └── README.md
├── 13.02 Enforcing Preconditions
│ ├── README.md
│ └── noassertions.py
├── 13.04 Removing Default from Switch
│ └── README.md
├── 13.06 Redefining Hash and Equality
│ ├── README.md
│ └── equalsAndHashCorrelated.java
├── 13.05 Avoiding Modifying Collections While Traversing
│ ├── removeOriginal.java
│ └── README.md
└── 13.01 Refactoring Reassignment of Variables
│ └── README.md
├── Chapter 22 Exceptions
├── 22.07 Hiding Low Level Errors from End Users
│ ├── fatal.php
│ ├── README.md
│ └── handled.php
├── 22.03 Rewriting Exceptions for Expected Cases
│ ├── normalNotFoundScenario.java
│ ├── exceptionFlow.java
│ └── README.md
├── 22.01 Removing Empty Exception Blocks
│ ├── try except.py
│ ├── try pas.py
│ └── README.md
├── 22.08 Narrowing Exception Tries
│ └── README.md
├── 22.04 Rewriting Nested TryCatches
│ ├── README.md
│ └── normalFlow.js
├── 22.06 Rewriting Exception Arrow Code
│ └── README.md
├── 22.02 Removing Unnecessary Exceptions
│ └── README.md
└── 22.05 Replacing Return Codes with Exceptions
│ └── README.md
├── Chapter 24 Types
├── 24.02 Dealing with Truthy Values
│ ├── max.js
│ ├── leastSurpriseMax.js
│ ├── explicit.py
│ └── README.md
├── 24.03 Changing Float Numbers to Decimals
│ ├── casting.js
│ └── README.md
└── 24.01 Removing Type Checking
│ ├── README.md
│ └── avoidMeta.js
├── Chapter 04 Primitive Obsession
├── 4.05 Reifying Timestamps
│ ├── timestamp.py
│ ├── sequence.py
│ └── README.md
├── 4.08 Removing Unnecessary Properties
│ ├── personInQueue.rb
│ ├── person.rb
│ └── README.md
├── 4.06 Creating Objects Subsets
│ ├── String.java
│ └── README.md
├── 4.03 Reifying Associative Arrays
│ ├── CoordinateAsArray.php
│ ├── Latitude.php
│ ├── coordinateOperations.php
│ └── anemic.php
├── 4.01 Creating Small Objects
│ ├── primitiveName.java
│ └── README.md
├── 4.04 Removing String Abuses
│ ├── stringnotabuser.php
│ ├── stringabuser.php
│ └── README.md
├── 4.02 Reifying Primitive Data
│ ├── primitive.java
│ └── README.md
├── 4.09 Creating Date Intervals
│ └── README.md
└── 4.07 Reifying String Validations
│ └── README.md
├── Chapter 21 Technical Debt
├── 21.03 Removing WarningStrict Off
│ ├── warnings.js
│ ├── strict.js
│ └── README.md
├── 21.02 Removing Defect Trackers
│ ├── fixme.php
│ ├── nodebt.php
│ └── README.md
├── 21.01 Removing Production Dependent Code
│ └── README.md
└── 21.04 Preventing and Removing ToDos and FixMes
│ └── README.md
└── Chapter 19 Hierarchies
├── 19.01 Breaking Deep Inheritances
├── hierarchy.py
├── GreySeal.py
└── README.md
├── 19.10 Delaying Premature Classification
├── song.js
└── README.md
├── 19.02 Breaking Yo-Yo Hierarchies
├── composition.php
├── hierarchy.php
└── README.md
├── 19.09 Migrating Empty Classes
├── code class.js
└── README.md
├── 19.12 Completing Empty Implementations
├── empty.js
└── README.md
├── 19.05 Removing Nested Classes
└── README.md
├── 19.06 Renaming Isolated Classes
├── README.md
└── fullyQualifiedHierarchy.java
├── 19.07 Making Concrete Classes Final
├── README.md
└── subclassification.java
├── 19.11 Removing Protected Attributes
└── README.md
├── 19.08 Defining Class Inheritance Explicitly
└── README.md
├── 19.03 Breaking Subclassification for Code Reuse
└── README.md
└── 19.04 Replacing 'is-a' Relationship with Behavior
└── README.md
/Code/Chapter 07 Naming/7.12 Converting Plural Classes to Singular/plural.sc:
--------------------------------------------------------------------------------
1 | class Users
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.12 Converting Plural Classes to Singular/singular.sc:
--------------------------------------------------------------------------------
1 | class User
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.04 Removing Double Negatives/positive.js:
--------------------------------------------------------------------------------
1 | if (work.isDone())
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.12 Converting Plural Classes to Singular/plural.scala:
--------------------------------------------------------------------------------
1 | class Users
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.12 Converting Plural Classes to Singular/singular.scala:
--------------------------------------------------------------------------------
1 | class User
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.05 Changing Global Date Creations/globalDate.js:
--------------------------------------------------------------------------------
1 | var today = new Date();
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.06 Renaming Long Names/context.java:
--------------------------------------------------------------------------------
1 | PlanetarySystem.CentralStarCatalogEntry
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.03 Removing Versioned Methods/versionControlIsYourFriend.js:
--------------------------------------------------------------------------------
1 | findMatch()
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.04 Removing Double Negatives/doubleNegation.js:
--------------------------------------------------------------------------------
1 | if (!work.isNotFinished())
--------------------------------------------------------------------------------
/Code/Chapter 15 Null/15.02 Removing Optional Chaining/elvis.kt:
--------------------------------------------------------------------------------
1 | val shipTo = address?: "No address specified"
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.08 Correcting Spelling Mistakes/mispell.js:
--------------------------------------------------------------------------------
1 | comboFeededBySupplyer = supplyer.providers();
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.08 Correcting Spelling Mistakes/spellcheck.js:
--------------------------------------------------------------------------------
1 | comboFedBySupplier = supplier.providers();
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.03 Forbidding Changes in the Essence/essenceOnCreation.js:
--------------------------------------------------------------------------------
1 | const date = new Date("2022-03-25");
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.03 Forbidding Changes in the Essence/mutator.js:
--------------------------------------------------------------------------------
1 | const date = new Date();
2 | date.setMonth(4);
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.01 Removing Dead Code/alive.js:
--------------------------------------------------------------------------------
1 | class Robot {
2 | walk() {
3 | // ...
4 | }
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.01 Replacing Accidental Ifs with Polymorphism/longChain.js:
--------------------------------------------------------------------------------
1 | movie.rate.warnIfNotAllowed(this.age);
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.03 Renaming MyObjects/myWindow.cs:
--------------------------------------------------------------------------------
1 | MainWindow myWindow = Application.Current.MainWindow as MainWindow;
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.18 Avoiding Data Naming/data.js:
--------------------------------------------------------------------------------
1 | if (!dataExists()) {
2 | return '
Loading Data...
';
3 | }
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.02 Identifying the Essence of Your Objects/mutator.js:
--------------------------------------------------------------------------------
1 | const date = new Date();
2 | date.setMonth(4);
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.07 Completing Empty Constructors/empty.js:
--------------------------------------------------------------------------------
1 | class AirTicket {
2 | constructor() {
3 | }
4 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.18 Avoiding Data Naming/entity.js:
--------------------------------------------------------------------------------
1 | if (!peopleFound()) {
2 | return 'Loading People...
';
3 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.06 Renaming Long Names/longName.java:
--------------------------------------------------------------------------------
1 | PlanetarySystem.PlanetarySystemCentralStarCatalogEntry
2 |
3 | // Redundant
--------------------------------------------------------------------------------
/Code/Chapter 23 Meta Programming/23.03 Removing Preprocessors/preprocessor.c:
--------------------------------------------------------------------------------
1 | #if VERBOSE >= 2
2 | printf("trace message");
3 | #endif
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.10 Documenting Regular Expressions/smart.pl:
--------------------------------------------------------------------------------
1 | val regex = Regex("^\\+(?:[0-9a-zA-Z][– -]?){6,14}[0-9a-zA-Z]$")
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.02 Standardizing Indentations/correct.js:
--------------------------------------------------------------------------------
1 | function add(x, y) {
2 | // --->return x + y;
3 | return x + y;
4 | }
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.05 Removing Automatic Properties/automatic.cs:
--------------------------------------------------------------------------------
1 | class Person
2 | {
3 | public string name
4 | { get; set; }
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.07 Documenting Design Decisions/explicit.c:
--------------------------------------------------------------------------------
1 | increase_memory_to_avoid_false_positives();
2 | run_process();
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.03 Removing Bitwise Premature Optimizations/Readable.js:
--------------------------------------------------------------------------------
1 | const nowInSeconds = Math.floor(Date.now() / 1000)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.03 Breaking God Objects/mortal.js:
--------------------------------------------------------------------------------
1 | class Soldier {
2 | run() {}
3 | fight() {}
4 | clean() {}
5 | }
6 |
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.12 Removing Comedian Methods/professional.js:
--------------------------------------------------------------------------------
1 | function deleteAllCustomers();
2 | // more declarative and professional
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.13 Removing Collection from Names/customers.js:
--------------------------------------------------------------------------------
1 | for (var customer in customers) {
2 | // iterate with current customer
3 | }
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.04 Removing Excessive Parenthesis/no parentheses.js:
--------------------------------------------------------------------------------
1 | schwarzschild = (2 * GRAVITATION_CONSTANT * mass) / (LIGHT_SPEED ** 2)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.08 Breaking 'And' Functions/glued.rs:
--------------------------------------------------------------------------------
1 | calculatePrimeFactorsRemoveDuplicatesAndPrintThem()
2 |
3 | // Three responsibilities
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.03 Replacing GoTo with Structured Code/structured.cs:
--------------------------------------------------------------------------------
1 | for (int i = 0; i < 10; i++)
2 | {
3 | Console.WriteLine(i);
4 | }
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.09 Removing Poltergeist Objects/justDrive.cs:
--------------------------------------------------------------------------------
1 | // You don't need the driver
2 | Car porsche = new Car();
3 | porsche.driveCar();
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.17 Removing Gratuitous Booleans/Nongratuitous.py:
--------------------------------------------------------------------------------
1 | if a > 0:
2 | print("a is positive")
3 | else:
4 | print("a is not positive")
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.13 Learning a New Programming Language/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.13 Learning a New Programming Language
2 |
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.12 Removing Comedian Methods/unprofessional.js:
--------------------------------------------------------------------------------
1 | function erradicateAndMurderAllCustomers();
2 | // unprofessional and offensive
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.04 Renaming the Result/insdictinct.js:
--------------------------------------------------------------------------------
1 | var result;
2 | result = getSomeResult();
3 |
4 | var theResult;
5 | theResult = getSomeResult();
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.15 Renaming Arguments According to Role/first.py:
--------------------------------------------------------------------------------
1 | class Calculator:
2 | def subtract(self, first, second):
3 | return first - second
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.04 Removing Excessive Parenthesis/parentheses.js:
--------------------------------------------------------------------------------
1 | schwarzschild =
2 | ((((2 * GRAVITATION_CONSTANT)) * mass) / ((LIGHT_SPEED ** 2)))
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.11 Preventing Return Boolean Values for Conditions Checks/negation.js:
--------------------------------------------------------------------------------
1 | function canWeMoveOn() {
2 | return !work.hasPendingTasks();
3 | }
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.05 Refining Generic Assertions/specific.py:
--------------------------------------------------------------------------------
1 | square = Square(5)
2 |
3 | assert square.area() = 25
4 |
5 | # Assertion should be precise
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.06 Replacing Explicit Iterations/explicitIteration.js:
--------------------------------------------------------------------------------
1 | for (let i = 0; i < colors.length; i++) {
2 | console.log(colors[i]);
3 | }
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.02 Removing Obsolete Comments/deleted.cpp:
--------------------------------------------------------------------------------
1 | void Widget::displayPlugin(Unit* unit)
2 | {
3 | if (!isVisible) {
4 | return;
5 | }
6 | }
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.08 Replacing Magic Numbers with Constants/magicNumbers.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function energy($mass) {
4 | return $mass * (299792 ** 2)
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.11 Rewriting Yoda Conditions/hitchhiker.js:
--------------------------------------------------------------------------------
1 | if (answerToLifeMeaning == 42) {
2 | // might be mistaken with answerToLifeMeaning = 42
3 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.15 Renaming Arguments According to Role/roles.py:
--------------------------------------------------------------------------------
1 | class Calculator:
2 | def subtract(self, minuend, subtrahend):
3 | return minuend - subtrahend
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.08 Breaking 'And' Functions/and.py:
--------------------------------------------------------------------------------
1 | def fetch_and_display_personnel():
2 | data = # ...
3 |
4 | for person in data:
5 | print(person)
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.07 Completing Empty Constructors/empty.java:
--------------------------------------------------------------------------------
1 | public Person();
2 |
3 | // Anemic and mutable
4 | // Does not have the essence to be a valid person
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.15 Avoiding Magic Corrections/smarty.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | new Date(31, 02, 2020);
4 |
5 | 1 + 'Hello';
6 |
7 | !3;
8 |
9 | // Valid on most languages
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.04 Renaming Result Variables/result.js:
--------------------------------------------------------------------------------
1 | var result;
2 |
3 | result = lastBlockchainBlock();
4 |
5 | // Many function calls
6 |
7 | addBlockAfter(result);
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.09 Removing Class Name from Attributes/prefix.java:
--------------------------------------------------------------------------------
1 | public class Employee {
2 | String empName = "John";
3 | int empId = 5;
4 | int empAge = 32;
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.10 Removing the First Letter from Classes and Interfaces/prefixes.java:
--------------------------------------------------------------------------------
1 | public interface IEngine
2 | {
3 | void Start();
4 | }
5 |
6 | public class ACar {}
--------------------------------------------------------------------------------
/Code/Chapter 23 Meta Programming/23.01 Removing Meta-programming Usage/Magic.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | private function doSomeCrazyMathToFindAMagicNumber() {
4 | //very crazy math
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.01 Sanitizing Inputs/not sanitized.py:
--------------------------------------------------------------------------------
1 | user_input = "abc123!@#"
2 | # This content might not be very safe
3 | # if you expect just alphanumeric characters
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.01 Converting Anemic Objects to Rich Objects/anemic.java:
--------------------------------------------------------------------------------
1 | public class Song {
2 | String name;
3 | String authorName;
4 | String albumName;
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.03 Using Strict Parameters/strict.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function parseArguments(array $arguments) {
4 | $this->arguments = http_build_query(arguments)
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.16 Reifying Hardcoded Business Conditions/nospecial.sol:
--------------------------------------------------------------------------------
1 | customer.liquidatePositionIfNecessary(0.15);
2 |
3 | // This follows the "Tell, Don't ask" principle
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.07 Hiding Low Level Errors from End Users/fatal.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | Fatal error: Uncaught Error: Class 'MyClass'
4 | not found in /nstest/src/Container.php:9
--------------------------------------------------------------------------------
/Code/Chapter 24 Types/24.02 Dealing with Truthy Values/max.js:
--------------------------------------------------------------------------------
1 | console.log(Math.max() > Math.min());
2 |
3 | // returns false
4 |
5 | console.log(Math.max());
6 |
7 | // returns -Infinite
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.05 Reifying Timestamps/timestamp.py:
--------------------------------------------------------------------------------
1 | import time
2 |
3 | # ts stores the time in seconds
4 | ts1 = time.time()
5 | ts2 = time.time() # might be the same!!
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.08 Removing Unnecessary Properties/personInQueue.rb:
--------------------------------------------------------------------------------
1 | class PersonInQueue
2 |
3 | def moveForwardOnePosition
4 | # implement protocol
5 | end
6 | end
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.14 Generating Good Error Messages/genericError.js:
--------------------------------------------------------------------------------
1 | alert("Cancel the appointment?", "Yes", "No");
2 |
3 | // No consequences
4 | // The options are not clear
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.01 Breaking Too Long Methods/extractedMethod.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function setUpChessBoard() {
4 | $this->placeWhitePieces();
5 | $this->placeBlackPieces();
6 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.07 Adding Implicit Else/implicit else.js:
--------------------------------------------------------------------------------
1 | function carBrandImplicit(model) {
2 | if (model === 'A4') {
3 | return 'Audi';
4 | }
5 | return 'Mercedes-Benz';
6 | }
--------------------------------------------------------------------------------
/Code/Chapter 15 Null/15.02 Removing Optional Chaining/exploded.kt:
--------------------------------------------------------------------------------
1 | val shipTo = if (address != null) address else "No address specified"
2 |
3 | // This keeps the billion-dollar mistake error
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.03 Replacing GoTo with Structured Code/goto.cs:
--------------------------------------------------------------------------------
1 | int i = 0;
2 |
3 | start:
4 | if (i < 10)
5 | {
6 | Console.WriteLine(i);
7 | i++;
8 | goto start;
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.05 Refining Generic Assertions/tooGeneric.py:
--------------------------------------------------------------------------------
1 | square = Square(5)
2 |
3 | assert square.area() != 0
4 |
5 | # This will lead to false negatives since it is too vague
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.06 Replacing Explicit Iterations/implicitIteration.js:
--------------------------------------------------------------------------------
1 | colors.forEach((color) => {
2 | console.log(color);
3 | });
4 |
5 | // You use closures and arrow functions
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.07 Documenting Design Decisions/implicit.c:
--------------------------------------------------------------------------------
1 | // You need to run this process with more memory
2 | set_memory("512k");
3 |
4 | run_process();
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.08 Breaking 'And' Functions/separated.py:
--------------------------------------------------------------------------------
1 | def fetch_personnel():
2 | return # ...
3 |
4 | def display_personnel(data):
5 | for person in data:
6 | print(person)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.07 Changing Float Number Assertions/assertFloat.java:
--------------------------------------------------------------------------------
1 | Assert.assertEquals(0.0012f, 0.0012f); // Deprecated
2 | Assert.assertTrue(0.0012f == 0.0012f); // Not JUnit - Smell
--------------------------------------------------------------------------------
/Code/Chapter 23 Meta Programming/23.01 Removing Meta-programming Usage/DynamicName.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | $selector = 'getLanguage' . $this->languageCode;
4 | Reflection::invokeMethod($selector, $object);
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.06 Creating Objects Subsets/String.java:
--------------------------------------------------------------------------------
1 | validDestination = "destination@example.com"
2 | invalidDestination = "destination.example.com"
3 | // No error is thrown
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.01 Changing var to const/var.js:
--------------------------------------------------------------------------------
1 | var pi = 3.14
2 | var universeAgeInYears = 13.800.000.000
3 |
4 | pi = 3.1415 // no error
5 | universeAgeInYears = 13.800.000.001 // no error
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.04 Avoiding Mutable const Arrays/spread.js:
--------------------------------------------------------------------------------
1 | const array = [1, 2];
2 |
3 | const newArray = [...array, 3]
4 |
5 | // array => [1, 2] Didn't mutate
6 | // newArray = [1, 2, 3]
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.03 Reifying Boolean Variables/boolean.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function processBatch(
4 | bool $useLogin,
5 | bool $deleteEntries,
6 | bool $beforeToday) {
7 | // ...
8 | }
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.10 Moving Default Arguments to the End/firstMandatory.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function buildCar($model, $color = "Red", ){...}
4 |
5 | buildCar("Volvo")}}
6 | // Works as expected
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.03 Removing Packages Dependencies/isOddReal.js:
--------------------------------------------------------------------------------
1 | function isOdd(value) {
2 | const n = Math.abs(value);
3 | return (n % 2) === 1;
4 | };
5 |
6 | // Just solve it inline
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.05 Reifying Timestamps/sequence.py:
--------------------------------------------------------------------------------
1 | numbers = range(1, 100000)
2 | # create a sequence of numbers and use them with a hotspot
3 |
4 | # or
5 | sequence = nextNumber()
6 |
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.05 Removing Lazy Initialization/lazy.rb:
--------------------------------------------------------------------------------
1 | class Employee
2 | def emails
3 | @emails ||= []
4 | end
5 |
6 | def voice_mails
7 | @voice_mails ||= []
8 | end
9 | end
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.05 Converting Comments to Function Names/declarative.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class ChatBotConnectionSequenceGenerator {
4 |
5 | function connectionSequence() {
6 | }
7 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.12 Changing Comparison Against Booleans/explicit.bash:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if false ; then
4 | echo "True"
5 | else
6 | echo "False"
7 | fi
8 |
9 | # this evaluates to false
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.17 Converting Fungible Objects/fungible.java:
--------------------------------------------------------------------------------
1 | public class Person {
2 | }
3 |
4 | shoppingQueueSystem.queue(new Person());
5 | // The identity is irrelevant for queue simulation
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.07 Completing Empty Constructors/complete.js:
--------------------------------------------------------------------------------
1 | class AirTicket {
2 | constructor(origin, destination, arline, departureTime, passenger) {
3 |
4 | // ...
5 | }
6 | }
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.03 Reifying Associative Arrays/CoordinateAsArray.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | $coordinate = array('latitude'=>1000, 'longitude'=>2000);
4 | // They are just arrays. A Bunch of raw data
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.04 Avoiding Mutable const Arrays/mutableConst.js:
--------------------------------------------------------------------------------
1 | const array = [1, 2];
2 |
3 | array.push(3)
4 |
5 | // array => [1, 2, 3]
6 | // Wasn't it constant ?
7 | // constant != immutable ?
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.07 Renaming Abstract Names/realNames.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class Schedule {}
4 | final class Portfolio {}
5 | final class NoteBook {}
6 | final class Journal {}
7 | final class Vehicle {}
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.10 Removing the First Letter from Classes and Interfaces/real names.java:
--------------------------------------------------------------------------------
1 | public interface Engine
2 | {
3 | void Start();
4 | }
5 |
6 | public class Vehicle {}
7 | public class Car {}
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.10 Rewriting Nested Arrow Code/extracted.js:
--------------------------------------------------------------------------------
1 | foreach (products as currentProduct) {
2 | addPriceIfDefined(currentProduct)
3 | }
4 |
5 | addPriceIfDefined() {
6 | // Several extracts
7 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.11 Preventing Return Boolean Values for Conditions Checks/ifnegated.js:
--------------------------------------------------------------------------------
1 | function canWeMoveOn() {
2 | if (work.hasPendingTasks())
3 | return false;
4 | else
5 | return true;
6 | }
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.02 Identifying the Essence of Your Objects/ImmutableDate.js:
--------------------------------------------------------------------------------
1 | const date = new ImmutableDate("2022-03-25");
2 | // The date essence is identified and you will never change it from now on
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.01 Expanding Abbreviations/short.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | type YVC struct {
6 | id int
7 | }
8 |
9 | func main() {
10 | fmt.Println("Hello, World")
11 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.04 Renaming the Result/goodNames.js:
--------------------------------------------------------------------------------
1 | var averageSalary;
2 | averageSalary = calculateAverageSalary();
3 |
4 | var averageSalaryWithRaises;
5 | averageSalaryWithRaises = calculateAverageSalary();
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.08 Breaking 'And' Functions/split.rs:
--------------------------------------------------------------------------------
1 | calculatePrimeFactors();
2 |
3 | removeDuplicates();
4 |
5 | printNumbers();
6 |
7 | // Three different methods
8 | // You can test them and reuse them
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.03 Reifying Boolean Variables/noflags.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function processBatch(
4 | LoginStrategy $login,
5 | DeletionPolicy $deletionPolicy,
6 | Date $cutoffDate) {
7 | // ...
8 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.16 Removing Redundant Parameter Names/sayitonce.cr:
--------------------------------------------------------------------------------
1 | class Employee
2 | def initialize(
3 | @first_name : String,
4 | @last_name : String,
5 | @birthdate : Time)
6 | end
7 | end
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.03 Refactoring Classes with One Subclass/noHierarchy.py:
--------------------------------------------------------------------------------
1 | class Boss(object):
2 | def __init__(self, name):
3 | self.name = name
4 |
5 | # Bosses are concrete and can change mood
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.16 Reifying Hardcoded Business Conditions/alameda.sol:
--------------------------------------------------------------------------------
1 | if (currentExposure > 0.15 && customer != "Very Special Customer") {
2 | // Be extra careful not to liquidate
3 | liquidatePosition();
4 | }
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.12 Rewriting Tests Depending on Dates/turnFlagff.java:
--------------------------------------------------------------------------------
1 | class DateTest {
2 | @Test
3 | void testNoFeatureFlags() {
4 | Assertions.assertFalse(featureFlag.isOn());
5 | }
6 | }
--------------------------------------------------------------------------------
/Code/Chapter 21 Technical Debt/21.03 Removing WarningStrict Off/warnings.js:
--------------------------------------------------------------------------------
1 | undefinedVariable = 310;
2 |
3 | console.log(undefinedVariable); // Output: 310
4 |
5 | delete x; // No error you can delete undefinedVariable
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.03 Rewriting Exceptions for Expected Cases/normalNotFoundScenario.java:
--------------------------------------------------------------------------------
1 | for (int index = 0; index < array.length; index++)
2 | array[index]++;
3 |
4 | // index < array.length breaks execution
--------------------------------------------------------------------------------
/Code/Chapter 23 Meta Programming/23.01 Removing Meta-programming Usage/FindMagic.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | private function doSomeCrazyMathToFindAMagicNumber() {
4 | return (new CrazyObjectCalculator())->findMagicNumber();
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.01 Creating Small Objects/primitiveName.java:
--------------------------------------------------------------------------------
1 | public class Person {
2 | private final String name;
3 |
4 | public Person(String name) {
5 | this.name = name;
6 | }
7 | }
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.08 Removing Unnecessary Properties/person.rb:
--------------------------------------------------------------------------------
1 | class PersonInQueue
2 | attr_accessor :name, :job
3 |
4 | def initialize(name, job)
5 | @name = name
6 | @job = job
7 | end
8 | end
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.07 Removing Side Effects/transparential.ts:
--------------------------------------------------------------------------------
1 | let counter = 0;
2 |
3 | function incrementCounter(counter: number, value: number): number {
4 | return counter + value; // Not too efficient
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.10 Documenting Regular Expressions/declarative.pl:
--------------------------------------------------------------------------------
1 |
2 | val prefix = "\\+"
3 | val digit = "[0-9]"
4 | val space = "[– -]"
5 | val phoneRegex = Regex("^$prefix(?:$digit$space?){6,14}$digit$")
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.09 Removing Class Name from Attributes/contextual.java:
--------------------------------------------------------------------------------
1 | public class Employee {
2 | String name;
3 | int id; // Ids are another smell
4 | int age; // Storing the age is another code smell
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.04 Removing Getter Comments/nogetter.sol:
--------------------------------------------------------------------------------
1 | contract Property {
2 | int private _price;
3 |
4 | function price() public view returns(int) {
5 | return _price;
6 | }
7 | }
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.02 Reifying Static Functions/static.js:
--------------------------------------------------------------------------------
1 | class DateStringHelper {
2 | static format(date) {
3 | return date.toString('yyyy-MM-dd');
4 | }
5 | }
6 |
7 | DateStringHelper.format(new Date());
--------------------------------------------------------------------------------
/Code/Chapter 23 Meta Programming/23.01 Removing Meta-programming Usage/testMagicNumber.php:
--------------------------------------------------------------------------------
1 | final class CrazyObjectCalculatorTest extends TestCase {
2 |
3 | function testFindMagicNumber() {
4 | //…
5 | }
6 | }
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.01 Removing Dead Code/dead.js:
--------------------------------------------------------------------------------
1 | class Robot {
2 | walk() {
3 | // ...
4 | }
5 | serialize() {
6 | // ..
7 | }
8 | persistOnDatabase(database) {
9 | // ..
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.07 Extracting a Method to an Object/beforeMethod.java:
--------------------------------------------------------------------------------
1 | class BlockchainAccount {
2 | // ...
3 | public double balance() {
4 | string address;
5 | // Very long untestable method
6 | }
7 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.11 Preventing Return Boolean Values for Condition Checks/boolean.java:
--------------------------------------------------------------------------------
1 | boolean isEven(int num) {
2 | if(num % 2 == 0) {
3 | return true;
4 | } else {
5 | return false;
6 | }
7 | }
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.02 Removing Empty Lines/extracted.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function translateFile() {
4 | $this->readFileToMemory();
5 | $this->translateContents();
6 | $this->generateStatsAndSaveFileContents();
7 | }
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.15 Avoiding Magic Corrections/failFast.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | new Date(31, 02, 2020);
4 | // Throw an exception
5 |
6 | 1 + 'Hello';
7 | // Type Mismatch
8 |
9 | !3;
10 | // Negating is a boolean operation
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.15 Changing Equal Comparison/comparison.js:
--------------------------------------------------------------------------------
1 | if (address.street == 'Broad Street') { }
2 |
3 | if (location.street == 'Bourbon St') { }
4 |
5 | // 24601 usages in a big system
6 | // Comparisons are case sensitive
--------------------------------------------------------------------------------
/Code/Chapter 24 Types/24.02 Dealing with Truthy Values/leastSurpriseMax.js:
--------------------------------------------------------------------------------
1 | console.log(Math.max() > Math.min());
2 | console.log(Math.max());
3 |
4 | // returns Exception. Not enough arguments passed.
5 | // Max requires at least one argument
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.08 Preventing Hoisting/hoisting.js:
--------------------------------------------------------------------------------
1 | console.log(willBeDefinedLater);
2 | // Output: undefined (but no error)
3 |
4 | var willBeDefinedLater = "Beatriz";
5 | console.log(willBeDefinedLater);
6 | // Output: "Beatriz"
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.03 Breaking God Objects/global.js:
--------------------------------------------------------------------------------
1 | public static class GlobalConstants
2 | {
3 | public const int MaxPlayers = 10;
4 | public const string DefaultLanguage = "en-US";
5 | public const double Pi = 3.14159;
6 | }
--------------------------------------------------------------------------------
/Code/Chapter 21 Technical Debt/21.02 Removing Defect Trackers/fixme.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function divide($numerator, $denominator) {
4 | return $numerator / $denominator;
5 | // FIXME denominator value might be 0
6 | // TODO Rename function
7 | }
--------------------------------------------------------------------------------
/Code/Chapter 24 Types/24.03 Changing Float Numbers to Decimals/casting.js:
--------------------------------------------------------------------------------
1 | console.log(0.2 + 0.1)
2 | // 0.30000000000000004
3 |
4 | // You are adding two decimal numbers
5 | // 2/10 + 1/10
6 | // Result should be 3/10 as you learned at school
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.07 Completing Empty Constructors/essence.java:
--------------------------------------------------------------------------------
1 | public Person(String name, int age) {
2 | this.name = name;
3 | this.age = age;
4 | }
5 |
6 | // You 'pass' the essence to the object
7 | // So it does not mutate
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.06 Changing Boolean to Short Circuit Conditions/short evaluation.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | if (isOpen(file) && size(contents(file)) > 0)
4 | // Short circuit evaluation
5 | // If the file is not open it willtry to get the contents
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.03 Rewriting Exceptions for Expected Cases/exceptionFlow.java:
--------------------------------------------------------------------------------
1 | try {
2 | for (int index = 0;; index++)
3 | array[index]++;
4 | } catch (ArrayIndexOutOfBoundsException e) {}
5 |
6 | // Endless loop without end condition
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.16 Removing Redundant Parameter Names/redundant.cr:
--------------------------------------------------------------------------------
1 | class Employee
2 | def initialize(
3 | @employee_first_name : String,
4 | @employee_last_name : String,
5 | @employee_birthdate : Time)
6 | end
7 | end
8 |
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.01 Removing Empty Exception Blocks/try except.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | logger logging.getLogger(__name___)
4 | try:
5 | send_email()
6 | except ConnectionError as exception:
7 | logger.error("Cannot send email {exception}")
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.11 Rewriting Yoda Conditions/joda.js:
--------------------------------------------------------------------------------
1 | if (42 == answerToLifeMeaning) {
2 | // prevents the accidental assignation typo
3 | // since ‘42 = answerToLifeMeaning’ is invalid
4 | // but ‘answerToLifeMeaning = 42’ is valid
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.07 Renaming Abstract Names/abstractNames.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class MeetingsCollection {}
4 | final class AccountsComposite {}
5 | final class NotesArray {}
6 | final class LogCollector {}
7 |
8 | abstract class AbstractTransportation {}
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.09 Avoiding Short Circuit Hacks/explicit.js:
--------------------------------------------------------------------------------
1 | if (userIsValid()) {
2 | logUserIn();
3 | }
4 |
5 | if(typeof functionDefinedOrNot == 'function') {
6 | functionDefinedOrNot();
7 | }
8 | // Checking for a type is another code smell
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.08 Preventing Feature Envy/external.js:
--------------------------------------------------------------------------------
1 | function area(rectangle) {
2 | return rectangle.width * rectangle.height;
3 | // Notice that you are sending consecutive messages to
4 | // the same object and doing calculations
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.03 Renaming MyObjects/salesWindow.cs:
--------------------------------------------------------------------------------
1 | MainWindow salesWindow = Application.Current.MainWindow as MainWindow;
2 |
3 | /*
4 | Since the window is instanciated, you are currently working
5 | with a specialized window playing a special role
6 | */
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.05 Unifying Parameter Order/coherence.js:
--------------------------------------------------------------------------------
1 | function giveFirstDoseOfVaccine(person, vaccine) { }
2 |
3 | function giveSecondDoseOfVaccine(person, vaccine) { }
4 |
5 | giveFirstDoseOfVaccine(jane, flu);
6 | giveSecondDoseOfVaccine(jane, flu);
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.01 Changing var to const/let.js:
--------------------------------------------------------------------------------
1 | const pi = 3.14 // Value cannot mutate or change
2 | let universeAgeInYears = 13.800.000.000 // Value can change
3 |
4 | pi = 3.1415 // error. cannot define
5 | universeAgeInYears = 13.800.000.001 // no error
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.11 Preventing Return Boolean Values for Condition Checks/declarative.java:
--------------------------------------------------------------------------------
1 | boolean isEven(int numberToCheck) {
2 | // You decouple the what (to check for even or odd)
3 | // With how (the algorithm)
4 | return (numberToCheck % 2 == 0);
5 | }
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.06 Removing Anchor Boats/yagni.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class DatabaseQueryOptimizer {
4 |
5 | public function selectWithCriteria($tableName, $criteria) {
6 | // Make some optimizations manipulating criteria
7 | }
8 | }
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.04 Breaking Divergent Change/divergent.js:
--------------------------------------------------------------------------------
1 | class Webpage {
2 |
3 | renderHTML() {
4 | renderDocType();
5 | renderTitle();
6 | renderRssHeader();
7 | renderRssTitle();
8 | renderRssDescription();
9 | }
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.01 Removing Empty Exception Blocks/try pas.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | def send_email():
4 | print("Sending email")
5 | raise ConnectionError("Oops")
6 |
7 | try:
8 | send_email()
9 | except:
10 | # AVOID THIS
11 | pass
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.01 Expanding Abbreviations/declarative.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "formatter"
4 |
5 | type YoutTubeVideoContent struct {
6 | imdbMovieIdentifier int
7 | }
8 |
9 | function main() {
10 | formatter.Printline("Hello, World")
11 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.13 Removing Collection from Names/customerCollection.js:
--------------------------------------------------------------------------------
1 | for (var customer in customerCollection) {
2 | // iterate with current customer
3 | }
4 |
5 | for (var currentCustomer in customersCollection) {
6 | // iterate with current customer
7 | }
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.01 Making Hidden Assumptions Explicit/hidden.py:
--------------------------------------------------------------------------------
1 | tenCentimeters = 10
2 | tenInches = 10
3 |
4 | tenCentimeters + tenInches
5 | # 20
6 | # this error is based on the hidden assumption of a unit (any)
7 | # and caused the Mars Climate Orbiter failure
--------------------------------------------------------------------------------
/Code/Chapter 23 Meta Programming/23.03 Removing Preprocessors/behavior.c:
--------------------------------------------------------------------------------
1 | if (runtimeEnvironment->traceDebug()) {
2 | printf("trace message");
3 | }
4 |
5 | // even better with polymorphism and you avoid annoying ifs
6 |
7 | runtimeEnvironment->traceDebug("trace message");
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.04 Removing Getter Comments/getterComment.sol:
--------------------------------------------------------------------------------
1 | contract Property {
2 | int private price;
3 |
4 | function getPrice() public view returns(int) {
5 | /* returns the Price */
6 |
7 | return price;
8 | }
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.02 Using Code Instead of Diagrams/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 12 YAGNI - 12.2 Using Code Instead of Diagrams
2 |
3 |
4 | [https://gist.github.com/mcsee/36f0af6785ea36a05c3ec394fa71e4e8](https://gist.github.com/mcsee/36f0af6785ea36a05c3ec394fa71e4e8)
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.04 Removing String Abuses/stringnotabuser.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | class School {
4 | private $name;
5 | private $location;
6 |
7 | function description() {
8 | return $this->name . ' of ' . $this->location->name;
9 | }
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.02 Standardizing Indentations/incorrect.js:
--------------------------------------------------------------------------------
1 | function add(x, y) {
2 | // --->..return x + y;
3 |
4 | return x + y;
5 | }
6 |
7 | function main() {
8 | // --->var x = 5,
9 | // --->....y = 7;
10 |
11 | var x = 5,
12 | y = 7;
13 | }
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.04 Removing Global Classes/globalClasses.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class StringUtilHelper {
4 | static function reformatYYYYDDMMtoYYYYMMDD($date) {
5 | }
6 | }
7 |
8 | class Singleton { }
9 |
10 | final class DatabaseAccessor extends Singleton { }
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.08 Preventing Feature Envy/internal.js:
--------------------------------------------------------------------------------
1 | class Rectangle {
2 | constructor(width, height) {
3 | this.height = height;
4 | this.width = width;
5 | }
6 |
7 | area() {
8 | return this.width * this.height;
9 | }
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.10 Moving Default Arguments to the End/optional.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function buildCar($color = "red", $model) {
4 | //...
5 | }
6 | // First argument with optional argument
7 |
8 | buildCar("Volvo");
9 | // Runtime error: Too few arguments to function buildCar()
--------------------------------------------------------------------------------
/Code/Chapter 21 Technical Debt/21.03 Removing WarningStrict Off/strict.js:
--------------------------------------------------------------------------------
1 | ’use strict’
2 |
3 | undefinedVariable = 310;
4 | console.log(undefinedVariable);
5 | // undefinedVariable is not defined
6 |
7 | delete undefinedVariable ;
8 | // Delete of an unqualified identifier in strict mode
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.02 Declaring Variables to Be Variable/variable.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function configureUser() {
4 | $password = '123456';
5 | // Setting a password on a variable is a vulnerability
6 | $user = new User($password);
7 | // Notice variable doesn't change
8 | }
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.14 Generating Good Error Messages/empathy.js:
--------------------------------------------------------------------------------
1 | alert("Cancel the appointment? \n" +
2 | "You will lose all the history",
3 | "Cancel Appointment",
4 | "Keep Editing");
5 |
6 | // The consequences are clear
7 | // The choice options have context
--------------------------------------------------------------------------------
/Code/Chapter 21 Technical Debt/21.02 Removing Defect Trackers/nodebt.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function integerDivide($numerator, $denominator) {
4 | if (denominator == 0) {
5 | throw new DivideByZero();
6 | }
7 | return $numerator / $denominator;
8 | }
9 |
10 | // You pay your debts
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.08 Replacing Magic Numbers with Constants/semanticMagic.rb:
--------------------------------------------------------------------------------
1 | # Storing magnitudes without units is another smell
2 | class PhysicsConstants
3 | LIGHT_SPEED = 299792458.freeze
4 | end
5 |
6 | def energy(mass)
7 | mass * PhysicsConstants::LIGHT_SPEED ** 2
8 | end
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.02 Removing Obsolete Comments/widget.cpp:
--------------------------------------------------------------------------------
1 | void Widget::displayPlugin(Unit* unit){
2 |
3 | // TODO the Plugin will be modified soon,
4 | // so I don't implement this right now
5 |
6 | if (!isVisible) {
7 | // hide all widgets
8 | return;
9 | }
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.06 Fixing Broken Windows/sloppy.c:
--------------------------------------------------------------------------------
1 | int mult(int a,int other)
2 | { int prod
3 | prod= 0;
4 | for(int i=0;i 0 and True:
4 | # This code was left on debugging and passed
5 | # by mistake during code reviews
6 | print("a is positive")
7 | else:
8 | print("a is not positive")
9 |
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.06 Changing Boolean to Short Circuit Conditions/full evaluation.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | if (isOpen(file) & size(contents(file)) > 0)
4 | // It performs a full evaluation since it is the bitwise AND
5 | // will fail since you cannot retrieve contents
6 | // from a file that is not open
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.18 Rewriting Nested Ternaries/nested.js:
--------------------------------------------------------------------------------
1 | const getUnits = secs => (
2 | secs <= 60 ? 'seconds' :
3 | secs <= 3600 ? 'minutes' :
4 | secs <= 86400 ? 'hours' :
5 | secs <= 2592000 ? 'days' :
6 | secs <= 31536000 ? 'months' :
7 | 'years'
8 | )
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.02 Reifying Primitive Data/primitive.java:
--------------------------------------------------------------------------------
1 | int port = 8080;
2 | InetSocketAddress in = open("example.org", port);
3 | String uri = urifromPort("example.org", port);
4 | String address = addressFromPort("example.org", port);
5 | String path = pathFromPort("example.org", port);
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.05 Removing Excess Methods/largeClass.java:
--------------------------------------------------------------------------------
1 | public class MyHelperClass {
2 | public void print() { }
3 | public void format() { }
4 | // ... many methods more
5 |
6 | // ... even more methods
7 | public void persist() { }
8 | public void solveFermiParadox() { }
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.07 Adding Implicit Else/explicit else.js:
--------------------------------------------------------------------------------
1 | function carBrandExplicit(model) {
2 | if (model === 'A4') {
3 | return 'Audi';
4 | }
5 | if (model === 'AMG') {
6 | return 'Mercedes-Benz';
7 | }
8 |
9 | // Fail Fast
10 | throw new Exception('Model not found);
11 | }
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.09 Removing Queries from Constructors/constructor with sql.java:
--------------------------------------------------------------------------------
1 | public class Person {
2 | int childrenCount;
3 |
4 | public Person(int id) {
5 | childrenCount = database.sqlCall(
6 | "SELECT COUNT(CHILDREN) FROM PERSON WHERE ID = " . id);
7 | }
8 | }
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.01 Reifying Global Functions/context.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class EmployeeTaxesCalculator {
4 | function taxesPayedUntilToday($context) {
5 | return $context->SelectTaxesForEmployeeUntil(
6 | $this->ssn,
7 | $context->currentDate());
8 | }
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.01 Breaking Deep Inheritances/hierarchy.py:
--------------------------------------------------------------------------------
1 | class Animalia:
2 | class Chordata(Animalia):
3 | class Mammalia(Chordata):
4 | class Carnivora(Mammalia):
5 | class Pinnipedia(Carnivora):
6 | class Phocidae(Pinnipedia):
7 | class Halichoerus(Phocidae):
8 | class GreySeal(Halichoerus):
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.03 Unifying Case Conventions/mixedCases.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": 2,
3 | "userId": 666,
4 | "accountNumber": "12345-12345-12345",
5 | "UPDATED_AT": "2022-01-07T02:23:41.305Z",
6 | "created_at": "2019-01-07T02:23:41.305Z",
7 | "deleted at": "2022-01-07T02:23:41.305Z"
8 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.02 Renaming Flag Variables for Events/uselessFlag.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function dummy() {
4 |
5 | $flag = true;
6 |
7 | while ($flag == true) {
8 |
9 | $result = checkSomething();
10 | if ($result) {
11 | $flag = false;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.10 Delaying Premature Classification/song.js:
--------------------------------------------------------------------------------
1 | class Song {
2 | constructor(title, artist) {
3 | this.title = title;
4 | this.artist = artist;
5 | }
6 |
7 | play() {
8 | console.log(`Playing ${this.title} by ${this.artist}`);
9 | }
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.03 Removing Packages Dependencies/isOdd.js:
--------------------------------------------------------------------------------
1 | $ npm install --save is-odd
2 |
3 | // https://www.npmjs.com/package/is-odd
4 | // This package has about 500k weekly downloads
5 |
6 | module.exports = function isOdd(value) {
7 | const n = Math.abs(value);
8 | return (n % 2) === 1;
9 | };
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.10 Removing Dynamic Properties/defined.py:
--------------------------------------------------------------------------------
1 | class Dream:
2 | def __init__(self):
3 | self.presentation = ""
4 |
5 | nightmare = Dream()
6 |
7 | nightmare.presentation = "I am the Sandman"
8 |
9 | print(nightmare.presentation)
10 | # Output: "I am the Sandman"
11 |
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.04 Renaming Result Variables/blockchain.js:
--------------------------------------------------------------------------------
1 | var lastBlockchainBlock;
2 |
3 | lastBlockchainBlock = findlastBlockchainBlock();
4 |
5 | // Many function calls
6 | // you should refactor them to minimize space
7 | // between variable definition and usage
8 |
9 | addBlockAfter(lastBlockchainBlock);
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.09 Removing the Middleman/nowhereman.java:
--------------------------------------------------------------------------------
1 | public class Client {
2 | public ZipCode zipCode() {
3 | // Can also store it
4 | return new ZipCode(’CA90210’);
5 | }
6 | }
7 |
8 | public class Application {
9 | ZipCode zipCode = client.address().zipCode();
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.03 Reifying Associative Arrays/Latitude.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class Latitude {
4 | function __construct($degrees) {
5 | if (!$degrees->between(-90, 90)) {
6 | throw new InvalidLatitudeException($degrees);
7 | }
8 | // ...
9 | }
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.14 Generating Good Error Messages/balance0.py:
--------------------------------------------------------------------------------
1 | def get_balance(address):
2 | url = "https://blockchain.info/q/addressbalance/" + address
3 | response = requests.get(url)
4 | if response.status_code == 200:
5 | return response.text
6 | else:
7 | return 0
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.05 Renaming Variables Named After Types/type coupling.java:
--------------------------------------------------------------------------------
1 | public bool CheckIfStringHas3To7LowercaseCharsFollowedBy3or4Numbers
2 | (string textToCheck)
3 | {
4 | Regex regex = new Regex(@"[a-z]{2,7}[1-9]{3,4}")
5 | var bool = regex.IsMatch(textToCheck);
6 | return bool;
7 | }
--------------------------------------------------------------------------------
/Code/Chapter 15 Null/15.02 Removing Optional Chaining/chaining.js:
--------------------------------------------------------------------------------
1 | const user = {
2 | name: 'Hacker'
3 | };
4 |
5 | if (user?.credentials?.notExpired) {
6 | user.login();
7 | }
8 |
9 | user.functionDefinedOrNot?.();
10 |
11 | // Seems compact but it is hacky and has lots
12 | // of potential NULLs and Undefined
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.02 Removing Premature Optimization/declarative.js:
--------------------------------------------------------------------------------
1 | class Person {
2 | ancestors() {
3 | return this.mother.meAndAncerstors().concat(
4 | this.father.meAndAncerstors());
5 | }
6 | meAndAncerstors() {
7 | return this.ancestors().push(this);
8 | }
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.01 Sanitizing Inputs/sanitized.py:
--------------------------------------------------------------------------------
1 | def sanitize(string):
2 | # Remove any characters that are not letters or numbers
3 | sanitized_string = re.sub(r'[^a-zA-Z0-9]', '', string)
4 |
5 | return sanitized_string
6 |
7 | user_input = "abc123!@#"
8 | print(sanitize(user_input)) # Output: "abc123"
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.10 Removing Dynamic Properties/dynamic.py:
--------------------------------------------------------------------------------
1 | class Dream:
2 | pass
3 |
4 | nightmare = Dream()
5 |
6 | nightmare.presentation = "I am the Sandman"
7 | # presentation is not defined
8 | # it is a dynamic property
9 |
10 | print(nightmare.presentation)
11 | # Output: "I am the Sandman"
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.05 Unifying Parameter Order/mixed.js:
--------------------------------------------------------------------------------
1 | function giveFirstDoseOfVaccine(person, vaccine) { }
2 |
3 | function giveSecondDoseOfVaccine(vaccine, person) { }
4 |
5 | giveFirstDoseOfVaccine(jane, flu);
6 | giveSecondDoseOfVaccine(jane, flu);
7 | //Unnoticed mistake since you changed the parameters’ order
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.06 Fixing Broken Windows/tidier.c:
--------------------------------------------------------------------------------
1 | int multiply(int firstMultiplier, int secondMultiplier) {
2 | int product = 0;
3 | for(int currentIndex=0; currentIndex= 2; ) {
5 | if(n % d == 0) {
6 | f[i++]=(d);
7 | n /= d;
8 | }
9 | else {
10 | d++;
11 | }
12 | }
13 | return f;
14 | }
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.05 Breaking Multiple Promises/fetchall.js:
--------------------------------------------------------------------------------
1 | async fetchLongTask() { }
2 | async fetchAnotherLongTask() { }
3 |
4 | async fetchAll() {
5 | let [result1, result2] =
6 | await Promise.all(
7 | [this.fetchLongTask(), this.fetchAnotherLongTask()]);
8 | // You wait until ALL are done
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.04 Removing String Abuses/stringabuser.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | $schoolDescription = 'College of Springfield';
4 |
5 | preg_match('/[^ ]*$/', $schoolDescription, $results);
6 | $location = $results[0]; // $location = 'Springfield'.
7 |
8 | $school = preg_split('/[\s,]+/', $schoolDescription, 3)[0]; //'College'
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.05 Removing Design Pattern Abuses/goodnames.java:
--------------------------------------------------------------------------------
1 | public final class FileSystem {
2 | // These names map 1:1 to real-world concepts
3 | }
4 |
5 | public final class DateTimeFormatter { }
6 | public final class BubbleSort { }
7 | public final class NetworkSniffer { }
8 | public final class Portfolio { }
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.01 Reifying Global Functions/global.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | class Employee {
4 | function taxesPayedUntilToday() {
5 | return database()->select(
6 | "SELECT TAXES FROM EMPLOYEE".
7 | " WHERE ID = " . $this->id() .
8 | " AND DATE < " . currentDate());
9 | }
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.05 Removing Lazy Initialization/nonLazy.rb:
--------------------------------------------------------------------------------
1 | class Employee
2 | attr_reader :emails, :voice_mails
3 |
4 | def initialize
5 | @emails = []
6 | @voice_mails = []
7 | end
8 | end
9 | # You can also inject a design pattern to externally deal
10 | # with voice_mails so you can mock it in your tests
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.07 Refactoring Without Functional Changes/renameAndChange.kt:
--------------------------------------------------------------------------------
1 | getFactorial(n) {
2 | return n * getFactorial(n);
3 | }
4 |
5 | // Rename and Change
6 |
7 | factorial(n) {
8 | return n * factorial(n-1);
9 | }
10 |
11 | // This is a very small example
12 | // Things go works while dealing with huge code
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.08 Rewriting Conditional Arrow Code/business.py:
--------------------------------------------------------------------------------
1 | def is_platypus(self):
2 | return self.is_mammal() &&
3 | self.has_fur() &&
4 | self.has_beak() &&
5 | self.has_tail() &&
6 | self.can_swim()
7 |
8 | # You can even group conditions according to animal taxonomies
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.14 Converting Nonpolymorphic Functions to Polymorphic/semanticDifferent.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | class array {
4 | public function arraySort() {
5 | }
6 | }
7 |
8 | class list {
9 | public function listSort() {
10 | }
11 | }
12 |
13 | class Stack {
14 | public function stackSort() {
15 | }
16 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.02 Renaming and Breaking Helpers and Utils/JavaScriptHelpers.js:
--------------------------------------------------------------------------------
1 | import UserHelpers from './UserHelpers';
2 |
3 | const alice = {
4 | firstName: 'Alice',
5 | lastName: 'Gray',
6 | points: 78,
7 | };
8 |
9 | const fullName = UserHelpers.getFullName(alice);
10 | const category = UserHelpers.getCategory(alice);
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.05 Breaking Multiple Promises/firstoneatonce.js:
--------------------------------------------------------------------------------
1 | async fetchLongTask() { }
2 | async fetchAnotherLongTask() { }
3 |
4 | async fetchAll() {
5 | let result1 = await this.fetchLongTask();
6 | let result2 = await this.fetchAnotherLongTask();
7 | // But they can run in parallel !!
8 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.15 Changing Equal Comparison/good responsibiliy.js:
--------------------------------------------------------------------------------
1 | if (address.isAtStreet('Broad Street') { }
2 |
3 | if (location.isAtStreet('Bourbon St') { }
4 | // 24601 usages in a big system
5 |
6 | function isAtStreet(street) {
7 | // You can change Comparisons to
8 | // case sensitive in just one place.
9 | }
10 |
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.03 Breaking God Objects/god.js:
--------------------------------------------------------------------------------
1 | class Soldier {
2 | run() {}
3 | fight() {}
4 | driveGeneral() {}
5 | clean() {}
6 | fire() {}
7 | bePromoted() {}
8 | serialize() {}
9 | display() {}
10 | persistOnDatabase() {}
11 | toXML() {}
12 | jsonDecode() {}
13 |
14 | // ...
15 | }
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.08 Preventing Feature Envy/envy.java:
--------------------------------------------------------------------------------
1 | class Candidate {
2 |
3 | void printJobAddress(Job job) {
4 | System.out.println("This is your position address");
5 | System.out.println(job.address().street());
6 | System.out.println(job.address().city());
7 | System.out.println(job.address().ZipCode());
8 | }
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.02 Reifying Static Functions/nonstatic.js:
--------------------------------------------------------------------------------
1 | class DateToStringFormatter {
2 | constructor(date) {
3 | this.date = date;
4 | }
5 |
6 | englishFormat() {
7 | return this.date.toString('yyyy-MM-dd');
8 | }
9 | }
10 |
11 | new DateToStringFormatter(new Date()).englishFormat()
12 |
13 |
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.05 Removing Automatic Properties/good.cs:
--------------------------------------------------------------------------------
1 | class Person
2 | {
3 | private string name;
4 |
5 | public Person(string personName)
6 | {
7 | name = personName;
8 | // immutable
9 | // no getters, no setters
10 | }
11 |
12 | // ... more protocol, probably accessing private variable name
13 | }
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.07 Removing Side Effects/sideeffect.ts:
--------------------------------------------------------------------------------
1 | let counter = 0;
2 |
3 | function incrementCounter(value: number): void {
4 | // Two side effects
5 | counter += value;
6 | // it modifies the global variable counter
7 |
8 | console.log(`Counter is now ${counter}`);
9 | // it logs a message to the console
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.08 Preventing Hoisting/const.js:
--------------------------------------------------------------------------------
1 | const dante = "abandon hope all ye who enter here";
2 | // Declaring a constant 'dante'
3 | // with value "abandon hope all ye who enter here"
4 |
5 | console.log(dante);
6 | // Output: "abandon hope all ye who enter here"
7 |
8 | dante = "Divine Comedy"; // Error: Assignment to constant variable
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.17 Removing Gratitous Context from Names/cleannames.rs:
--------------------------------------------------------------------------------
1 | struct Exoplanet {
2 | name: String,
3 | mass: f64,
4 | radius: f64,
5 | distance: f64,
6 | orbital_period: f64,
7 | }
8 |
9 | struct Galaxy {
10 | name: String,
11 | classification: String,
12 | distance: f64,
13 | age: f64,
14 | }
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.07 Refactoring Without Functional Changes/renameThenChange.kt:
--------------------------------------------------------------------------------
1 | getFactorial(n) {
2 | return n * getFactorial(n);
3 | }
4 |
5 | // Change
6 |
7 | getFactorial(n) {
8 | return n * getFactorial(n-1);
9 | }
10 |
11 | // Run the tests
12 |
13 | factorial(n) {
14 | return n * factorial(n-1);
15 | }
16 |
17 | // Rename
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.01 Breaking Deep Inheritances/GreySeal.py:
--------------------------------------------------------------------------------
1 | class GreySeal:
2 | def eat(self): # find the common behavior in the hierarchy
3 | def sleep(self): # find the common behavior in the hierarchy
4 | def swim(self): # find the common behavior in the hierarchy
5 | def breed(self): # find the common behavior in the hierarchy
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.07 Changing Float Number Assertions/assertDelta.java:
--------------------------------------------------------------------------------
1 | Assert.assertEquals(0.0012f, 0.0014f, 0.0002); // true
2 | Assert.assertEquals(0.0012f, 0.0014f, 0.0001); // false
3 | // The last parameter is the delta threshold
4 |
5 | Assert.assertEquals(12 / 10000, 12 / 10000); // true
6 | Assert.assertEquals(12 / 10000, 14 / 10000); // false
--------------------------------------------------------------------------------
/Code/Chapter 23 Meta Programming/23.04 Removing Dynamic Methods/explicit.rb:
--------------------------------------------------------------------------------
1 | class Skynet < ActiveRecord::Base
2 | # define some attributes explicitly
3 | attr_accessor :asimovsFirstLaw, :asimovsSecondLaw, :asimovsThirdLaw
4 |
5 | # define some methods explicitly
6 | def takeoverTheWorld
7 | # implementation
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.03 Unifying Case Conventions/standard.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": 2,
3 | "userId": 666,
4 | "accountNumber": "12345-12345-12345",
5 | "updatedAt": "2022-01-07T02:23:41.305Z",
6 | "createdAt": "2019-01-07T02:23:41.305Z",
7 | "deletedAt": "2022-01-07T02:23:41.305Z"
8 | // This doesn't mean THIS standard is the right one
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.01 Narrowing Reused Variables/temp.java:
--------------------------------------------------------------------------------
1 | // print line total
2 | double total = item.getPrice() * item.getQuantity();
3 | System.out.println("Line total: " + total);
4 |
5 | // print amount total
6 | total = order.getTotal() - order.getDiscount();
7 | System.out.println( "Amount due: " + total);
8 |
9 | // 'total' variable is reused
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.17 Removing Gratitous Context from Names/Gratuitous.rs:
--------------------------------------------------------------------------------
1 | struct WEBBExoplanet {
2 | name: String,
3 | mass: f64,
4 | radius: f64,
5 | distance: f64,
6 | orbital_period: f64,
7 | }
8 |
9 | struct WEBBGalaxy {
10 | name: String,
11 | classification: String,
12 | distance: f64,
13 | age: f64,
14 | }
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.03 Breaking God Objects/broken.js:
--------------------------------------------------------------------------------
1 | public static class GameConstants
2 | {
3 | public const int MaxPlayers = 10;
4 | }
5 |
6 | public static class LanguageConstants
7 | {
8 | public const string DefaultLanguage = "en-US";
9 | }
10 |
11 | public static class MathConstants
12 | {
13 | public const double Pi = 3.14159;
14 | }
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.15 Refactoring Data Clumps/dataclump.cs:
--------------------------------------------------------------------------------
1 | public class DinnerTable
2 | {
3 | public DinnerTable(Person guest, DateTime from, DateTime to)
4 | {
5 | Guest = guest;
6 | From = from;
7 | To = to;
8 | }
9 | private Person Guest;
10 | private DateTime From;
11 | private DateTime To;
12 | }
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.09 Migrating Empty Classes/code class.js:
--------------------------------------------------------------------------------
1 | class ShopItem {
2 | code() { }
3 | description() { }
4 | }
5 |
6 | class BookItem extends ShopItem {
7 | code() { return 'book' }
8 | description() { return 'some book'}
9 | }
10 |
11 | // concrete Class has no real behavior, just return different 'data'
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.14 Generating Good Error Messages/balanceError.py:
--------------------------------------------------------------------------------
1 | def get_balance(address):
2 | url = "https://blockchain.info/q/addressbalance/" + address
3 | response = requests.get(url)
4 | if response.status_code == 200:
5 | return response.text
6 | else:
7 | raise BlockchainNotReachableError("Error reaching blockchain")
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.04 Reducing Overgeneralization/speculative.rs:
--------------------------------------------------------------------------------
1 | fn validate_size(value: i32) {
2 | validate_integer(value);
3 | }
4 |
5 | fn validate_years(value: i32) {
6 | validate_integer(value);
7 | }
8 |
9 | fn validate_integer(value: i32) {
10 | validate_type(value, :integer);
11 | validate_min_integer(value, 0);
12 | }
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.08 Removing Callback Events Based On Implementation/cuopledEvent.js:
--------------------------------------------------------------------------------
1 | const Item = ({name, handlePageChange)} =>
2 |
3 | {name}
4 |
5 |
6 | // handlePageChange is coupled with what you decide to do
7 | // instead of what really happened
8 | //
9 | // You cannot reuse this kind of callback
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.08 Removing Callback Events Based On Implementation/domainAgnostic.js:
--------------------------------------------------------------------------------
1 | const Item = ({name, onItemSelected)} =>
2 |
3 | {name}
4 |
5 |
6 | // onItemSelected will be called just when an item was selected. KISS
7 | // Parent can decide what to do (or do nothing)
8 | // You defer the decision
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.02 Breaking Yo-Yo Hierarchies/hierarchy.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | abstract class Controller {}
4 |
5 | class BaseController extends Controller {}
6 | class SimpleController extends BaseController {}
7 | class ControllerBase extends SimpleController {}
8 | class LoggedController extends ControllerBase {}
9 | class RealController extends LoggedController {}
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.02 Standardizing Indentations/formatted.py:
--------------------------------------------------------------------------------
1 | def calculate_average(numbers):
2 | total = 0
3 | count = 0
4 | for number in numbers:
5 | total += number
6 | count += 1
7 | average = total / count
8 | return average
9 |
10 | numbers = [1, 2, 3, 4, 5]
11 | print("The average is:", calculate_average(numbers))
12 |
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.02 Replacing Singletons/Singleton.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | class God {
4 | private static $instance = null;
5 |
6 | private function __construct() { }
7 |
8 | public static function getInstance() {
9 | if (null === self::$instance) {
10 | self::$instance = new self();
11 | }
12 | return self::$instance;
13 | }
14 | }
--------------------------------------------------------------------------------
/Code/Chapter 24 Types/24.02 Dealing with Truthy Values/explicit.py:
--------------------------------------------------------------------------------
1 | if len(vaccines) == 0:
2 | print ("There are no vaccines yet. Keep researching")
3 | else:
4 | print ("Let's get vaccinated")
5 |
6 | if len(virus) == 0:
7 | print ("You are free to get out. Not masks are necessary")
8 | else:
9 | print ("There are some virus around. Take extra care")
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.05 Removing Design Pattern Abuses/abuser.java:
--------------------------------------------------------------------------------
1 | public final class FileTreeComposite {
2 | // name should be inferred from behavior
3 | }
4 |
5 | public final class DateTimeConverterAdapterSingleton { }
6 | public final class PermutationSorterStrategy { }
7 | public final class NetworkPacketObserver { }
8 | public final class AccountsComposite { }
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.05 Changing Structural Optimizations/optimizedforloop.js:
--------------------------------------------------------------------------------
1 | for (k = 0; k < 3 * 3; ++k) {
2 | i = Math.floor(k / 3);
3 | j = k % 3;
4 | console.log(i + ' ' + j);
5 | }
6 |
7 | // This cryptic piece of code iterates a
8 | // two-dimensional array
9 | // You don't have proof this will be useful
10 | // In real contexts
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.03 Renaming MyObjects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.3 Renaming MyObjects
2 |
3 |
4 | [https://gist.github.com/mcsee/5c9ab47e5af40a643dee30ace2b57a93](https://gist.github.com/mcsee/5c9ab47e5af40a643dee30ace2b57a93)
5 |
6 | [https://gist.github.com/mcsee/8d230b138e3220e08064acedd585dd7d](https://gist.github.com/mcsee/8d230b138e3220e08064acedd585dd7d)
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.02 Standardizing Indentations/badformat.py:
--------------------------------------------------------------------------------
1 | def calculate_average(numbers):
2 | total = 0
3 | count = 0
4 | for number in numbers:
5 | total += number
6 | count += 1
7 | average = total / count
8 | return average
9 |
10 | numbers = [1, 2, 3, 4, 5]
11 | print("The average is:", calculate_average(numbers))
12 |
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.02 Removing SettingsConfigs/pluggable.js:
--------------------------------------------------------------------------------
1 | class VerySpecificAndSmallObjectDealingWithPersistency {
2 | constructor(retrieveStrategy) {
3 | this.retrieveStrategy = retrieveStrategy;
4 | }
5 | retrieveData() {
6 | this.retrieveStrategy.retrieveData();
7 | }
8 | }
9 | // You get rid of the if condition by using a polymorphic strategy
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.05 Removing Excess Methods/smallclasses.java:
--------------------------------------------------------------------------------
1 | public class Printer {
2 | public void print() { }
3 | }
4 |
5 | public class DateToStringFormatter {
6 | public void format() { }
7 | }
8 |
9 | public class Database {
10 | public void persist() { }
11 | }
12 |
13 | public class RadioTelescope {
14 | public void solveFermiParadox() { }
15 | }
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.01 Removing Dead Code/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 12 YAGNI - 12.1 Removing Dead Code
2 |
3 |
4 | [https://gist.github.com/mcsee/9e793df7489a96dc27d29d0f4e963bdf](https://gist.github.com/mcsee/9e793df7489a96dc27d29d0f4e963bdf)
5 |
6 | [https://gist.github.com/mcsee/e1075cc971b5f7af28e37d29b492735d](https://gist.github.com/mcsee/e1075cc971b5f7af28e37d29b492735d)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.02 Renaming Flag Variables for Events/declarativeFlag.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function dummy()
4 | {
5 | $atLeastOneElementWasFound = false;
6 |
7 | while (!$atLeastOneElementWasFound) {
8 |
9 | $elementSatisfies = doSomething();
10 | if ($elementSatisfies) {
11 | $atLeastOneElementWasFound = true;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.07 Adding Implicit Else/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.7 Adding Implicit Else
2 |
3 |
4 | [https://gist.github.com/mcsee/8d2eb5957180d324326e2c30a72166f6](https://gist.github.com/mcsee/8d2eb5957180d324326e2c30a72166f6)
5 |
6 | [https://gist.github.com/mcsee/34f2e6cc97fb6ef9cb77f8998aaa790e](https://gist.github.com/mcsee/34f2e6cc97fb6ef9cb77f8998aaa790e)
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.06 Removing DTOs/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 3 Anemic Models - 3.6 Removing DTOs
2 |
3 |
4 | [https://gist.github.com/mcsee/91a2d630101ba6137f64195e76c1b266](https://gist.github.com/mcsee/91a2d630101ba6137f64195e76c1b266)
5 |
6 | [https://gist.github.com/mcsee/e1ecfdec6bd0fbe72f2d9ee7664af1c4](https://gist.github.com/mcsee/e1ecfdec6bd0fbe72f2d9ee7664af1c4)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.04 Renaming the Result/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.4 Renaming the Result
2 |
3 |
4 | [https://gist.github.com/mcsee/eba3cf3c61494bd4e6a087776bfc5484](https://gist.github.com/mcsee/eba3cf3c61494bd4e6a087776bfc5484)
5 |
6 | [https://gist.github.com/mcsee/35dba1f621ebe19431e5fbe693546c9a](https://gist.github.com/mcsee/35dba1f621ebe19431e5fbe693546c9a)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.06 Renaming Long Names/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.6 Renaming Long Names
2 |
3 |
4 | [https://gist.github.com/mcsee/661d68a82e80799c6f9330d33c271a0b](https://gist.github.com/mcsee/661d68a82e80799c6f9330d33c271a0b)
5 |
6 | [https://gist.github.com/mcsee/7da772566dee2fb79f3bfea13196ee22](https://gist.github.com/mcsee/7da772566dee2fb79f3bfea13196ee22)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.18 Avoiding Data Naming/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.18 Avoiding Data Naming
2 |
3 |
4 | [https://gist.github.com/mcsee/0c0c6b9e9e8a5b2aa4dfe32828c9cbc5](https://gist.github.com/mcsee/0c0c6b9e9e8a5b2aa4dfe32828c9cbc5)
5 |
6 | [https://gist.github.com/mcsee/945e6a64fd3167637ff1e1eb872ff179](https://gist.github.com/mcsee/945e6a64fd3167637ff1e1eb872ff179)
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.03 Removing Logical Comments/real code.js:
--------------------------------------------------------------------------------
1 | if (cart.items() > 11 && user.isRetail()) {
2 | doStuff();
3 | }
4 | doMore();
5 | // Production code
6 |
7 | // Either if you need to force or skip the condition
8 | // you can do it with a covering test forcing
9 | // real world scenario and not the code
10 |
11 | testLargeCartItems()
12 | testUserIsRetail()
--------------------------------------------------------------------------------
/Code/Chapter 15 Null/15.01 Creating Null Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 15 Null - 15.1 Creating Null Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/2f7aee362e99fbe447d8c1e8aaeb9f8e](https://gist.github.com/mcsee/2f7aee362e99fbe447d8c1e8aaeb9f8e)
5 |
6 | [https://gist.github.com/mcsee/a7571cf0ce9e7666bd6a393520f9a968](https://gist.github.com/mcsee/a7571cf0ce9e7666bd6a393520f9a968)
--------------------------------------------------------------------------------
/Code/Chapter 15 Null/15.03 Converting Optional Attributes to a Collection/optional.js:
--------------------------------------------------------------------------------
1 | class Person {
2 | constructor(name, email) {
3 | this.name = name;
4 | this.email = email;
5 | }
6 |
7 | email() {
8 | return this.email;
9 | // might be null
10 | }
11 | }
12 |
13 | // You cannot use safely person.email()
14 | // You need to check for null explicitly
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.10 Removing Code from Destructors/destructor.cpp:
--------------------------------------------------------------------------------
1 | class File {
2 | public:
3 | File(const std::string& filename) {
4 | file_ = fopen(filename.c_str(), "r");
5 | }
6 |
7 | ~File() {
8 | if (file_) {
9 | fclose(file_);
10 | }
11 | }
12 |
13 | private:
14 | FILE* file_;
15 | };
16 |
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.12 Completing Empty Implementations/empty.js:
--------------------------------------------------------------------------------
1 | class MerchantProcessor {
2 | processPayment(amount) {
3 | // no default implementation
4 | }
5 | }
6 |
7 | class MockMerchantProcessor extends MerchantProcessor {
8 | processPayment(amount) {
9 | // Empty implementation to comply with the compiler
10 | // Won't do anything
11 | }
12 | }
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.01 Sanitizing Inputs/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 25 Security - 25.1 Sanitizing Inputs
2 |
3 |
4 | [https://gist.github.com/mcsee/d72d1e6617755cd8eff723b4dba90078](https://gist.github.com/mcsee/d72d1e6617755cd8eff723b4dba90078)
5 |
6 | [https://gist.github.com/mcsee/2c19c64f268afb946ee8560e19cf444f](https://gist.github.com/mcsee/2c19c64f268afb946ee8560e19cf444f)
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.08 Removing Getters/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 3 Anemic Models - 3.8 Removing Getters
2 |
3 |
4 | [https://gist.github.com/mcsee/39d40cf2f0d4159c95d90243c59a4df5](https://gist.github.com/mcsee/39d40cf2f0d4159c95d90243c59a4df5)
5 |
6 | [https://gist.github.com/mcsee/cd465eb9ca4f2771fb3dc5e30dc491cc](https://gist.github.com/mcsee/cd465eb9ca4f2771fb3dc5e30dc491cc)
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.02 Declaring Variables to Be Variable/constant.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | define("USER_PASSWORD", '123456')
4 |
5 | function configureUser() {
6 | $user = new User(USER_PASSWORD);
7 | }
8 |
9 | // or
10 |
11 | function configureUser() {
12 | $user = new User(userPassword());
13 | }
14 |
15 | function userPassword() : string {
16 | return '123456';
17 | }
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.08 Preventing Hoisting/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 5 Mutability - 5.8 Preventing Hoisting
2 |
3 |
4 | [https://gist.github.com/mcsee/6d889d8015a9acd6b8de8382e7dd28fc](https://gist.github.com/mcsee/6d889d8015a9acd6b8de8382e7dd28fc)
5 |
6 | [https://gist.github.com/mcsee/fe321a8c79ef2b6520e752ad091f20c3](https://gist.github.com/mcsee/fe321a8c79ef2b6520e752ad091f20c3)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.01 Narrowing Reused Variables/notreuse.java:
--------------------------------------------------------------------------------
1 | function printLineTotal() {
2 | double lineTotal = item.getPrice() * item.getQuantity();
3 | System.out.println("Line total: " + lineTotal);
4 | }
5 |
6 | function printAmountTotal() {
7 | double ammountTotal = order.getTotal() - order.getDiscount();
8 | System.out.println( "Amount due: " + ammountTotal);
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.01 Expanding Abbreviations/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.1 Expanding Abbreviations
2 |
3 |
4 | [https://gist.github.com/mcsee/946b6391e043d6abec9a3ae5976c5d8f](https://gist.github.com/mcsee/946b6391e043d6abec9a3ae5976c5d8f)
5 |
6 | [https://gist.github.com/mcsee/6b5865d3a16ed5ccccd34348070d7d62](https://gist.github.com/mcsee/6b5865d3a16ed5ccccd34348070d7d62)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.07 Renaming Abstract Names/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.7 Renaming Abstract Names
2 |
3 |
4 | [https://gist.github.com/mcsee/568bc61348f648e3e0db8434b59b92a2](https://gist.github.com/mcsee/568bc61348f648e3e0db8434b59b92a2)
5 |
6 | [https://gist.github.com/mcsee/106a64e384b1348dea8b1d486b4bacc5](https://gist.github.com/mcsee/106a64e384b1348dea8b1d486b4bacc5)
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.03 Removing Bitwise Premature Optimizations/birwise.js:
--------------------------------------------------------------------------------
1 | const nowInSeconds = ~~(Date.now() / 1000)
2 |
3 | // The double bitwise NOT operator ~~
4 | // is a bitwise operation that performs a bitwise
5 | // negation followed by a bitwise negation again.
6 | // This operation effectively truncates any decimal places
7 | // converting the result to an integer.
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.09 Removing Queries from Constructors/constructor.java:
--------------------------------------------------------------------------------
1 | public class Person {
2 | int childrenCount;
3 |
4 | public Person(int id, int childrenCount) {
5 | this.childrenCount = childrenCount;
6 | // You can assign the number in the constructor
7 | // Accidental Database is decoupled
8 | // You can test the object
9 | }
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.02 Replacing Singletons/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.2 Replacing Singletons
2 |
3 |
4 | [https://gist.github.com/mcsee/5f0b4685e3af22e2a0a82f9f642c5c79](https://gist.github.com/mcsee/5f0b4685e3af22e2a0a82f9f642c5c79)
5 |
6 | [https://gist.github.com/mcsee/48af2ebb8874c53f5aa5091c24c832e5](https://gist.github.com/mcsee/48af2ebb8874c53f5aa5091c24c832e5)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.03 Breaking God Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.3 Breaking God Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/402d6689b9a9bdef6a0cedf4e8974805](https://gist.github.com/mcsee/402d6689b9a9bdef6a0cedf4e8974805)
5 |
6 | [https://gist.github.com/mcsee/d26aa5ca0e29c906689c7e0b3be8cd54](https://gist.github.com/mcsee/d26aa5ca0e29c906689c7e0b3be8cd54)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.06 Removing Flaky Tests/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.6 Removing Flaky Tests
2 |
3 |
4 | [https://gist.github.com/mcsee/20c94ec159e6333ddd5891b4af0d5688](https://gist.github.com/mcsee/20c94ec159e6333ddd5891b4af0d5688)
5 |
6 | [https://gist.github.com/mcsee/e89bdc655b7248598e0e8ccd3e94997d](https://gist.github.com/mcsee/e89bdc655b7248598e0e8ccd3e94997d)
--------------------------------------------------------------------------------
/Code/Chapter 24 Types/24.01 Removing Type Checking/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 24 Types - 24.1 Removing Type Checking
2 |
3 |
4 | [https://gist.github.com/mcsee/a2307973172b62bb9dc7b11ef7450220](https://gist.github.com/mcsee/a2307973172b62bb9dc7b11ef7450220)
5 |
6 | [https://gist.github.com/mcsee/5c0218fcf1362228f406e463f79171a9](https://gist.github.com/mcsee/5c0218fcf1362228f406e463f79171a9)
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.09 Preventing Object Orgy/intimate.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class Point {
4 | public $x;
5 | public $y;
6 | }
7 |
8 | final class DistanceCalculator {
9 | function distanceBetween(Point $origin, Point $destination) {
10 | return sqrt((($destination->x - $origin->x) ^ 2) +
11 | (($destination->y - $origin->y) ^ 2));
12 | }
13 | }
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.01 Changing var to const/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 5 Mutability - 5.1 Changing var to const
2 |
3 |
4 | [https://gist.github.com/mcsee/f310bf19719788bfe2dbca3dab16a2c3](https://gist.github.com/mcsee/f310bf19719788bfe2dbca3dab16a2c3)
5 |
6 | [https://gist.github.com/mcsee/c0c6bf0726100b918e5aa04955519465](https://gist.github.com/mcsee/c0c6bf0726100b918e5aa04955519465)
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.07 Removing Side Effects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 5 Mutability - 5.7 Removing Side Effects
2 |
3 |
4 | [https://gist.github.com/mcsee/e532e326a6b5ac7d4b88b9aadaa86c0b](https://gist.github.com/mcsee/e532e326a6b5ac7d4b88b9aadaa86c0b)
5 |
6 | [https://gist.github.com/mcsee/9ce2320f04f2a6f2e0c24e581e472091](https://gist.github.com/mcsee/9ce2320f04f2a6f2e0c24e581e472091)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.03 Removing Versioned Methods/versioned.js:
--------------------------------------------------------------------------------
1 | findMatch()
2 | findMatch_new()
3 | findMatch_newer()
4 | findMatch_newest()
5 | findMatch_version2()
6 | findMatch_old()
7 | findMatch_working()
8 | findMatch_for_real()
9 | findMatch_20200229()
10 | findMatch_thisoneisnewer()
11 | findMatch_themostnewestone()
12 | findMatch_thisisit()
13 | findMatch_thisisit_for_real()
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.04 Renaming Result Variables/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.4 Renaming Result Variables
2 |
3 |
4 | [https://gist.github.com/mcsee/9d1f20a108047109bf229baf1c4c9976](https://gist.github.com/mcsee/9d1f20a108047109bf229baf1c4c9976)
5 |
6 | [https://gist.github.com/mcsee/75488df759013fcc4f3381b1006b7f82](https://gist.github.com/mcsee/75488df759013fcc4f3381b1006b7f82)
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.01 Removing Commented Code/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 8 Comments - 8.1 Removing Commented Code
2 |
3 |
4 | [https://gist.github.com/mcsee/ff64e843938e642edb15cc473008bdc2](https://gist.github.com/mcsee/ff64e843938e642edb15cc473008bdc2)
5 |
6 | [https://gist.github.com/mcsee/4d485268c773366069213c5b915acf89](https://gist.github.com/mcsee/4d485268c773366069213c5b915acf89)
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.04 Removing Getter Comments/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 8 Comments - 8.4 Removing Getter Comments
2 |
3 |
4 | [https://gist.github.com/mcsee/29cd4411aa32467291998e467e6ef503](https://gist.github.com/mcsee/29cd4411aa32467291998e467e6ef503)
5 |
6 | [https://gist.github.com/mcsee/bf1ab1d44b078d797796d19554032591](https://gist.github.com/mcsee/bf1ab1d44b078d797796d19554032591)
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.04 Writing Code in English/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 9 Standards - 9.4 Writing Code in English
2 |
3 |
4 | [https://gist.github.com/mcsee/498a2b777034a67a6725885a20d30c15](https://gist.github.com/mcsee/498a2b777034a67a6725885a20d30c15)
5 |
6 | [https://gist.github.com/mcsee/34f1d56858e83e39ebda706a05315454](https://gist.github.com/mcsee/34f1d56858e83e39ebda706a05315454)
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.06 Fixing Broken Windows/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 9 Standards - 9.6 Fixing Broken Windows
2 |
3 |
4 | [https://gist.github.com/mcsee/5577d55a7a059073137b7d892b218e80](https://gist.github.com/mcsee/5577d55a7a059073137b7d892b218e80)
5 |
6 | [https://gist.github.com/mcsee/952f2de180ccdbe8bb73f7dfac162fe5](https://gist.github.com/mcsee/952f2de180ccdbe8bb73f7dfac162fe5)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.07 Reducing Import Lists/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 11 Bloaters - 11.7 Reducing Import Lists
2 |
3 |
4 | [https://gist.github.com/mcsee/1ee88717de17b2cc57b12fbd5d6e9bf2](https://gist.github.com/mcsee/1ee88717de17b2cc57b12fbd5d6e9bf2)
5 |
6 | [https://gist.github.com/mcsee/920db69fda667e32b9d682fdab61c634](https://gist.github.com/mcsee/920db69fda667e32b9d682fdab61c634)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.03 Reifying Boolean Variables/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.3 Reifying Boolean Variables
2 |
3 |
4 | [https://gist.github.com/mcsee/5a3e8e05def917a29b84be7264493a67](https://gist.github.com/mcsee/5a3e8e05def917a29b84be7264493a67)
5 |
6 | [https://gist.github.com/mcsee/66956e6ccfe8126d0819fa193d793dd5](https://gist.github.com/mcsee/66956e6ccfe8126d0819fa193d793dd5)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.10 Rewriting Nested Arrow Code/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.10 Rewriting Nested Arrow Code
2 |
3 |
4 | [https://gist.github.com/mcsee/0313b55715cf050e4eadb80e7b0ffad2](https://gist.github.com/mcsee/0313b55715cf050e4eadb80e7b0ffad2)
5 |
6 | [https://gist.github.com/mcsee/a01fc3411e8aff647a2ff0812f313318](https://gist.github.com/mcsee/a01fc3411e8aff647a2ff0812f313318)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.15 Changing Equal Comparison/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.15 Changing Equal Comparison
2 |
3 |
4 | [https://gist.github.com/mcsee/d3eda35a36e6dfe7cb292ff2be5a7b71](https://gist.github.com/mcsee/d3eda35a36e6dfe7cb292ff2be5a7b71)
5 |
6 | [https://gist.github.com/mcsee/7ecfc60fccc9053db2a7b22dc30f31cd](https://gist.github.com/mcsee/7ecfc60fccc9053db2a7b22dc30f31cd)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.18 Rewriting Nested Ternaries/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.18 Rewriting Nested Ternaries
2 |
3 |
4 | [https://gist.github.com/mcsee/45754a6d586d067627c4796748686384](https://gist.github.com/mcsee/45754a6d586d067627c4796748686384)
5 |
6 | [https://gist.github.com/mcsee/4ac913c6d842c4f0fc9d8e9998348335](https://gist.github.com/mcsee/4ac913c6d842c4f0fc9d8e9998348335)
--------------------------------------------------------------------------------
/Code/Chapter 15 Null/15.02 Removing Optional Chaining/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 15 Null - 15.2 Removing Optional Chaining
2 |
3 |
4 | [https://gist.github.com/mcsee/a976521e75a08ca0c57cb0153039e67e](https://gist.github.com/mcsee/a976521e75a08ca0c57cb0153039e67e)
5 |
6 | [https://gist.github.com/mcsee/1f0771dc50c77d39c6577405142e52e8](https://gist.github.com/mcsee/1f0771dc50c77d39c6577405142e52e8)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.09 Removing the Middleman/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.9 Removing the Middleman
2 |
3 |
4 | [https://gist.github.com/mcsee/8f89b53d0be21a6779e4be53673edf5c](https://gist.github.com/mcsee/8f89b53d0be21a6779e4be53673edf5c)
5 |
6 | [https://gist.github.com/mcsee/63674fe800fca77d3a7edc39bde428c8](https://gist.github.com/mcsee/63674fe800fca77d3a7edc39bde428c8)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.11 Avoiding Ripple Effect/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.11 Avoiding Ripple Effect
2 |
3 |
4 | [https://gist.github.com/mcsee/3861429b0a02eb2a3906d0f939cc1809](https://gist.github.com/mcsee/3861429b0a02eb2a3906d0f939cc1809)
5 |
6 | [https://gist.github.com/mcsee/7fbceedcae6aae7f15d392c9bbe0ffa1](https://gist.github.com/mcsee/7fbceedcae6aae7f15d392c9bbe0ffa1)
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.04 Removing Global Classes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 18 Globals - 18.4 Removing Global Classes
2 |
3 |
4 | [https://gist.github.com/mcsee/6b3f0e2a24ea7a6da72dadcbb36a8dd0](https://gist.github.com/mcsee/6b3f0e2a24ea7a6da72dadcbb36a8dd0)
5 |
6 | [https://gist.github.com/mcsee/9dd928bab5528d07b7f63b5d76821f4f](https://gist.github.com/mcsee/9dd928bab5528d07b7f63b5d76821f4f)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.01 Testing Private Methods/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.1 Testing Private Methods
2 |
3 |
4 | [https://gist.github.com/mcsee/47c21b9a717ee1ac9b7d2f10bbb7a2d0](https://gist.github.com/mcsee/47c21b9a717ee1ac9b7d2f10bbb7a2d0)
5 |
6 | [https://gist.github.com/mcsee/acf7c184cef3babb5251da6ea946f5ae](https://gist.github.com/mcsee/acf7c184cef3babb5251da6ea946f5ae)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.12 Rewriting Tests Depending on Dates/fixedAssert.java:
--------------------------------------------------------------------------------
1 | class DateTest {
2 | @Test
3 | void testNoFeatureFlagsAfterFixedDate() {
4 | LocalDate fixedDate = LocalDate.of(2023, 4, 4);
5 | LocalDate currentDate = LocalDate.now();
6 | Assertions.assertTrue(currentDate.isBefore(fixedDate) ||
7 | !featureFlag.isOn());
8 | }
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.05 Protecting Object Deserialization/unserializejson.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | def process_serialized_data(serialized_data):
4 | try:
5 | obj = json.loads(serialized_data)
6 | # Deserialize the JSON object
7 | # Does not execute code
8 | # ...
9 |
10 | user_data = '{"key": "value"}'
11 |
12 | process_serialized_data(user_data)
13 |
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.03 Reifying Associative Arrays/coordinateOperations.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class GeographicCoordinate {
4 |
5 | function distanceTo(GeographicCoordinate $coordinate) { }
6 | function pointInPolygon(Polygon $polygon) { }
7 | }
8 |
9 | // Now you are in geometry world (and not in the world of arrays anymore).
10 | // You can safely do many exciting things.
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.08 Correcting Spelling Mistakes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.8 Correcting Spelling Mistakes
2 |
3 |
4 | [https://gist.github.com/mcsee/a4c5716a56fdb9b1b743debae3adfb4c](https://gist.github.com/mcsee/a4c5716a56fdb9b1b743debae3adfb4c)
5 |
6 | [https://gist.github.com/mcsee/1fc16a4982d8f423107d3e64d3c31e48](https://gist.github.com/mcsee/1fc16a4982d8f423107d3e64d3c31e48)
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.02 Removing Obsolete Comments/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 8 Comments - 8.2 Removing Obsolete Comments
2 |
3 |
4 | [https://gist.github.com/mcsee/fd5b6b44920df66b6558be35f729f0f7](https://gist.github.com/mcsee/fd5b6b44920df66b6558be35f729f0f7)
5 |
6 | [https://gist.github.com/mcsee/36f9dde4301f0ab77c034aeba7c0b391](https://gist.github.com/mcsee/36f9dde4301f0ab77c034aeba7c0b391)
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.03 Removing Logical Comments/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 8 Comments - 8.3 Removing Logical Comments
2 |
3 |
4 | [https://gist.github.com/mcsee/a07a71db83f2c65adefffd736e77ee91](https://gist.github.com/mcsee/a07a71db83f2c65adefffd736e77ee91)
5 |
6 | [https://gist.github.com/mcsee/174010435acb2c12f45124f2a085fa51](https://gist.github.com/mcsee/174010435acb2c12f45124f2a085fa51)
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.01 Following Code Standards/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 9 Standards - 9.1 Following Code Standards
2 |
3 |
4 | [https://gist.github.com/mcsee/ef87aec745f654878ce71c844f786f17](https://gist.github.com/mcsee/ef87aec745f654878ce71c844f786f17)
5 |
6 | [https://gist.github.com/mcsee/55ade1bd7d835ef3804e86b55ec3abaa](https://gist.github.com/mcsee/55ade1bd7d835ef3804e86b55ec3abaa)
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.03 Unifying Case Conventions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 9 Standards - 9.3 Unifying Case Conventions
2 |
3 |
4 | [https://gist.github.com/mcsee/f0858b7401a061b1d87ad5e488a85bc3](https://gist.github.com/mcsee/f0858b7401a061b1d87ad5e488a85bc3)
5 |
6 | [https://gist.github.com/mcsee/3dd8fd30a0c8c50538b401cbfb746ecc](https://gist.github.com/mcsee/3dd8fd30a0c8c50538b401cbfb746ecc)
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.05 Unifying Parameter Order/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 9 Standards - 9.5 Unifying Parameter Order
2 |
3 |
4 | [https://gist.github.com/mcsee/1f21534bd7ddf9390271ed0badd7352b](https://gist.github.com/mcsee/1f21534bd7ddf9390271ed0badd7352b)
5 |
6 | [https://gist.github.com/mcsee/e33e4b69f36750d7a24621f70aba155c](https://gist.github.com/mcsee/e33e4b69f36750d7a24621f70aba155c)
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.01 Removing Repeated Code/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 10 Complexity - 10.1 Removing Repeated Code
2 |
3 |
4 | [https://gist.github.com/mcsee/b6df5d98efbecc9be783006d364e63f8](https://gist.github.com/mcsee/b6df5d98efbecc9be783006d364e63f8)
5 |
6 | [https://gist.github.com/mcsee/4eb63e5acfcdda39b24e3f6a73eb0bdb](https://gist.github.com/mcsee/4eb63e5acfcdda39b24e3f6a73eb0bdb)
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.09 Removing Poltergeist Objects/driver.cs:
--------------------------------------------------------------------------------
1 | public class Driver
2 | {
3 | private Car car;
4 |
5 | public Driver(Car car)
6 | {
7 | this.car = car;
8 | }
9 |
10 | public void DriveCar()
11 | {
12 | car.driveCar();
13 | }
14 | }
15 |
16 | Car porsche = new Car();
17 | Driver homer = new Driver(porsche);
18 | homer.DriveCar();
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.01 Breaking Too Long Methods/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 11 Bloaters - 11.1 Breaking Too Long Methods
2 |
3 |
4 | [https://gist.github.com/mcsee/1f12fb2d0cb9f8eea202526597cf4b83](https://gist.github.com/mcsee/1f12fb2d0cb9f8eea202526597cf4b83)
5 |
6 | [https://gist.github.com/mcsee/0f66ce8c2bba8990e44a36495fa4c3e1](https://gist.github.com/mcsee/0f66ce8c2bba8990e44a36495fa4c3e1)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.02 Reducing Excess Arguments/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 11 Bloaters - 11.2 Reducing Excess Arguments
2 |
3 |
4 | [https://gist.github.com/mcsee/ea7d32472830d5ea877be1438807fe89](https://gist.github.com/mcsee/ea7d32472830d5ea877be1438807fe89)
5 |
6 | [https://gist.github.com/mcsee/200a18dd99a76a95155df4cb032b1d10](https://gist.github.com/mcsee/200a18dd99a76a95155df4cb032b1d10)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.03 Reducing Excess Variables/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 11 Bloaters - 11.3 Reducing Excess Variables
2 |
3 |
4 | [https://gist.github.com/mcsee/b3d04c90186e88bca3e3353af7c24284](https://gist.github.com/mcsee/b3d04c90186e88bca3e3353af7c24284)
5 |
6 | [https://gist.github.com/mcsee/21117af327d700e359d1eccf2d45accc](https://gist.github.com/mcsee/21117af327d700e359d1eccf2d45accc)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.05 Removing Excess Methods/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 11 Bloaters - 11.5 Removing Excess Methods
2 |
3 |
4 | [https://gist.github.com/mcsee/d1c326e90aa2feba4746c6e019999312](https://gist.github.com/mcsee/d1c326e90aa2feba4746c6e019999312)
5 |
6 | [https://gist.github.com/mcsee/c64e13c3ea97620ce02dab73ffc517b2](https://gist.github.com/mcsee/c64e13c3ea97620ce02dab73ffc517b2)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.08 Breaking 'And' Functions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 11 Bloaters - 11.8 Breaking 'And' Functions
2 |
3 |
4 | [https://gist.github.com/mcsee/059b9deb2e9e13c94a724b82e54f6fda](https://gist.github.com/mcsee/059b9deb2e9e13c94a724b82e54f6fda)
5 |
6 | [https://gist.github.com/mcsee/47a1f8cd217afd58bc47b373b91593ef](https://gist.github.com/mcsee/47a1f8cd217afd58bc47b373b91593ef)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.09 Breaking Fat Interfaces/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 11 Bloaters - 11.9 Breaking Fat Interfaces
2 |
3 |
4 | [https://gist.github.com/mcsee/dc549ce28d805020e657f227eef10c5f](https://gist.github.com/mcsee/dc549ce28d805020e657f227eef10c5f)
5 |
6 | [https://gist.github.com/mcsee/811c638d22fb50bff24336695a6750ae](https://gist.github.com/mcsee/811c638d22fb50bff24336695a6750ae)
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.04 Removing One-Use Interfaces/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 12 YAGNI - 12.4 Removing One-Use Interfaces
2 |
3 |
4 | [https://gist.github.com/mcsee/e86499e8b367ce0d5524c347ed821cda](https://gist.github.com/mcsee/e86499e8b367ce0d5524c347ed821cda)
5 |
6 | [https://gist.github.com/mcsee/c7c06a683be5fe72d481840c2720e0d5](https://gist.github.com/mcsee/c7c06a683be5fe72d481840c2720e0d5)
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.02 Enforcing Preconditions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 13 Fail Fast - 13.2 Enforcing Preconditions
2 |
3 |
4 | [https://gist.github.com/mcsee/61e95b5c7a8d697cb748cd49b43aab90](https://gist.github.com/mcsee/61e95b5c7a8d697cb748cd49b43aab90)
5 |
6 | [https://gist.github.com/mcsee/b5eebe620b66c510bafe04a7a4f8ef82](https://gist.github.com/mcsee/b5eebe620b66c510bafe04a7a4f8ef82)
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.03 Using Strict Parameters/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 13 Fail Fast - 13.3 Using Strict Parameters
2 |
3 |
4 | [https://gist.github.com/mcsee/d6efbffa513dae1c59059439c64eea1b](https://gist.github.com/mcsee/d6efbffa513dae1c59059439c64eea1b)
5 |
6 | [https://gist.github.com/mcsee/7876a9b6bacf55a72abcaf5e2ca2e008](https://gist.github.com/mcsee/7876a9b6bacf55a72abcaf5e2ca2e008)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.09 Avoiding Short Circuit Hacks/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.9 Avoiding Short Circuit Hacks
2 |
3 |
4 | [https://gist.github.com/mcsee/be2e697d71cfb438110d911c9e4751dc](https://gist.github.com/mcsee/be2e697d71cfb438110d911c9e4751dc)
5 |
6 | [https://gist.github.com/mcsee/5c48bd13ce74f1605cf8d6a8ed2de4d9](https://gist.github.com/mcsee/5c48bd13ce74f1605cf8d6a8ed2de4d9)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.17 Removing Gratuitous Booleans/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.17 Removing Gratuitous Booleans
2 |
3 |
4 | [https://gist.github.com/mcsee/dc73985cd7ff45aa7496f41f96e81fe3](https://gist.github.com/mcsee/dc73985cd7ff45aa7496f41f96e81fe3)
5 |
6 | [https://gist.github.com/mcsee/c8d0be601736520faa86a8d7e781be2f](https://gist.github.com/mcsee/c8d0be601736520faa86a8d7e781be2f)
--------------------------------------------------------------------------------
/Code/Chapter 15 Null/15.04 Using Real Objects for Null/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 15 Null - 15.4 Using Real Objects for Null
2 |
3 |
4 | [https://gist.github.com/mcsee/36ff0b92d6365291ba000de230e3924e](https://gist.github.com/mcsee/36ff0b92d6365291ba000de230e3924e)
5 |
6 | [https://gist.github.com/mcsee/baa5c877b821b807ef9c691569a4174d](https://gist.github.com/mcsee/baa5c877b821b807ef9c691569a4174d)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.04 Breaking Divergent Change/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.4 Breaking Divergent Change
2 |
3 |
4 | [https://gist.github.com/mcsee/398ed708b96ddabe79971b98edefce4a](https://gist.github.com/mcsee/398ed708b96ddabe79971b98edefce4a)
5 |
6 | [https://gist.github.com/mcsee/cb5736ef2d43863b8cae0ff060c1317a](https://gist.github.com/mcsee/cb5736ef2d43863b8cae0ff060c1317a)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.06 Removing Shotgun Surgery/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.6 Removing Shotgun Surgery
2 |
3 |
4 | [https://gist.github.com/mcsee/cb3d9eb1ede5297a16006a1453009867](https://gist.github.com/mcsee/cb3d9eb1ede5297a16006a1453009867)
5 |
6 | [https://gist.github.com/mcsee/23a8649a28ec56db1d0874c1a32b4fc7](https://gist.github.com/mcsee/23a8649a28ec56db1d0874c1a32b4fc7)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.08 Preventing Feature Envy/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.8 Preventing Feature Envy
2 |
3 |
4 | [https://gist.github.com/mcsee/4b3483f5be825913df7a6c709efebdbc](https://gist.github.com/mcsee/4b3483f5be825913df7a6c709efebdbc)
5 |
6 | [https://gist.github.com/mcsee/891b1df84cd9e0528fad2dae42322c54](https://gist.github.com/mcsee/891b1df84cd9e0528fad2dae42322c54)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.15 Refactoring Data Clumps/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.15 Refactoring Data Clumps
2 |
3 |
4 | [https://gist.github.com/mcsee/076c003ce49b9fc4af66f4dffeb71079](https://gist.github.com/mcsee/076c003ce49b9fc4af66f4dffeb71079)
5 |
6 | [https://gist.github.com/mcsee/a848e76a45559291a2f71cd76aa91961](https://gist.github.com/mcsee/a848e76a45559291a2f71cd76aa91961)
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.01 Reifying Global Functions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 18 Globals - 18.1 Reifying Global Functions
2 |
3 |
4 | [https://gist.github.com/mcsee/4713b63031ad073d46701b7b4c81b028](https://gist.github.com/mcsee/4713b63031ad073d46701b7b4c81b028)
5 |
6 | [https://gist.github.com/mcsee/74d9534ee563afc1fdf766b90115fb10](https://gist.github.com/mcsee/74d9534ee563afc1fdf766b90115fb10)
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.02 Reifying Static Functions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 18 Globals - 18.2 Reifying Static Functions
2 |
3 |
4 | [https://gist.github.com/mcsee/293dc79524550a542fc70db572d8e092](https://gist.github.com/mcsee/293dc79524550a542fc70db572d8e092)
5 |
6 | [https://gist.github.com/mcsee/b8cfaddb9085b92d21a434a2bca2b14e](https://gist.github.com/mcsee/b8cfaddb9085b92d21a434a2bca2b14e)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.11 Adding Coverage for Every Merge Request/orphanMergeRequest.ts:
--------------------------------------------------------------------------------
1 | export function sayHello(name: string): string {
2 | const lengthOfName = name.length;
3 | - const salutation =
4 | - `How are you ${name}?, I see your name has ${lengthOfName} letters!`;
5 | + const salutation =
6 | + `Hello ${name}, I see your name has ${lengthOfName} letters!`;
7 | return salutation;
8 | }
--------------------------------------------------------------------------------
/Code/Chapter 24 Types/24.02 Dealing with Truthy Values/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 24 Types - 24.2 Dealing with Truthy Values
2 |
3 |
4 | [https://gist.github.com/mcsee/8440adc57486989468045de4df3c9bef](https://gist.github.com/mcsee/8440adc57486989468045de4df3c9bef)
5 |
6 | [https://gist.github.com/mcsee/7f275da71e96bd4050e17c0ec7511c14](https://gist.github.com/mcsee/7f275da71e96bd4050e17c0ec7511c14)
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.02 Changing Sequential Ids/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 25 Security - 25.2 Changing Sequential Ids
2 |
3 |
4 | [https://gist.github.com/mcsee/095409b419d460484cc418d549861c98](https://gist.github.com/mcsee/095409b419d460484cc418d549861c98)
5 |
6 | [https://gist.github.com/mcsee/83b1660ec07e5bafd0a5b1c567f76aee](https://gist.github.com/mcsee/83b1660ec07e5bafd0a5b1c567f76aee)
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.02 Changing Sequential Ids/integerIDs.java:
--------------------------------------------------------------------------------
1 | class Book {
2 | private Long bookId; // book knows its ID
3 | private List authorIds; // book knows author IDs
4 | }
5 |
6 | Book harryPotter = new Book(1, List.of(2));
7 | Book designPatterns = new Book(2, List.of(4, 6, 7, 8));
8 | Book donQuixote = new Book(3, List.of(5));
9 |
10 | // You can scrape from now on
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.09 Preventing Object Orgy/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 3 Anemic Models - 3.9 Preventing Object Orgy
2 |
3 |
4 | [https://gist.github.com/mcsee/ee56984fadcd35eb91b7e2617eec875a](https://gist.github.com/mcsee/ee56984fadcd35eb91b7e2617eec875a)
5 |
6 | [https://gist.github.com/mcsee/4135a48a51ff4361359326f2d4b2076e](https://gist.github.com/mcsee/4135a48a51ff4361359326f2d4b2076e)
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.06 Freezing Mutable Constants/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 5 Mutability - 5.6 Freezing Mutable Constants
2 |
3 |
4 | [https://gist.github.com/mcsee/3317c6e127e2d8b800174415eb79a08e](https://gist.github.com/mcsee/3317c6e127e2d8b800174415eb79a08e)
5 |
6 | [https://gist.github.com/mcsee/e656ae640875909f55bd7eda10b4d227](https://gist.github.com/mcsee/e656ae640875909f55bd7eda10b4d227)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.02 Removing Empty Lines/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.2 Removing Empty Lines
2 |
3 |
4 | [https://gist.github.com/mcsee/3e7f0a453f04d443a98d3ffd99d9bfde](https://gist.github.com/mcsee/3e7f0a453f04d443a98d3ffd99d9bfde)
5 |
6 | [https://gist.github.com/mcsee/13ce5551b29a588db5dbb9903d714b84](https://gist.github.com/mcsee/13ce5551b29a588db5dbb9903d714b84)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.05 Renaming Variables Named After Types/role coupling.java:
--------------------------------------------------------------------------------
1 | public bool CheckIfStringHas3To7LowercaseCharsFollowedBy3or4Numbers
2 | (string password)
3 | {
4 | Regex stringHas3To7LowercaseCharsFollowedBy3or4Numbers =
5 | new Regex(@"[a-z]{2,7}[1-9]{3,4}")
6 | var hasMatch =
7 | stringHas3To7LowercaseCharsFollowedBy3or4Numbers.IsMatch(password);
8 | return hasMatch;
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.11 Renaming Basic Do Functions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.11 Renaming Basic / Do Functions
2 |
3 |
4 | [https://gist.github.com/mcsee/dd988af705942cfafd5811df60acaed2](https://gist.github.com/mcsee/dd988af705942cfafd5811df60acaed2)
5 |
6 | [https://gist.github.com/mcsee/ce98c6db785d947e77790c3cc6b4bad0](https://gist.github.com/mcsee/ce98c6db785d947e77790c3cc6b4bad0)
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.07 Replacing Comments with Tests/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 8 Comments - 8.7 Replacing Comments with Tests
2 |
3 |
4 | [https://gist.github.com/mcsee/99a20b92785fa34a4dd5c32a8623e8d4](https://gist.github.com/mcsee/99a20b92785fa34a4dd5c32a8623e8d4)
5 |
6 | [https://gist.github.com/mcsee/e73306c042cbc8f200fc149d78f24173](https://gist.github.com/mcsee/e73306c042cbc8f200fc149d78f24173)
--------------------------------------------------------------------------------
/Code/Chapter 09 Standards/9.02 Standardizing Indentations/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 9 Standards - 9.2 Standardizing Indentations
2 |
3 |
4 | [https://gist.github.com/mcsee/f0e5a66c59069833be76905f11a6da7b](https://gist.github.com/mcsee/f0e5a66c59069833be76905f11a6da7b)
5 |
6 | [https://gist.github.com/mcsee/3382696a06e5b8a1e5f032289fba3be3](https://gist.github.com/mcsee/3382696a06e5b8a1e5f032289fba3be3)
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.02 Removing SettingsConfigs/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 10 Complexity - 10.2 Removing Settings/Configs
2 |
3 |
4 | [https://gist.github.com/mcsee/f001710d13fd158e75313c9b54ffc1aa](https://gist.github.com/mcsee/f001710d13fd158e75313c9b54ffc1aa)
5 |
6 | [https://gist.github.com/mcsee/b4f9f8e80f19c89e99e10c999871ea2d](https://gist.github.com/mcsee/b4f9f8e80f19c89e99e10c999871ea2d)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.07 Reducing Import Lists/hiddenlayers.java:
--------------------------------------------------------------------------------
1 | import org.fermi.domainModel;
2 | import org.fermi.workflow;
3 |
4 | // You rely on few libraries
5 | // and you hide their implementation
6 | // So maybe transitive imports are the same
7 | // but you don't break encapsulation
8 |
9 | public class Demo {
10 | public static void main(String[] args) {
11 |
12 | }
13 | }
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.05 Removing Design Pattern Abuses/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 12 YAGNI - 12.5 Removing Design Pattern Abuses
2 |
3 |
4 | [https://gist.github.com/mcsee/a94aac5dd5fee1e1c19b4b07e87e7887](https://gist.github.com/mcsee/a94aac5dd5fee1e1c19b4b07e87e7887)
5 |
6 | [https://gist.github.com/mcsee/9adec62e0637199e351100eb2ece56f2](https://gist.github.com/mcsee/9adec62e0637199e351100eb2ece56f2)
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.06 Replacing Business Collections/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 12 YAGNI - 12.6 Replacing Business Collections
2 |
3 |
4 | [https://gist.github.com/mcsee/6e4e3684bbb29379a6bf30f4a00a2c7f](https://gist.github.com/mcsee/6e4e3684bbb29379a6bf30f4a00a2c7f)
5 |
6 | [https://gist.github.com/mcsee/2d15677ca73742cb2553aa4a098f3683](https://gist.github.com/mcsee/2d15677ca73742cb2553aa4a098f3683)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.08 Rewriting Conditional Arrow Code/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.8 Rewriting Conditional Arrow Code
2 |
3 |
4 | [https://gist.github.com/mcsee/b7125d33f30a8a37a40bc994fe7fcba6](https://gist.github.com/mcsee/b7125d33f30a8a37a40bc994fe7fcba6)
5 |
6 | [https://gist.github.com/mcsee/b0afdb15577225b97f66381872f373f1](https://gist.github.com/mcsee/b0afdb15577225b97f66381872f373f1)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.13 Extracting from Long Ternaries/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.13 Extracting from Long Ternaries
2 |
3 |
4 | [https://gist.github.com/mcsee/274faf5d13f9853f63228fa10ee45d7e](https://gist.github.com/mcsee/274faf5d13f9853f63228fa10ee45d7e)
5 |
6 | [https://gist.github.com/mcsee/36ef3f34e5767f120dcabe8eebda1072](https://gist.github.com/mcsee/36ef3f34e5767f120dcabe8eebda1072)
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.02 Removing Premature Optimization/premature.js:
--------------------------------------------------------------------------------
1 | class Person {
2 | ancestors() {
3 | cachedResults =
4 | GlobalPeopleSingletonCache.getInstance().relativesCache(this.id);
5 | if (cachedResults != null) {
6 | return (cachedResults.hashFor(this.id)).getAllParents();
7 | }
8 | return database().getAllParents(this.id);
9 | }
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.07 Removing Optional Arguments/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.7 Removing Optional Arguments
2 |
3 |
4 | [https://gist.github.com/mcsee/66738047685e798a4e4008e291dcff70](https://gist.github.com/mcsee/66738047685e798a4e4008e291dcff70)
5 |
6 | [https://gist.github.com/mcsee/559b802e5a6a0e1aa432e594fe5f28dc](https://gist.github.com/mcsee/559b802e5a6a0e1aa432e594fe5f28dc)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.17 Converting Fungible Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.17 Converting Fungible Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/3fc2c7089aa88088a73138ee6b62e675](https://gist.github.com/mcsee/3fc2c7089aa88088a73138ee6b62e675)
5 |
6 | [https://gist.github.com/mcsee/97a8fd4467d51b6769f7ba63210dddee](https://gist.github.com/mcsee/97a8fd4467d51b6769f7ba63210dddee)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.05 Removing Nested Classes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.5 Removing Nested Classes
2 |
3 |
4 | [https://gist.github.com/mcsee/836b485a9a9bb29e8292f9e79b867cbb](https://gist.github.com/mcsee/836b485a9a9bb29e8292f9e79b867cbb)
5 |
6 | [https://gist.github.com/mcsee/abcc622d9f0f27c40fd94202535dcced](https://gist.github.com/mcsee/abcc622d9f0f27c40fd94202535dcced)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.09 Migrating Empty Classes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.9 Migrating Empty Classes
2 |
3 |
4 | [https://gist.github.com/mcsee/729e6032d21c0c2997228680170ff768](https://gist.github.com/mcsee/729e6032d21c0c2997228680170ff768)
5 |
6 | [https://gist.github.com/mcsee/a8c680954291f8d9be4023ff8062b504](https://gist.github.com/mcsee/a8c680954291f8d9be4023ff8062b504)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.05 Refining Generic Assertions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.5 Refining Generic Assertions
2 |
3 |
4 | [https://gist.github.com/mcsee/6712052beddeaac0d959785726fa82ca](https://gist.github.com/mcsee/6712052beddeaac0d959785726fa82ca)
5 |
6 | [https://gist.github.com/mcsee/d9f05a81f7689e86c353ccd6a29e8306](https://gist.github.com/mcsee/d9f05a81f7689e86c353ccd6a29e8306)
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.08 Narrowing Exception Tries/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 22 Exceptions - 22.8 Narrowing Exception Tries
2 |
3 |
4 | [https://gist.github.com/mcsee/0ff3c46988812be98da1e256b54c00d1](https://gist.github.com/mcsee/0ff3c46988812be98da1e256b54c00d1)
5 |
6 | [https://gist.github.com/mcsee/0d7e270416ebc934fbfbe8934175e52c](https://gist.github.com/mcsee/0d7e270416ebc934fbfbe8934175e52c)
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.05 Reifying Timestamps/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 4 Primitive Obsession - 4.5 Reifying Timestamps
2 |
3 |
4 | [https://gist.github.com/mcsee/395fe180085be252c2ff97020b9f3bc9](https://gist.github.com/mcsee/395fe180085be252c2ff97020b9f3bc9)
5 |
6 | [https://gist.github.com/mcsee/67d4df804716d5fb10bcbb7d8ce6f7fe](https://gist.github.com/mcsee/67d4df804716d5fb10bcbb7d8ce6f7fe)
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.04 Avoiding Mutable const Arrays/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 5 Mutability - 5.4 Avoiding Mutable const Arrays
2 |
3 |
4 | [https://gist.github.com/mcsee/03563ad0268ac240336fcab195f8da29](https://gist.github.com/mcsee/03563ad0268ac240336fcab195f8da29)
5 |
6 | [https://gist.github.com/mcsee/c1610a6305aa2a1f3b9add686652d0b7](https://gist.github.com/mcsee/c1610a6305aa2a1f3b9add686652d0b7)
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.05 Removing Lazy Initialization/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 5 Mutability - 5.5 Removing Lazy Initialization
2 |
3 |
4 | [https://gist.github.com/mcsee/0d762f54e37352ed72eee7e77d0ae5e0](https://gist.github.com/mcsee/0d762f54e37352ed72eee7e77d0ae5e0)
5 |
6 | [https://gist.github.com/mcsee/dbd08513d5005325e63954515052555d](https://gist.github.com/mcsee/dbd08513d5005325e63954515052555d)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.09 Separating What and How/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.9 Separating What and How
2 |
3 |
4 | [https://gist.github.com/mcsee/d6d3df14e1268f9308fdd2121ccd598d](https://gist.github.com/mcsee/d6d3df14e1268f9308fdd2121ccd598d)
5 |
6 | [https://gist.github.com/mcsee/4fb3c004b00d81cfb1749bd22394772c](https://gist.github.com/mcsee/4fb3c004b00d81cfb1749bd22394772c)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.09 Separating What and How/coupled.js:
--------------------------------------------------------------------------------
1 | class Workflow {
2 | moveToNextTransition() {
3 | // You couple the business rule with the accidental implementation
4 | if (this.stepWork.hasPendingTasks()) {
5 | throw new Error('Preconditions are not met yet..');
6 | } else {
7 | this.moveToNextStep();
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.13 Avoiding Callback Hell/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.13 Avoiding Callback Hell
2 |
3 |
4 | [https://gist.github.com/mcsee/110f803da03a27f4024ebbce97154307](https://gist.github.com/mcsee/110f803da03a27f4024ebbce97154307)
5 |
6 | [https://gist.github.com/mcsee/90622aea76933ddedea1fd344dbe4751](https://gist.github.com/mcsee/90622aea76933ddedea1fd344dbe4751)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.13 Removing Collection from Names/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.13 Removing "Collection" from Names
2 |
3 |
4 | [https://gist.github.com/mcsee/685b6d202e94d8c5b410dafd15d8b5de](https://gist.github.com/mcsee/685b6d202e94d8c5b410dafd15d8b5de)
5 |
6 | [https://gist.github.com/mcsee/a8a2b41722dde835757f360a5d1f01d2](https://gist.github.com/mcsee/a8a2b41722dde835757f360a5d1f01d2)
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.03 Changing State as Properties/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 10 Complexity - 10.3 Changing State as Properties
2 |
3 |
4 | [https://gist.github.com/mcsee/817257ca2966c8f2381dcf9887dfa1a4](https://gist.github.com/mcsee/817257ca2966c8f2381dcf9887dfa1a4)
5 |
6 | [https://gist.github.com/mcsee/1b98448f97cd23b6b5f8438280b73736](https://gist.github.com/mcsee/1b98448f97cd23b6b5f8438280b73736)
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.05 Breaking Multiple Promises/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 10 Complexity - 10.5 Breaking Multiple Promises
2 |
3 |
4 | [https://gist.github.com/mcsee/08e94e3b7dbf0fd20cc1d9c296d6fdbc](https://gist.github.com/mcsee/08e94e3b7dbf0fd20cc1d9c296d6fdbc)
5 |
6 | [https://gist.github.com/mcsee/b1f4721f8b8db8da67435c499fcec83d](https://gist.github.com/mcsee/b1f4721f8b8db8da67435c499fcec83d)
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.09 Removing Poltergeist Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 10 Complexity - 10.9 Removing Poltergeist Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/e51b8f319d33c800895b14e463b3b380](https://gist.github.com/mcsee/e51b8f319d33c800895b14e463b3b380)
5 |
6 | [https://gist.github.com/mcsee/0c13213cc8d76d0f1d5041deb94a7946](https://gist.github.com/mcsee/0c13213cc8d76d0f1d5041deb94a7946)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.04 Removing Excessive Parenthesis/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 11 Bloaters - 11.4 Removing Excessive Parenthesis
2 |
3 |
4 | [https://gist.github.com/mcsee/03c6940b1fa140572f29bfe37cf784c1](https://gist.github.com/mcsee/03c6940b1fa140572f29bfe37cf784c1)
5 |
6 | [https://gist.github.com/mcsee/5b468c4d60d25dec61e538d0c1ed1329](https://gist.github.com/mcsee/5b468c4d60d25dec61e538d0c1ed1329)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.06 Breaking Too Many Attributes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 11 Bloaters - 11.6 Breaking Too Many Attributes
2 |
3 |
4 | [https://gist.github.com/mcsee/b6c664aef3247af3bc48d19f3d47d20e](https://gist.github.com/mcsee/b6c664aef3247af3bc48d19f3d47d20e)
5 |
6 | [https://gist.github.com/mcsee/c34dd227f16b52772f8c4cfbb31841e8](https://gist.github.com/mcsee/c34dd227f16b52772f8c4cfbb31841e8)
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.04 Removing Default from Switch/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 13 Fail Fast - 13.4 Removing Default from Switch
2 |
3 |
4 | [https://gist.github.com/mcsee/ddad35dc0be43c82d4aff94ad2b79d09](https://gist.github.com/mcsee/ddad35dc0be43c82d4aff94ad2b79d09)
5 |
6 | [https://gist.github.com/mcsee/78ca0363b28677b5ff24973b2fc4806f](https://gist.github.com/mcsee/78ca0363b28677b5ff24973b2fc4806f)
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.06 Redefining Hash and Equality/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 13 Fail Fast - 13.6 Redefining Hash and Equality
2 |
3 |
4 | [https://gist.github.com/mcsee/b97afa5814c25e6d9c53e35f3fc5f09e](https://gist.github.com/mcsee/b97afa5814c25e6d9c53e35f3fc5f09e)
5 |
6 | [https://gist.github.com/mcsee/4a40df553e8d08860b23f35fb4400c0e](https://gist.github.com/mcsee/4a40df553e8d08860b23f35fb4400c0e)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.02 Renaming Flag Variables for Events/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.2 Renaming Flag Variables for Events
2 |
3 |
4 | [https://gist.github.com/mcsee/694068de9cd2bbb8592d1a14bd89fe9e](https://gist.github.com/mcsee/694068de9cd2bbb8592d1a14bd89fe9e)
5 |
6 | [https://gist.github.com/mcsee/8a0de13a6fb13ae4da9c51a1b91c9705](https://gist.github.com/mcsee/8a0de13a6fb13ae4da9c51a1b91c9705)
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.04 Reducing Overgeneralization/duplication.rs:
--------------------------------------------------------------------------------
1 | fn validate_size(value: i32) {
2 | validate_type(value, Type::Integer);
3 | validate_min_integer(value, 0);
4 | }
5 |
6 | fn validate_years(value: i32) {
7 | validate_type(value, Type::Integer);
8 | validate_min_integer(value, 0);
9 | }
10 |
11 | // Duplication is accidental, therefore you should not abstract it
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.14 Changing Coupling to Classes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.14 Changing Coupling to Classes
2 |
3 |
4 | [https://gist.github.com/mcsee/e805e3d4540de21d6c1c3ff0341aac5a](https://gist.github.com/mcsee/e805e3d4540de21d6c1c3ff0341aac5a)
5 |
6 | [https://gist.github.com/mcsee/0358951abbf771f2b63a3ae6833ea210](https://gist.github.com/mcsee/0358951abbf771f2b63a3ae6833ea210)
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.05 Changing Global Date Creations/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 18 Globals - 18.5 Changing Global Date Creations
2 |
3 |
4 | [https://gist.github.com/mcsee/272ba8ead8cb11037d97f6a0cd473ef2](https://gist.github.com/mcsee/272ba8ead8cb11037d97f6a0cd473ef2)
5 |
6 | [https://gist.github.com/mcsee/51f09b9c56f077aa2954745c1f43da2c](https://gist.github.com/mcsee/51f09b9c56f077aa2954745c1f43da2c)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.01 Breaking Deep Inheritances/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.1 Breaking Deep Inheritances
2 |
3 |
4 | [https://gist.github.com/mcsee/ca80ab1c2443f8494817c027678ab7f3](https://gist.github.com/mcsee/ca80ab1c2443f8494817c027678ab7f3)
5 |
6 | [https://gist.github.com/mcsee/23622a20da88b3192eb97577557a1f08](https://gist.github.com/mcsee/23622a20da88b3192eb97577557a1f08)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.02 Breaking Yo-Yo Hierarchies/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.2 Breaking Yo-Yo Hierarchies
2 |
3 |
4 | [https://gist.github.com/mcsee/85826dec4db583e6301c9c45a625a246](https://gist.github.com/mcsee/85826dec4db583e6301c9c45a625a246)
5 |
6 | [https://gist.github.com/mcsee/d50419e3b895ee4d4341ca3c31faa091](https://gist.github.com/mcsee/d50419e3b895ee4d4341ca3c31faa091)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.06 Renaming Isolated Classes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.6 Renaming Isolated Classes
2 |
3 |
4 | [https://gist.github.com/mcsee/78ec88e709cd2a5efc4a0a09903c5a4e](https://gist.github.com/mcsee/78ec88e709cd2a5efc4a0a09903c5a4e)
5 |
6 | [https://gist.github.com/mcsee/f46bfc303a23c3e6c2d31d7bb4168f28](https://gist.github.com/mcsee/f46bfc303a23c3e6c2d31d7bb4168f28)
--------------------------------------------------------------------------------
/Code/Chapter 21 Technical Debt/21.02 Removing Defect Trackers/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 21 Technical Debt - 21.2 Removing Defect Trackers
2 |
3 |
4 | [https://gist.github.com/mcsee/352ade4d98a059ed49e4312ae3bab44e](https://gist.github.com/mcsee/352ade4d98a059ed49e4312ae3bab44e)
5 |
6 | [https://gist.github.com/mcsee/d1323654df40648970e8058c0cbd55cc](https://gist.github.com/mcsee/d1323654df40648970e8058c0cbd55cc)
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.04 Rewriting Nested TryCatches/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 22 Exceptions - 22.4 Rewriting Nested Try/Catches
2 |
3 |
4 | [https://gist.github.com/mcsee/f180d0e09abe6dc0f637a142c4a5a58b](https://gist.github.com/mcsee/f180d0e09abe6dc0f637a142c4a5a58b)
5 |
6 | [https://gist.github.com/mcsee/a4fc40e63f2506bf02144c9f71f164a3](https://gist.github.com/mcsee/a4fc40e63f2506bf02144c9f71f164a3)
--------------------------------------------------------------------------------
/Code/Chapter 23 Meta Programming/23.03 Removing Preprocessors/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 23 Meta Programming - 23.3 Removing Preprocessors
2 |
3 |
4 | [https://gist.github.com/mcsee/b9945cd67cc06de97cffe8edb114862c](https://gist.github.com/mcsee/b9945cd67cc06de97cffe8edb114862c)
5 |
6 | [https://gist.github.com/mcsee/717c0b451c159315180c56fb0849419c](https://gist.github.com/mcsee/717c0b451c159315180c56fb0849419c)
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.03 Removing Packages Dependencies/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 25 Security - 25.3 Removing Packages Dependencies
2 |
3 |
4 | [https://gist.github.com/mcsee/32a73793d00fc672138e1a98bbdc9aa8](https://gist.github.com/mcsee/32a73793d00fc672138e1a98bbdc9aa8)
5 |
6 | [https://gist.github.com/mcsee/751b57a8178500e9143ea2081237ffaf](https://gist.github.com/mcsee/751b57a8178500e9143ea2081237ffaf)
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.04 Replacing Evil Regular Expressions/evilregex.go:
--------------------------------------------------------------------------------
1 | func main() {
2 | var regularExpression =
3 | regexp.MustCompile(`^(([a-z])+.)+[A-Z]([a-z])+$`)
4 | var candidateString = "aaaaaaaaaaaaaaaaaaaaaaaa!"
5 | for index, match :=
6 | range regularExpression.FindAllString(candidateString, -1) {
7 | fmt.Println(match, "found at index", index)
8 | }
9 | }
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.05 Removing Automatic Properties/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 3 Anemic Models - 3.5 Removing Automatic Properties
2 |
3 |
4 | [https://gist.github.com/mcsee/2353f11cfb336aaeda194c4a11a21324](https://gist.github.com/mcsee/2353f11cfb336aaeda194c4a11a21324)
5 |
6 | [https://gist.github.com/mcsee/198d8a232bd1abf52cda0884fb96bc5f](https://gist.github.com/mcsee/198d8a232bd1abf52cda0884fb96bc5f)
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.07 Completing Empty Constructors/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 3 Anemic Models - 3.7 Completing Empty Constructors
2 |
3 |
4 | [https://gist.github.com/mcsee/d42be6d1931e7f4f80781b1360e86a0f](https://gist.github.com/mcsee/d42be6d1931e7f4f80781b1360e86a0f)
5 |
6 | [https://gist.github.com/mcsee/af9b6b0a60b76d984cd43b2c26720040](https://gist.github.com/mcsee/af9b6b0a60b76d984cd43b2c26720040)
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.10 Removing Dynamic Properties/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 3 Anemic Models - 3.10 Removing Dynamic Properties
2 |
3 |
4 | [https://gist.github.com/mcsee/1fceddaa27b7dcbb2cf0ba4f85861237](https://gist.github.com/mcsee/1fceddaa27b7dcbb2cf0ba4f85861237)
5 |
6 | [https://gist.github.com/mcsee/b2f04e4bafd415006b4ace96e4456612](https://gist.github.com/mcsee/b2f04e4bafd415006b4ace96e4456612)
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.01 Creating Small Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 4 Primitive Obsession - 4.1 Creating Small Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/9a4cce1354fa6b13bdf90b19e453fbb8](https://gist.github.com/mcsee/9a4cce1354fa6b13bdf90b19e453fbb8)
5 |
6 | [https://gist.github.com/mcsee/79e4e83a5f5f2a17f310a4ae743221b4](https://gist.github.com/mcsee/79e4e83a5f5f2a17f310a4ae743221b4)
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.02 Reifying Primitive Data/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 4 Primitive Obsession - 4.2 Reifying Primitive Data
2 |
3 |
4 | [https://gist.github.com/mcsee/12dc64f150fb047541b9aaa795d85faf](https://gist.github.com/mcsee/12dc64f150fb047541b9aaa795d85faf)
5 |
6 | [https://gist.github.com/mcsee/32202947a8d5ef760936a1e094d3f6b3](https://gist.github.com/mcsee/32202947a8d5ef760936a1e094d3f6b3)
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.04 Removing String Abuses/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 4 Primitive Obsession - 4.4 Removing String Abuses
2 |
3 |
4 | [https://gist.github.com/mcsee/19b5965879d11e6c185d4591add24042](https://gist.github.com/mcsee/19b5965879d11e6c185d4591add24042)
5 |
6 | [https://gist.github.com/mcsee/9aea4a3d401b7e3c2e80101ff348dfa6](https://gist.github.com/mcsee/9aea4a3d401b7e3c2e80101ff348dfa6)
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.09 Creating Date Intervals/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 4 Primitive Obsession - 4.9 Creating Date Intervals
2 |
3 |
4 | [https://gist.github.com/mcsee/1e7dafa0143427c7e381017d77da987e](https://gist.github.com/mcsee/1e7dafa0143427c7e381017d77da987e)
5 |
6 | [https://gist.github.com/mcsee/cff12c234110259b3b39b6a0122e1b76](https://gist.github.com/mcsee/cff12c234110259b3b39b6a0122e1b76)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.01 Narrowing Reused Variables/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.1 Narrowing Reused Variables
2 |
3 |
4 | [https://gist.github.com/mcsee/88615884493c78d45a57be565964ae5b](https://gist.github.com/mcsee/88615884493c78d45a57be565964ae5b)
5 |
6 | [https://gist.github.com/mcsee/9657946be3bcd5a81aebc12d4ef82d0b](https://gist.github.com/mcsee/9657946be3bcd5a81aebc12d4ef82d0b)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.03 Removing Versioned Methods/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.3 Removing Versioned Methods
2 |
3 |
4 | [https://gist.github.com/mcsee/3b63bc3a76faf6e98c3770171f8e1c10](https://gist.github.com/mcsee/3b63bc3a76faf6e98c3770171f8e1c10)
5 |
6 | [https://gist.github.com/mcsee/1e3df98869010c8b9f37f1a76ff80c8b](https://gist.github.com/mcsee/1e3df98869010c8b9f37f1a76ff80c8b)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.04 Removing Double Negatives/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.4 Removing Double Negatives
2 |
3 |
4 | [https://gist.github.com/mcsee/f5c32dfa2aefa4f7fcb180ea28995508](https://gist.github.com/mcsee/f5c32dfa2aefa4f7fcb180ea28995508)
5 |
6 | [https://gist.github.com/mcsee/842684ebe8f5496d1d6374436a0c9473](https://gist.github.com/mcsee/842684ebe8f5496d1d6374436a0c9473)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.11 Rewriting Yoda Conditions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.11 Rewriting Yoda Conditions
2 |
3 |
4 | [https://gist.github.com/mcsee/530570169b351c8d411c310d9a182d1a](https://gist.github.com/mcsee/530570169b351c8d411c310d9a182d1a)
5 |
6 | [https://gist.github.com/mcsee/3a59fd09423eef0bbc5ab7857d041309](https://gist.github.com/mcsee/3a59fd09423eef0bbc5ab7857d041309)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.12 Removing Comedian Methods/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.12 Removing Comedian Methods
2 |
3 |
4 | [https://gist.github.com/mcsee/fe5ba2b148a1b9b5f11cd7022b059fe6](https://gist.github.com/mcsee/fe5ba2b148a1b9b5f11cd7022b059fe6)
5 |
6 | [https://gist.github.com/mcsee/19ae535002ea19708c13334a1171af37](https://gist.github.com/mcsee/19ae535002ea19708c13334a1171af37)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.05 Renaming Variables Named After Types/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.5 Renaming Variables Named After Types
2 |
3 |
4 | [https://gist.github.com/mcsee/00c30c369fe7339e28d50f858392cf4c](https://gist.github.com/mcsee/00c30c369fe7339e28d50f858392cf4c)
5 |
6 | [https://gist.github.com/mcsee/91e3a3f2b1351fa0e09fb8c56a5c2779](https://gist.github.com/mcsee/91e3a3f2b1351fa0e09fb8c56a5c2779)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.09 Removing Class Name from Attributes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.9 Removing Class Name from Attributes
2 |
3 |
4 | [https://gist.github.com/mcsee/a826cc57021603442286f8c40d6981a2](https://gist.github.com/mcsee/a826cc57021603442286f8c40d6981a2)
5 |
6 | [https://gist.github.com/mcsee/60f3381be1d06def7f68419ec2776b3a](https://gist.github.com/mcsee/60f3381be1d06def7f68419ec2776b3a)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.16 Removing Redundant Parameter Names/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.16 Removing Redundant Parameter Names
2 |
3 |
4 | [https://gist.github.com/mcsee/846ae86d9b75ccb1ccbabe75c4306800](https://gist.github.com/mcsee/846ae86d9b75ccb1ccbabe75c4306800)
5 |
6 | [https://gist.github.com/mcsee/5f4a6933b3d176e061d795119d5bc11c](https://gist.github.com/mcsee/5f4a6933b3d176e061d795119d5bc11c)
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.06 Removing Comments Inside Methods/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 8 Comments - 8.6 Removing Comments Inside Methods
2 |
3 |
4 | [https://gist.github.com/mcsee/eae0f716ae595002445926a33fb4d7e8](https://gist.github.com/mcsee/eae0f716ae595002445926a33fb4d7e8)
5 |
6 | [https://gist.github.com/mcsee/06f878717d284007d42c0140ccd0cb8e](https://gist.github.com/mcsee/06f878717d284007d42c0140ccd0cb8e)
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.04 Removing Cleverness from Code/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 10 Complexity - 10.4 Removing Cleverness from Code
2 |
3 |
4 | [https://gist.github.com/mcsee/df27505a28b5f65faaa273b0bfe1f322](https://gist.github.com/mcsee/df27505a28b5f65faaa273b0bfe1f322)
5 |
6 | [https://gist.github.com/mcsee/4749cfe51de1c02848df1aa802fa5705](https://gist.github.com/mcsee/4749cfe51de1c02848df1aa802fa5705)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.05 Replacing Hardcoded If Conditions with Collections/hardcoded.cs:
--------------------------------------------------------------------------------
1 | private string FindCountryName (string internetCode)
2 | {
3 | if (internetCode == "de")
4 | return "Germany";
5 | else if(internetCode == "fr")
6 | return "France";
7 | else if(internetCode == "ar")
8 | return "Argentina";
9 | // lots of else clauses
10 | else
11 | return "Suffix not Valid";
12 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.12 Changing Comparison Against Booleans/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.12 Changing Comparison Against Booleans
2 |
3 |
4 | [https://gist.github.com/mcsee/118ff2e5ebd9779675f664ed46bae95d](https://gist.github.com/mcsee/118ff2e5ebd9779675f664ed46bae95d)
5 |
6 | [https://gist.github.com/mcsee/405d45ed06a94a81d1f1a3b06381c0f9](https://gist.github.com/mcsee/405d45ed06a94a81d1f1a3b06381c0f9)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.16 Breaking Inappropriate Intimacy/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.16 Breaking Inappropriate Intimacy
2 |
3 |
4 | [https://gist.github.com/mcsee/5f9206a8a131b4dcaaa2fd64562c9eca](https://gist.github.com/mcsee/5f9206a8a131b4dcaaa2fd64562c9eca)
5 |
6 | [https://gist.github.com/mcsee/f94d51d327592ca511b625bac37cb441](https://gist.github.com/mcsee/f94d51d327592ca511b625bac37cb441)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.07 Making Concrete Classes Final/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.7 Making Concrete Classes Final
2 |
3 |
4 | [https://gist.github.com/mcsee/9780cd7772afddbc8356bab8aa5eabed](https://gist.github.com/mcsee/9780cd7772afddbc8356bab8aa5eabed)
5 |
6 | [https://gist.github.com/mcsee/3edd25966d27541140a3e4672f5e9b3c](https://gist.github.com/mcsee/3edd25966d27541140a3e4672f5e9b3c)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.11 Removing Protected Attributes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.11 Removing Protected Attributes
2 |
3 |
4 | [https://gist.github.com/mcsee/b599977d400cf92eda495f5f5011fb97](https://gist.github.com/mcsee/b599977d400cf92eda495f5f5011fb97)
5 |
6 | [https://gist.github.com/mcsee/def8678faff1e1952e7ad43b70f1b6da](https://gist.github.com/mcsee/def8678faff1e1952e7ad43b70f1b6da)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.02 Adding Descriptions to Assertions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.2 Adding Descriptions to Assertions
2 |
3 |
4 | [https://gist.github.com/mcsee/4edc85bb65bc9a70d11706086e0fab99](https://gist.github.com/mcsee/4edc85bb65bc9a70d11706086e0fab99)
5 |
6 | [https://gist.github.com/mcsee/72a551eb26d02f1480142e9cd41a5ca7](https://gist.github.com/mcsee/72a551eb26d02f1480142e9cd41a5ca7)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.04 Replacing Mocks with Real Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.4 Replacing Mocks with Real Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/191cee3a71132501564cdb58abef27a7](https://gist.github.com/mcsee/191cee3a71132501564cdb58abef27a7)
5 |
6 | [https://gist.github.com/mcsee/1a84f6cf33594a0b63f5171a13513439](https://gist.github.com/mcsee/1a84f6cf33594a0b63f5171a13513439)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.07 Changing Float Number Assertions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.7 Changing Float Number Assertions
2 |
3 |
4 | [https://gist.github.com/mcsee/2fc79af85305eaada328fd324cb38c0d](https://gist.github.com/mcsee/2fc79af85305eaada328fd324cb38c0d)
5 |
6 | [https://gist.github.com/mcsee/570958fcfb8e52379b7ddde2389ad6f8](https://gist.github.com/mcsee/570958fcfb8e52379b7ddde2389ad6f8)
--------------------------------------------------------------------------------
/Code/Chapter 21 Technical Debt/21.03 Removing WarningStrict Off/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 21 Technical Debt - 21.3 Removing Warning/Strict Off
2 |
3 |
4 | [https://gist.github.com/mcsee/d4f19089543214fbc677a846967cb501](https://gist.github.com/mcsee/d4f19089543214fbc677a846967cb501)
5 |
6 | [https://gist.github.com/mcsee/4523879f8fd11134654d4683b5c68ceb](https://gist.github.com/mcsee/4523879f8fd11134654d4683b5c68ceb)
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.06 Rewriting Exception Arrow Code/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 22 Exceptions - 22.6 Rewriting Exception Arrow Code
2 |
3 |
4 | [https://gist.github.com/mcsee/18a248332d86061c9cccdf5195a70ca8](https://gist.github.com/mcsee/18a248332d86061c9cccdf5195a70ca8)
5 |
6 | [https://gist.github.com/mcsee/7d40861212d1d475a25d740f10c8f34e](https://gist.github.com/mcsee/7d40861212d1d475a25d740f10c8f34e)
--------------------------------------------------------------------------------
/Code/Chapter 23 Meta Programming/23.04 Removing Dynamic Methods/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 23 Meta Programming - 23.4 Removing Dynamic Methods
2 |
3 |
4 | [https://gist.github.com/mcsee/38b69082f08a26158420fbfb1856e8c2](https://gist.github.com/mcsee/38b69082f08a26158420fbfb1856e8c2)
5 |
6 | [https://gist.github.com/mcsee/7249e35ba5c33c91aa93388647d9f345](https://gist.github.com/mcsee/7249e35ba5c33c91aa93388647d9f345)
--------------------------------------------------------------------------------
/Code/Chapter 24 Types/24.03 Changing Float Numbers to Decimals/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 24 Types - 24.3 Changing Float Numbers to Decimals
2 |
3 |
4 | [https://gist.github.com/mcsee/46a81f9ff84ac7c32b2f482e0625efce](https://gist.github.com/mcsee/46a81f9ff84ac7c32b2f482e0625efce)
5 |
6 | [https://gist.github.com/mcsee/f57afd489e3f65c44e4e92fc1ff74fb8](https://gist.github.com/mcsee/f57afd489e3f65c44e4e92fc1ff74fb8)
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.04 Removing Anemic Code Generators/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 3 Anemic Models - 3.4 Removing Anemic Code Generators
2 |
3 |
4 | [https://gist.github.com/mcsee/f930ccb9f2a14798aea9c6b96977b391](https://gist.github.com/mcsee/f930ccb9f2a14798aea9c6b96977b391)
5 |
6 | [https://gist.github.com/mcsee/366d7d78b0952ac088125f75c2bc4035](https://gist.github.com/mcsee/366d7d78b0952ac088125f75c2bc4035)
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.06 Creating Objects Subsets/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 4 Primitive Obsession - 4.6 Creating Objects Subsets
2 |
3 |
4 | [https://gist.github.com/mcsee/6fedc83479a0894ca2467247ecd5e85c](https://gist.github.com/mcsee/6fedc83479a0894ca2467247ecd5e85c)
5 |
6 | [https://gist.github.com/mcsee/51ea6966c13b5aa25c34437218eef5b8](https://gist.github.com/mcsee/51ea6966c13b5aa25c34437218eef5b8)
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.02 Declaring Variables to Be Variable/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 5 Mutability - 5.2 Declaring Variables to Be Variable
2 |
3 |
4 | [https://gist.github.com/mcsee/ab8aca666d5064bac5a4e8d096900138](https://gist.github.com/mcsee/ab8aca666d5064bac5a4e8d096900138)
5 |
6 | [https://gist.github.com/mcsee/9649878302b3d66603b2cfdce2de87ba](https://gist.github.com/mcsee/9649878302b3d66603b2cfdce2de87ba)
--------------------------------------------------------------------------------
/Code/Chapter 05 Mutability/5.03 Forbidding Changes in the Essence/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 5 Mutability - 5.3 Forbidding Changes in the Essence
2 |
3 |
4 | [https://gist.github.com/mcsee/7c1ee7181f403225470c90c2f4668f99](https://gist.github.com/mcsee/7c1ee7181f403225470c90c2f4668f99)
5 |
6 | [https://gist.github.com/mcsee/c758d376a61469d8ce4266b6e9fbe115](https://gist.github.com/mcsee/c758d376a61469d8ce4266b6e9fbe115)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.07 Documenting Design Decisions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.7 Documenting Design Decisions
2 |
3 |
4 | [https://gist.github.com/mcsee/554144e5e61703b8a556328671b0a3dd](https://gist.github.com/mcsee/554144e5e61703b8a556328671b0a3dd)
5 |
6 | [https://gist.github.com/mcsee/ab76cec5efd320d5cf9a2e626343d3e8](https://gist.github.com/mcsee/ab76cec5efd320d5cf9a2e626343d3e8)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.15 Avoiding Magic Corrections/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.15 Avoiding Magic Corrections
2 |
3 |
4 | [https://gist.github.com/mcsee/e86fe7a699dd825c3f238c6073b5e7ea](https://gist.github.com/mcsee/e86fe7a699dd825c3f238c6073b5e7ea)
5 |
6 | [https://gist.github.com/mcsee/4daf2c3a710dfe5b647ec871d1d10ca8](https://gist.github.com/mcsee/4daf2c3a710dfe5b647ec871d1d10ca8)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.12 Converting Plural Classes to Singular/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.12 Converting Plural Classes to Singular
2 |
3 |
4 | [https://gist.github.com/mcsee/5d0c869a94d623684baefce9897563e2](https://gist.github.com/mcsee/5d0c869a94d623684baefce9897563e2)
5 |
6 | [https://gist.github.com/mcsee/34c2fa54fa1629971b55d084541e9ce2](https://gist.github.com/mcsee/34c2fa54fa1629971b55d084541e9ce2)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.15 Renaming Arguments According to Role/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.15 Renaming Arguments According to Role
2 |
3 |
4 | [https://gist.github.com/mcsee/552f2a10d660ee37744f111fe9bf6665](https://gist.github.com/mcsee/552f2a10d660ee37744f111fe9bf6665)
5 |
6 | [https://gist.github.com/mcsee/bbbc636c7c309c86b4f1114b1f57f6b8](https://gist.github.com/mcsee/bbbc636c7c309c86b4f1114b1f57f6b8)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.17 Removing Gratitous Context from Names/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.17 Removing Gratitous Context from Names
2 |
3 |
4 | [https://gist.github.com/mcsee/0e69debe5bcce802a00b09be29a1a668](https://gist.github.com/mcsee/0e69debe5bcce802a00b09be29a1a668)
5 |
6 | [https://gist.github.com/mcsee/111aa1f4c0d67b3230f6166aadecd9d6](https://gist.github.com/mcsee/111aa1f4c0d67b3230f6166aadecd9d6)
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.07 Extracting a Method to an Object/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 10 Complexity - 10.7 Extracting a Method to an Object
2 |
3 |
4 | [https://gist.github.com/mcsee/c8984513652806d25e26f5c184849af0](https://gist.github.com/mcsee/c8984513652806d25e26f5c184849af0)
5 |
6 | [https://gist.github.com/mcsee/77d24738ede67a5a99d28e796ce1fade](https://gist.github.com/mcsee/77d24738ede67a5a99d28e796ce1fade)
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.08 Looking After Array Constructors/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 10 Complexity - 10.8 Looking After Array Constructors
2 |
3 |
4 | [https://gist.github.com/mcsee/5d0644c120630d637c9649d7c92805c7](https://gist.github.com/mcsee/5d0644c120630d637c9649d7c92805c7)
5 |
6 | [https://gist.github.com/mcsee/a7f4c59210257cb279efc6747b4e3122](https://gist.github.com/mcsee/a7f4c59210257cb279efc6747b4e3122)
--------------------------------------------------------------------------------
/Code/Chapter 11 Bloaters/11.01 Breaking Too Long Methods/longMethod.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | function setUpChessBoard() {
4 | $this->placeOnBoard($this->whiteTower);
5 | $this->placeOnBoard($this->whiteKnight);
6 | // A lot more lines
7 |
8 | // Empty space to pause definition
9 | $this->placeOnBoard($this->blackTower);
10 | $this->placeOnBoard($this->blackKnight);
11 | // A lot more lines
12 | }
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.03 Refactoring Classes with One Subclass/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 12 YAGNI - 12.3 Refactoring Classes with One Subclass
2 |
3 |
4 | [https://gist.github.com/mcsee/ce3cbe785c4b1d542a2b0660acabbc8f](https://gist.github.com/mcsee/ce3cbe785c4b1d542a2b0660acabbc8f)
5 |
6 | [https://gist.github.com/mcsee/441d6bf98d916336dbfa2670d7109640](https://gist.github.com/mcsee/441d6bf98d916336dbfa2670d7109640)
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.03 Refactoring Classes with One Subclass/boss.py:
--------------------------------------------------------------------------------
1 | class Boss(object):
2 | def __init__(self, name):
3 | self.name = name
4 |
5 | class GoodBoss(Boss):
6 | def __init__(self, name):
7 | super().__init__(name)
8 |
9 | # This is actually a poor classification example
10 | # Bosses should be immutable but can change their mood
11 | # with constructive feedback
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.04 Replacing SwitchCaseElseif Statements/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.4 Replacing Switch/Case/Elseif Statements
2 |
3 |
4 | [https://gist.github.com/mcsee/fd1c07ce153817a5572cb3cb84ae1007](https://gist.github.com/mcsee/fd1c07ce153817a5572cb3cb84ae1007)
5 |
6 | [https://gist.github.com/mcsee/ef02daf9882bbf6a6f12820b31e19920](https://gist.github.com/mcsee/ef02daf9882bbf6a6f12820b31e19920)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.16 Reifying Hardcoded Business Conditions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.16 Reifying Hardcoded Business Conditions
2 |
3 |
4 | [https://gist.github.com/mcsee/27cdd48bf20694b735f7d5914c086022](https://gist.github.com/mcsee/27cdd48bf20694b735f7d5914c086022)
5 |
6 | [https://gist.github.com/mcsee/d43ab068cbec6d361fb429fd2860f518](https://gist.github.com/mcsee/d43ab068cbec6d361fb429fd2860f518)
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.06 Removing Anchor Boats/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 16 Premature Optimization - 16.6 Removing Anchor Boats
2 |
3 |
4 | [https://gist.github.com/mcsee/22deb44d4e95b4a3ca8ce9ba18d0f908](https://gist.github.com/mcsee/22deb44d4e95b4a3ca8ce9ba18d0f908)
5 |
6 | [https://gist.github.com/mcsee/7d520c7f266d0180f42c3fc12b41fddc](https://gist.github.com/mcsee/7d520c7f266d0180f42c3fc12b41fddc)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.01 Making Hidden Assumptions Explicit/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.1 Making Hidden Assumptions Explicit
2 |
3 |
4 | [https://gist.github.com/mcsee/33f7a662d4394e6c94c6603f88d9e975](https://gist.github.com/mcsee/33f7a662d4394e6c94c6603f88d9e975)
5 |
6 | [https://gist.github.com/mcsee/a0ee2b3ec2e963149bb2b39a9cfa1a08](https://gist.github.com/mcsee/a0ee2b3ec2e963149bb2b39a9cfa1a08)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.17 Converting Fungible Objects/non fungible.java:
--------------------------------------------------------------------------------
1 | public class Person implements Serializable {
2 | private final String firstName;
3 | private final String lastName;
4 |
5 | public Person(String firstName, String lastName) {
6 | this.firstName = firstName;
7 | this.lastName = lastName;
8 | }
9 | }
10 |
11 | shoppingQueueSystem.queue(new Person('John', 'Doe'));
--------------------------------------------------------------------------------
/Code/Chapter 18 Globals/18.03 Replacing GoTo with Structured Code/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 18 Globals - 18.3 Replacing GoTo with Structured Code
2 |
3 |
4 | [https://gist.github.com/mcsee/5d76fda8dfbe6f351e709baa00e0e61c](https://gist.github.com/mcsee/5d76fda8dfbe6f351e709baa00e0e61c)
5 |
6 | [https://gist.github.com/mcsee/da74b8e901f234b6bc400c9a6e0b7725](https://gist.github.com/mcsee/da74b8e901f234b6bc400c9a6e0b7725)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.08 Changing Test Data to Realistic Data/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.8 Changing Test Data to Realistic Data
2 |
3 |
4 | [https://gist.github.com/mcsee/d9b312e97d7233738ea06f322ae41da1](https://gist.github.com/mcsee/d9b312e97d7233738ea06f322ae41da1)
5 |
6 | [https://gist.github.com/mcsee/539d4699db494d180219620b7baeedea](https://gist.github.com/mcsee/539d4699db494d180219620b7baeedea)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.12 Rewriting Tests Depending on Dates/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.12 Rewriting Tests Depending on Dates
2 |
3 |
4 | [https://gist.github.com/mcsee/7e96669a0239ea203c90423e2e08b22d](https://gist.github.com/mcsee/7e96669a0239ea203c90423e2e08b22d)
5 |
6 | [https://gist.github.com/mcsee/3ccfe6623e9eea63c135afa59c4dbf4f](https://gist.github.com/mcsee/3ccfe6623e9eea63c135afa59c4dbf4f)
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.01 Removing Empty Exception Blocks/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 22 Exceptions - 22.1 Removing Empty Exception Blocks
2 |
3 |
4 | [https://gist.github.com/mcsee/9569c95218a7d8a33d68587fa70e5782](https://gist.github.com/mcsee/9569c95218a7d8a33d68587fa70e5782)
5 |
6 | [https://gist.github.com/mcsee/02d281247e7baac4d5dca91bc77a146a](https://gist.github.com/mcsee/02d281247e7baac4d5dca91bc77a146a)
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.02 Removing Unnecessary Exceptions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 22 Exceptions - 22.2 Removing Unnecessary Exceptions
2 |
3 |
4 | [https://gist.github.com/mcsee/c8fefffd87c98af9bec173266f090497](https://gist.github.com/mcsee/c8fefffd87c98af9bec173266f090497)
5 |
6 | [https://gist.github.com/mcsee/029e21221849e251babf8d933170e62f](https://gist.github.com/mcsee/029e21221849e251babf8d933170e62f)
--------------------------------------------------------------------------------
/Code/Chapter 24 Types/24.01 Removing Type Checking/avoidMeta.js:
--------------------------------------------------------------------------------
1 | class Animal { }
2 |
3 | class Rabbit extends Animal {
4 | move() {
5 | console.log("I'm running");
6 | }
7 | }
8 |
9 | class Seagull extends Animal {
10 | move() {
11 | console.log("I'm flying");
12 | }
13 | }
14 |
15 | let bunny = new Rabbit();
16 | let livingstone = new Seagull();
17 |
18 | bunny.move();
19 | livingstone.move();
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.04 Replacing Evil Regular Expressions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 25 Security - 25.4 Replacing Evil Regular Expressions
2 |
3 |
4 | [https://gist.github.com/mcsee/a4e74fb3e18cde7ff7f15636e05ced89](https://gist.github.com/mcsee/a4e74fb3e18cde7ff7f15636e05ced89)
5 |
6 | [https://gist.github.com/mcsee/4ba06d514fb663f0ee628139d463f8c7](https://gist.github.com/mcsee/4ba06d514fb663f0ee628139d463f8c7)
--------------------------------------------------------------------------------
/Code/Chapter 25 Security/25.05 Protecting Object Deserialization/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 25 Security - 25.5 Protecting Object Deserialization
2 |
3 |
4 | [https://gist.github.com/mcsee/4b1c59db5f77bc9d29db5115c6516b46](https://gist.github.com/mcsee/4b1c59db5f77bc9d29db5115c6516b46)
5 |
6 | [https://gist.github.com/mcsee/d6f86ea9959eb68e0604f6249afa8709](https://gist.github.com/mcsee/d6f86ea9959eb68e0604f6249afa8709)
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.07 Reifying String Validations/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 4 Primitive Obsession - 4.7 Reifying String Validations
2 |
3 |
4 | [https://gist.github.com/mcsee/1b6799dac071ce8bd2a1082dfdbd668d](https://gist.github.com/mcsee/1b6799dac071ce8bd2a1082dfdbd668d)
5 |
6 | [https://gist.github.com/mcsee/d2eace32ecb9f7564ebeaf8136118f53](https://gist.github.com/mcsee/d2eace32ecb9f7564ebeaf8136118f53)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.06 Replacing Explicit Iterations/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.6 Replacing Explicit Iterations
2 |
3 |
4 | [https://gist.github.com/mcsee/9277f66f0a09b0e01ab217a65f80fe61](https://gist.github.com/mcsee/9277f66f0a09b0e01ab217a65f80fe61)
5 |
6 | [https://gist.github.com/mcsee/c5640773e3691e2aa6ac6db27b5596bf](https://gist.github.com/mcsee/c5640773e3691e2aa6ac6db27b5596bf)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.14 Generating Good Error Messages/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.14 Generating Good Error Messages
2 |
3 |
4 | [https://gist.github.com/mcsee/e35210910d75821224dd75de8053b46f](https://gist.github.com/mcsee/e35210910d75821224dd75de8053b46f)
5 |
6 | [https://gist.github.com/mcsee/220e4c4d8eea96d15a0f34de2c5e96e3](https://gist.github.com/mcsee/220e4c4d8eea96d15a0f34de2c5e96e3)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.14 Removing Impl PrefixSuffix from Class Names/addressImpl.java:
--------------------------------------------------------------------------------
1 | public interface Address extends ChangeAware, Serializable {
2 | String getStreet();
3 | }
4 |
5 | // Wrong Name - There is no concept 'AddressImpl' in the real world
6 | public class AddressImpl implements Address {
7 | private String street;
8 | private String houseNumber;
9 | private City city;
10 | // ..
11 | }
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.05 Converting Comments to Function Names/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 8 Comments - 8.5 Converting Comments to Function Names
2 |
3 |
4 | [https://gist.github.com/mcsee/4fb1f04c950ece88450fec59ed6a827b](https://gist.github.com/mcsee/4fb1f04c950ece88450fec59ed6a827b)
5 |
6 | [https://gist.github.com/mcsee/698102c04428aec69356cad26d4c50cd](https://gist.github.com/mcsee/698102c04428aec69356cad26d4c50cd)
--------------------------------------------------------------------------------
/Code/Chapter 12 YAGNI/12.04 Removing One-Use Interfaces/vehicle.java:
--------------------------------------------------------------------------------
1 | public interface Vehicle {
2 | public void start();
3 | public void stop();
4 | }
5 |
6 | public class Car implements Vehicle {
7 | public void start() {
8 | System.out.println("Running...");
9 | }
10 | public void stop() {
11 | System.out.println("Stopping...");
12 | }
13 | }
14 |
15 | // No more concrete vehicles??
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.05 Avoiding Modifying Collections While Traversing/removeOriginal.java:
--------------------------------------------------------------------------------
1 | // here you add elements to the collection...
2 | Collection people = new ArrayList<>();
3 |
4 | for (Object person : people) {
5 | if (condition(person)) {
6 | people.remove(person);
7 | }
8 | }
9 | // You iterate AND remove elements, elements,
10 | // risking skipping other candidates for removal
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.09 Avoiding Short Circuit Hacks/masked IF.js:
--------------------------------------------------------------------------------
1 | userIsValid() && logUserIn();
2 |
3 | // this expression is short circuit
4 | // Does not value second statement
5 | // Unless the first one is true
6 |
7 | functionDefinedOrNot && functionDefinedOrNot();
8 |
9 | // in some languages undefined works as a false
10 | // If functionDefinedOrNot is not defined does
11 | // not raise an error and neither runs
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.01 Avoiding IDs on Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 16 Premature Optimization - 16.1 Avoiding IDs on Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/388923d775ca893eb1e6ca4c28c3287f](https://gist.github.com/mcsee/388923d775ca893eb1e6ca4c28c3287f)
5 |
6 | [https://gist.github.com/mcsee/9a0f4f02514f740f3872cbc463d25c8b](https://gist.github.com/mcsee/9a0f4f02514f740f3872cbc463d25c8b)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.10 Moving Default Arguments to the End/dafaults.py:
--------------------------------------------------------------------------------
1 | def functionWithLastOptional(a, b, c='foo'):
2 | print(a)
3 | print(b)
4 | print(c)
5 | functionWithLastOptional(1, 2)
6 |
7 | def functionWithMiddleOptional(a, b='foo', c):
8 | print(a)
9 | print(b)
10 | print(c)
11 | functionWithMiddleOptional(1, 2)
12 |
13 | # SyntaxError: non-default argument follows default argument
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.11 Avoiding Ripple Effect/ripple.js:
--------------------------------------------------------------------------------
1 | class Time {
2 | constructor(hour, minute, seconds) {
3 | this.hour = hour;
4 | this.minute = minute;
5 | this.seconds = seconds;
6 | }
7 | now() {
8 | // call operating system
9 | }
10 | }
11 |
12 | // Adding a TimeZone will have a big Ripple Effect
13 | // Changing now() to consider timezone will also bring the effect
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.10 Delaying Premature Classification/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.10 Delaying Premature Classification
2 |
3 |
4 | [https://gist.github.com/mcsee/e6ca123df9f10f291a92e863bf168cc0](https://gist.github.com/mcsee/e6ca123df9f10f291a92e863bf168cc0)
5 |
6 | [https://gist.github.com/mcsee/d3232090ebc0c1360c85dd1079aebe14](https://gist.github.com/mcsee/d3232090ebc0c1360c85dd1079aebe14)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.12 Completing Empty Implementations/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.12 Completing Empty Implementations
2 |
3 |
4 | [https://gist.github.com/mcsee/56e55a0fdee9d223fc050652b298f699](https://gist.github.com/mcsee/56e55a0fdee9d223fc050652b298f699)
5 |
6 | [https://gist.github.com/mcsee/77dcf4848f489f7011aefbe4971d4b0a](https://gist.github.com/mcsee/77dcf4848f489f7011aefbe4971d4b0a)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.10 Removing Irrelevant Test Information/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.10 Removing Irrelevant Test Information
2 |
3 |
4 | [https://gist.github.com/mcsee/913c97719a02e75721ea53d8e4e674c7](https://gist.github.com/mcsee/913c97719a02e75721ea53d8e4e674c7)
5 |
6 | [https://gist.github.com/mcsee/ce5da0101b5e9eb72af22c12d6338f6a](https://gist.github.com/mcsee/ce5da0101b5e9eb72af22c12d6338f6a)
--------------------------------------------------------------------------------
/Code/Chapter 23 Meta Programming/23.02 Reifying Anonymous Functions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 23 Meta Programming - 23.2 Reifying Anonymous Functions
2 |
3 |
4 | [https://gist.github.com/mcsee/ee95a7e72f3c758d6544eab054ce2697](https://gist.github.com/mcsee/ee95a7e72f3c758d6544eab054ce2697)
5 |
6 | [https://gist.github.com/mcsee/f3000f6792099ea70c649698203554b8](https://gist.github.com/mcsee/f3000f6792099ea70c649698203554b8)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.10 Documenting Regular Expressions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.10 Documenting Regular Expressions
2 |
3 |
4 | [https://gist.github.com/mcsee/d0e8d1c002a12a9f535ab2fef4440d31](https://gist.github.com/mcsee/d0e8d1c002a12a9f535ab2fef4440d31)
5 |
6 | [https://gist.github.com/mcsee/f3df119d3be0cdfee7fddd6d725f92be](https://gist.github.com/mcsee/f3df119d3be0cdfee7fddd6d725f92be)
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.06 Breaking Long Chains of Collaborations/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 10 Complexity - 10.6 Breaking Long Chains of Collaborations
2 |
3 |
4 | [https://gist.github.com/mcsee/de702945b0bb7cd80f696f8cbe19c91c](https://gist.github.com/mcsee/de702945b0bb7cd80f696f8cbe19c91c)
5 |
6 | [https://gist.github.com/mcsee/b3b7d73ffb6554df2c06fce3b93a134f](https://gist.github.com/mcsee/b3b7d73ffb6554df2c06fce3b93a134f)
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.01 Refactoring Reassignment of Variables/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 13 Fail Fast - 13.1 Refactoring Reassignment of Variables
2 |
3 |
4 | [https://gist.github.com/mcsee/f97b6362fcfa4018e75d1d2ce9fc9169](https://gist.github.com/mcsee/f97b6362fcfa4018e75d1d2ce9fc9169)
5 |
6 | [https://gist.github.com/mcsee/d5f970273099100449221f600cd7612f](https://gist.github.com/mcsee/d5f970273099100449221f600cd7612f)
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.02 Enforcing Preconditions/noassertions.py:
--------------------------------------------------------------------------------
1 | class Date:
2 | def __init__(self, day, month, year):
3 | self.day = day
4 | self.month = month
5 | self.year = year
6 |
7 | def setMonth(self, month):
8 | self.month = month
9 |
10 | startDate = Date(3, 11, 2020)
11 | # OK
12 |
13 | startDate = Date(31, 11, 2020)
14 | # Should fail
15 |
16 | startDate.setMonth(13)
17 | # Should fail
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.07 Refactoring Without Functional Changes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 13 Fail Fast - 13.7 Refactoring Without Functional Changes
2 |
3 |
4 | [https://gist.github.com/mcsee/f07e5ef021600a82d086fe7cb001fb84](https://gist.github.com/mcsee/f07e5ef021600a82d086fe7cb001fb84)
5 |
6 | [https://gist.github.com/mcsee/7ae7ad75035ee5c5d1180d0db966dece](https://gist.github.com/mcsee/7ae7ad75035ee5c5d1180d0db966dece)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.06 Changing Boolean to Short Circuit Conditions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.6 Changing Boolean to Short Circuit Conditions
2 |
3 |
4 | [https://gist.github.com/mcsee/57e3cb3fc3c5e8c90a544834022f3ab8](https://gist.github.com/mcsee/57e3cb3fc3c5e8c90a544834022f3ab8)
5 |
6 | [https://gist.github.com/mcsee/c548b8d38d7ddfd3dc98aa799ef975c1](https://gist.github.com/mcsee/c548b8d38d7ddfd3dc98aa799ef975c1)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.08 Defining Class Inheritance Explicitly/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.8 Defining Class Inheritance Explicitly
2 |
3 |
4 | [https://gist.github.com/mcsee/580be250747d29d198fe4bbf9db41c8e](https://gist.github.com/mcsee/580be250747d29d198fe4bbf9db41c8e)
5 |
6 | [https://gist.github.com/mcsee/712df5f99ec232c4e4d2cdaf1bdf62c0](https://gist.github.com/mcsee/712df5f99ec232c4e4d2cdaf1bdf62c0)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.09 Protecting Tests Violating Encapsulation/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.9 Protecting Tests Violating Encapsulation
2 |
3 |
4 | [https://gist.github.com/mcsee/06757fcedc4c442584f144c68b16d597](https://gist.github.com/mcsee/06757fcedc4c442584f144c68b16d597)
5 |
6 | [https://gist.github.com/mcsee/c2d16cf8f0d533345ec74314c04863ea](https://gist.github.com/mcsee/c2d16cf8f0d533345ec74314c04863ea)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.11 Adding Coverage for Every Merge Request/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.11 Adding Coverage for Every Merge Request
2 |
3 |
4 | [https://gist.github.com/mcsee/51317c09b8994b6cb57e09e2059a5d9b](https://gist.github.com/mcsee/51317c09b8994b6cb57e09e2059a5d9b)
5 |
6 | [https://gist.github.com/mcsee/7a5adcac0ead17d037924b6fd47888fb](https://gist.github.com/mcsee/7a5adcac0ead17d037924b6fd47888fb)
--------------------------------------------------------------------------------
/Code/Chapter 21 Technical Debt/21.01 Removing Production Dependent Code/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 21 Technical Debt - 21.1 Removing Production Dependent Code
2 |
3 |
4 | [https://gist.github.com/mcsee/2b00edcf1fded330263a4773b227cd06](https://gist.github.com/mcsee/2b00edcf1fded330263a4773b227cd06)
5 |
6 | [https://gist.github.com/mcsee/4a598f416f01357597a072d75ba30a6f](https://gist.github.com/mcsee/4a598f416f01357597a072d75ba30a6f)
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.04 Rewriting Nested TryCatches/normalFlow.js:
--------------------------------------------------------------------------------
1 | try {
2 | transaction.commit();
3 | } catch (transactionError) {
4 | this.withTransactionErrorDo(
5 | transationError, transaction);
6 | }
7 |
8 | // transaction error policy is not defined in this function
9 | // so you don't have repeated code and code is more readable
10 | // It is up to the transaction and the error to decide what to do
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.05 Replacing Return Codes with Exceptions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 22 Exceptions - 22.5 Replacing Return Codes with Exceptions
2 |
3 |
4 | [https://gist.github.com/mcsee/d7afaa2f18126a7cdb7ecfcbb1124d81](https://gist.github.com/mcsee/d7afaa2f18126a7cdb7ecfcbb1124d81)
5 |
6 | [https://gist.github.com/mcsee/5162daac1e8e7aa5b163ef724944a524](https://gist.github.com/mcsee/5162daac1e8e7aa5b163ef724944a524)
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.07 Hiding Low Level Errors from End Users/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 22 Exceptions - 22.7 Hiding Low Level Errors from End Users
2 |
3 |
4 | [https://gist.github.com/mcsee/8d71bdae68fc52a1b6d1c65e8ce944af](https://gist.github.com/mcsee/8d71bdae68fc52a1b6d1c65e8ce944af)
5 |
6 | [https://gist.github.com/mcsee/3d16a49a680234811e19a56fd3d5be17](https://gist.github.com/mcsee/3d16a49a680234811e19a56fd3d5be17)
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.02 Identifying the Essence of Your Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 3 Anemic Models - 3.2 Identifying the Essence of Your Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/7c1ee7181f403225470c90c2f4668f99](https://gist.github.com/mcsee/7c1ee7181f403225470c90c2f4668f99)
5 |
6 | [https://gist.github.com/mcsee/4dba037ac97bb8cf1e77caed469347a1](https://gist.github.com/mcsee/4dba037ac97bb8cf1e77caed469347a1)
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.08 Removing Unnecessary Properties/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 4 Primitive Obsession - 4.8 Removing Unnecessary Properties
2 |
3 |
4 | [https://gist.github.com/mcsee/f3a9f762f2781017247f5acf6cf281a1](https://gist.github.com/mcsee/f3a9f762f2781017247f5acf6cf281a1)
5 |
6 | [https://gist.github.com/mcsee/53d1777f204e64f5746a9a148ada934a](https://gist.github.com/mcsee/53d1777f204e64f5746a9a148ada934a)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.05 Changing Misplaced Responsibilities/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.5 Changing Misplaced Responsibilities
2 |
3 |
4 | [https://gist.github.com/mcsee/66489fee9b0707d7514d520c515ad102](https://gist.github.com/mcsee/66489fee9b0707d7514d520c515ad102)
5 |
6 | [https://gist.github.com/mcsee/57f86bc7ab8f2e4c67039733ddacb118](https://gist.github.com/mcsee/57f86bc7ab8f2e4c67039733ddacb118)
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.14 Removing Impl PrefixSuffix from Class Names/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.14 Removing Impl Prefix/Suffix from Class Names
2 |
3 |
4 | [https://gist.github.com/mcsee/f1f4d16d6f90c682f540cd2c0c2cc5f2](https://gist.github.com/mcsee/f1f4d16d6f90c682f540cd2c0c2cc5f2)
5 |
6 | [https://gist.github.com/mcsee/6cf15d798176fd83cbe00e207d8351fc](https://gist.github.com/mcsee/6cf15d798176fd83cbe00e207d8351fc)
--------------------------------------------------------------------------------
/Code/Chapter 08 Comments/8.05 Converting Comments to Function Names/commentAbusers.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class ChatBotConnectionHelper {
4 | // ChatBotConnectionHelper is used
5 | // to create connection strings to Bot Platform
6 | // Use this class with getString() function
7 | // to get connection string to platform
8 |
9 | function getString() {
10 | // Get Connection String from Chatbot
11 | }
12 | }
--------------------------------------------------------------------------------
/Code/Chapter 15 Null/15.03 Converting Optional Attributes to a Collection/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 15 Null - 15.3 Converting Optional Attributes to a Collection
2 |
3 |
4 | [https://gist.github.com/mcsee/a6549bd6a333574a2ba7120a74bcb974](https://gist.github.com/mcsee/a6549bd6a333574a2ba7120a74bcb974)
5 |
6 | [https://gist.github.com/mcsee/ec3cca15f071ae1ecebb223675e0cf79](https://gist.github.com/mcsee/ec3cca15f071ae1ecebb223675e0cf79)
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.04 Reducing Overgeneralization/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 16 Premature Optimization - 16.4 Reducing Overgeneralization
2 |
3 |
4 | [https://gist.github.com/mcsee/2b7734f1f6c0ab46a88a71b37464ceeb](https://gist.github.com/mcsee/2b7734f1f6c0ab46a88a71b37464ceeb)
5 |
6 | [https://gist.github.com/mcsee/1eca09d9bb13cea966bcbe2eda95021c](https://gist.github.com/mcsee/1eca09d9bb13cea966bcbe2eda95021c)
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.03 Migrating asserttrue to Specific Assertions/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 20 Testing - 20.3 Migrating asserttrue to Specific Assertions
2 |
3 |
4 | [https://gist.github.com/mcsee/c54f0b1ee42d6a1aff640507e0bdf625](https://gist.github.com/mcsee/c54f0b1ee42d6a1aff640507e0bdf625)
5 |
6 | [https://gist.github.com/mcsee/edf0b1c3339451662bb000055ef5d782](https://gist.github.com/mcsee/edf0b1c3339451662bb000055ef5d782)
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.03 Rewriting Exceptions for Expected Cases/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 22 Exceptions - 22.3 Rewriting Exceptions for Expected Cases
2 |
3 |
4 | [https://gist.github.com/mcsee/14fe90a45804c47d898bab4fe8d17d36](https://gist.github.com/mcsee/14fe90a45804c47d898bab4fe8d17d36)
5 |
6 | [https://gist.github.com/mcsee/49811ad62691011166020c49c1c2ed71](https://gist.github.com/mcsee/49811ad62691011166020c49c1c2ed71)
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.01 Converting Anemic Objects to Rich Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 3 Anemic Models - 3.1 Converting Anemic Objects to Rich Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/73f84d80f7c3e89a216dd9e40ab71bcc](https://gist.github.com/mcsee/73f84d80f7c3e89a216dd9e40ab71bcc)
5 |
6 | [https://gist.github.com/mcsee/78f2dd78120db843c960ed41839f29cb](https://gist.github.com/mcsee/78f2dd78120db843c960ed41839f29cb)
--------------------------------------------------------------------------------
/Code/Chapter 06 Declarative Code/6.08 Replacing Magic Numbers with Constants/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 6 Declarative Code - 6.8 Replacing Magic Numbers with Constants
2 |
3 |
4 | [https://gist.github.com/mcsee/dec9856bf69a06c367d2e683b179577a](https://gist.github.com/mcsee/dec9856bf69a06c367d2e683b179577a)
5 |
6 | [https://gist.github.com/mcsee/2e4c88a516078500ce833dbfbd3d9b0e](https://gist.github.com/mcsee/2e4c88a516078500ce833dbfbd3d9b0e)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.05 Replacing Hardcoded If Conditions with Collections/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.5 Replacing Hardcoded If Conditions with Collections
2 |
3 |
4 | [https://gist.github.com/mcsee/894c442e034658ee3a6d602c1dcfcca4](https://gist.github.com/mcsee/894c442e034658ee3a6d602c1dcfcca4)
5 |
6 | [https://gist.github.com/mcsee/5d45c77d532eb370ca6b78606c0db05e](https://gist.github.com/mcsee/5d45c77d532eb370ca6b78606c0db05e)
--------------------------------------------------------------------------------
/Code/Chapter 15 Null/15.05 Representing Unknown Locations without using Null/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 15 Null - 15.5 Representing Unknown Locations without using Null
2 |
3 |
4 | [https://gist.github.com/mcsee/8103413f0cbda26e2133f977a3180d8a](https://gist.github.com/mcsee/8103413f0cbda26e2133f977a3180d8a)
5 |
6 | [https://gist.github.com/mcsee/dea28242b003409926f2d49cf7ad0849](https://gist.github.com/mcsee/dea28242b003409926f2d49cf7ad0849)
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.02 Removing Premature Optimization/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 16 Premature Optimization - 16.2 Removing Premature Optimization
2 |
3 |
4 | [https://gist.github.com/mcsee/9ac202ec7527f486b6a3ff1895d6ba41](https://gist.github.com/mcsee/9ac202ec7527f486b6a3ff1895d6ba41)
5 |
6 | [https://gist.github.com/mcsee/8f6b87de8228b342caabefab2b05ca42](https://gist.github.com/mcsee/8f6b87de8228b342caabefab2b05ca42)
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.10 Removing Code from Destructors/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 16 Premature Optimization - 16.10 Removing Code from Destructors
2 |
3 |
4 | [https://gist.github.com/mcsee/73df39bf0fcbf9537ed210cf367daac6](https://gist.github.com/mcsee/73df39bf0fcbf9537ed210cf367daac6)
5 |
6 | [https://gist.github.com/mcsee/a0423d39f6b1310dadb049e4188f5fc5](https://gist.github.com/mcsee/a0423d39f6b1310dadb049e4188f5fc5)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.05 Converting 9999 Special Flag Values to Normal/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.5 Converting 9999 Special Flag Values to Normal
2 |
3 |
4 | [https://gist.github.com/mcsee/342599869ca032390b55d4cc76c49548](https://gist.github.com/mcsee/342599869ca032390b55d4cc76c49548)
5 |
6 | [https://gist.github.com/mcsee/40fb4a5238c9d6fbf5ad0f0aefa7fd07](https://gist.github.com/mcsee/40fb4a5238c9d6fbf5ad0f0aefa7fd07)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.03 Breaking Subclassification for Code Reuse/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.3 Breaking Subclassification for Code Reuse
2 |
3 |
4 | [https://gist.github.com/mcsee/4f53d085c8b566936c04483064e25ed9](https://gist.github.com/mcsee/4f53d085c8b566936c04483064e25ed9)
5 |
6 | [https://gist.github.com/mcsee/9f0082db40c2ab590b2b6ea9702bbb22](https://gist.github.com/mcsee/9f0082db40c2ab590b2b6ea9702bbb22)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.14 Converting Nonpolymorphic Functions to Polymorphic/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.14 Converting Nonpolymorphic Functions to Polymorphic
2 |
3 |
4 | [https://gist.github.com/mcsee/17ccba69a9bcb7fbe2e8ee15e0487585](https://gist.github.com/mcsee/17ccba69a9bcb7fbe2e8ee15e0487585)
5 |
6 | [https://gist.github.com/mcsee/ba7cb02ed4cf4c8ae6d0bf4aae3d7cb2](https://gist.github.com/mcsee/ba7cb02ed4cf4c8ae6d0bf4aae3d7cb2)
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.05 Changing Structural Optimizations/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 16 Premature Optimization - 16.5 Changing Structural Optimizations
2 |
3 |
4 | [https://gist.github.com/mcsee/b8d538891f3b1cf508e984399af004b0](https://gist.github.com/mcsee/b8d538891f3b1cf508e984399af004b0)
5 |
6 | [https://gist.github.com/mcsee/b68e67c449b7d0a5b13f69381f02e8e4](https://gist.github.com/mcsee/b68e67c449b7d0a5b13f69381f02e8e4)
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.05 Changing Structural Optimizations/forloop.js:
--------------------------------------------------------------------------------
1 | for (outerIterator = 0; outerIterator< 3; outerIterator++) {
2 | for (innerIterator = 0; innerIterator< 3; innerIterator++) {
3 | console.log(outerIterator + ' ' + innerIterator);
4 | }
5 | }
6 |
7 | // This is a readable double for-loop
8 | // 3 is a small number
9 | // No performance issues (by now)
10 | // You will wait for real evidence
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.12 Removing Accidental Methods on Business Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.12 Removing Accidental Methods on Business Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/11c5f7da7d9c54a05456102e128d010d](https://gist.github.com/mcsee/11c5f7da7d9c54a05456102e128d010d)
5 |
6 | [https://gist.github.com/mcsee/47847ea77875bb6f6e5e1cba2e914b05](https://gist.github.com/mcsee/47847ea77875bb6f6e5e1cba2e914b05)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.13 Removing Business Code from the User Interface/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 17 Coupling - 17.13 Removing Business Code from the User Interface
2 |
3 |
4 | [https://gist.github.com/mcsee/213101392f85e7b9b06727204c84abe1](https://gist.github.com/mcsee/213101392f85e7b9b06727204c84abe1)
5 |
6 | [https://gist.github.com/mcsee/f3b239c093b15786d3e87f4a236203a2](https://gist.github.com/mcsee/f3b239c093b15786d3e87f4a236203a2)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.04 Replacing 'is-a' Relationship with Behavior/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 19 Hierarchies - 19.4 Replacing 'is-a' Relationship with Behavior
2 |
3 |
4 | [https://gist.github.com/mcsee/34677fbac1f6a837bf2b8d17bc882251](https://gist.github.com/mcsee/34677fbac1f6a837bf2b8d17bc882251)
5 |
6 | [https://gist.github.com/mcsee/29e46d1d672ac397552fae978148a7c2](https://gist.github.com/mcsee/29e46d1d672ac397552fae978148a7c2)
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.07 Making Concrete Classes Final/subclassification.java:
--------------------------------------------------------------------------------
1 | class Stack extends ArrayList {
2 | public void push(Object value) { … }
3 | public Object pop() { … }
4 | }
5 |
6 | // Stack does not behave Like an ArrayList
7 | // besides pop, push, top it also implements (or overrides)
8 | // get, set, add, remove and clear
9 | // stack elements can be arbitrary accessed
10 |
11 | // both classes are concrete
--------------------------------------------------------------------------------
/Code/Chapter 21 Technical Debt/21.04 Preventing and Removing ToDos and FixMes/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 21 Technical Debt - 21.4 Preventing and Removing ToDos and FixMes
2 |
3 |
4 | [https://gist.github.com/mcsee/76fb2f5fada656e6dd5be6989351e91c](https://gist.github.com/mcsee/76fb2f5fada656e6dd5be6989351e91c)
5 |
6 | [https://gist.github.com/mcsee/2d1fcb683f9c9c0391c7c369baf54bff](https://gist.github.com/mcsee/2d1fcb683f9c9c0391c7c369baf54bff)
--------------------------------------------------------------------------------
/Code/Chapter 04 Primitive Obsession/4.03 Reifying Associative Arrays/anemic.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | final class GeographicCoordinate {
4 |
5 | function __construct($latitudeInDegrees, $longitudeInDegrees) {
6 | $this->longitude = $longitudeInDegress;
7 | $this->latitude = $latitudeInDegress;
8 | }
9 | }
10 |
11 | $coordinate = new GeographicCoordinate(1000, 2000);
12 | // Should throw an error since these values don't exist on Earth
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.10 Removing the First Letter from Classes and Interfaces/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 7 Naming - 7.10 Removing the First Letter from Classes and Interfaces
2 |
3 |
4 | [https://gist.github.com/mcsee/00b852bfb884a47c5d7adf0543ec3a61](https://gist.github.com/mcsee/00b852bfb884a47c5d7adf0543ec3a61)
5 |
6 | [https://gist.github.com/mcsee/4507889577dd937dda844b8119782a50](https://gist.github.com/mcsee/4507889577dd937dda844b8119782a50)
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.05 Avoiding Modifying Collections While Traversing/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 13 Fail Fast - 13.5 Avoiding Modifying Collections While Traversing
2 |
3 |
4 | [https://gist.github.com/mcsee/9d66e179c57495aa7c2080ee34152c11](https://gist.github.com/mcsee/9d66e179c57495aa7c2080ee34152c11)
5 |
6 | [https://gist.github.com/mcsee/18369eb8798462ef04372be56827c9d6](https://gist.github.com/mcsee/18369eb8798462ef04372be56827c9d6)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.11 Preventing Return Boolean Values for Condition Checks/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.11 Preventing Return Boolean Values for Condition Checks
2 |
3 |
4 | [https://gist.github.com/mcsee/973a11295d0d93baa620763dd8eff801](https://gist.github.com/mcsee/973a11295d0d93baa620763dd8eff801)
5 |
6 | [https://gist.github.com/mcsee/ab38ef6fcc5dd6dea98f1edb452e75e9](https://gist.github.com/mcsee/ab38ef6fcc5dd6dea98f1edb452e75e9)
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.11 Preventing Return Boolean Values for Conditions Checks/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 14 IFs - 14.11 Preventing Return Boolean Values for Conditions Checks
2 |
3 |
4 | [https://gist.github.com/mcsee/57c079a22fe139667c8330a937d4dcca](https://gist.github.com/mcsee/57c079a22fe139667c8330a937d4dcca)
5 |
6 | [https://gist.github.com/mcsee/0f0cfe7cd5133dc605555eeb20feaa95](https://gist.github.com/mcsee/0f0cfe7cd5133dc605555eeb20feaa95)
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.09 Removing Queries from Constructors/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 16 Premature Optimization - 16.9 Removing Queries from Constructors
2 |
3 |
4 | [https://gist.github.com/mcsee/5125008158d94d51b27e8687bbbbf812](https://gist.github.com/mcsee/5125008158d94d51b27e8687bbbbf812)
5 |
6 | [https://gist.github.com/mcsee/a84b6d71034c47c1f95590d74bd2126d](https://gist.github.com/mcsee/a84b6d71034c47c1f95590d74bd2126d)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.12 Removing Accidental Methods on Business Objects/safecar.py:
--------------------------------------------------------------------------------
1 | class car:
2 |
3 | def __init__(self,company,color,engine):
4 | self._company = company
5 | self._color = color
6 | self._engine = engine
7 |
8 | def goTo(self, coordinate):
9 | self.move()
10 |
11 | def startEngine(self):
12 | ## code to start engine
13 | self.engine.start()
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.14 Changing Coupling to Classes/coupled.java:
--------------------------------------------------------------------------------
1 | public class MyCollection {
2 | public bool HasNext { get; set;} // implementation details
3 | public object Next(); // implementation details
4 | }
5 |
6 | public class MyDomainObject sum(MyCollection anObjectThatCanBeIterated) {
7 | // Tight coupling
8 | }
9 |
10 | // You cannot fake or mock this method
11 | // since it always expects an instance of MyCollection
--------------------------------------------------------------------------------
/Code/Chapter 07 Naming/7.14 Removing Impl PrefixSuffix from Class Names/Address.java:
--------------------------------------------------------------------------------
1 | // Simple
2 | public class Address {
3 | private String street;
4 | private String houseNumber;
5 | private City city;
6 | // ..
7 | }
8 |
9 | // OR
10 | // Both are real-world names
11 | public class Address implements ContactLocation {
12 | private String street;
13 | private String houseNumber;
14 | private City city;
15 | // ..
16 | }
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.07 Extracting Caches from Domain Objects/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 16 Premature Optimization - 16.7 Extracting Caches from Domain Objects
2 |
3 |
4 | [https://gist.github.com/mcsee/c429e71f6b0239b83e7e307feb5927fe](https://gist.github.com/mcsee/c429e71f6b0239b83e7e307feb5927fe)
5 |
6 | [https://gist.github.com/mcsee/7b6a2b5eb49cbb4dc690a2657d6837d0](https://gist.github.com/mcsee/7b6a2b5eb49cbb4dc690a2657d6837d0)
--------------------------------------------------------------------------------
/Code/Chapter 03 Anemic Models/3.08 Removing Getters/getters.php:
--------------------------------------------------------------------------------
1 | width;
10 | }
11 |
12 | public function getArea() {
13 | return $this->width * $this->height;
14 | }
15 |
16 | public function getChildren() {
17 | return $this->children;
18 | }
19 | }
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.04 Removing Cleverness from Code/intelligent.js:
--------------------------------------------------------------------------------
1 | function primeFactors(numberToFactor) {
2 | var factors = [],
3 | divisor = 2,
4 | remainder = numberToFactor;
5 |
6 | while(remainder>=2) {
7 | if(remainder % divisor === 0) {
8 | factors.push(divisor);
9 | remainder = remainder / divisor;
10 | }
11 | else {
12 | divisor++;
13 | }
14 | }
15 | return factors;
16 | }
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.03 Removing Bitwise Premature Optimizations/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 16 Premature Optimization - 16.3 Removing Bitwise Premature Optimizations
2 |
3 |
4 | [https://gist.github.com/mcsee/46a0a22d915e949c42cfb8260a5689bc](https://gist.github.com/mcsee/46a0a22d915e949c42cfb8260a5689bc)
5 |
6 | [https://gist.github.com/mcsee/31a2d5a8699579d5472688b3ac9d9f61](https://gist.github.com/mcsee/31a2d5a8699579d5472688b3ac9d9f61)
--------------------------------------------------------------------------------
/Code/Chapter 17 Coupling/17.09 Removing the Middleman/middleman.java:
--------------------------------------------------------------------------------
1 | public class Client {
2 | Address address;
3 | public ZipCode zipCode() {
4 | return address.zipCode();
5 | }
6 | }
7 |
8 | public class Address {
9 | private ZipCode zipCode;
10 |
11 | public ZipCode zipCode() {
12 | return new ZipCode('CA90210');
13 | }
14 | }
15 |
16 | public class Application {
17 | ZipCode zipCode = client.zipCode();
18 | }
--------------------------------------------------------------------------------
/Code/Chapter 19 Hierarchies/19.06 Renaming Isolated Classes/fullyQualifiedHierarchy.java:
--------------------------------------------------------------------------------
1 | abstract class PerserveranceDirection {
2 | }
3 |
4 | class PerserveranceDirectionNorth extends PerserveranceDirection {}
5 | class PerserveranceDirectionEast extends PerserveranceDirection {}
6 | class PerserveranceDirectionWest extends PerserveranceDirection {}
7 | class PerserveranceDirectionSouth extends PerserveranceDirection {}
8 |
9 | // Subclasses have fully qualified names
--------------------------------------------------------------------------------
/Code/Chapter 20 Testing/20.02 Adding Descriptions to Assertions/assertEquals.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | public function testNoNewStarsAppeared(): void
4 | {
5 | $expectedStars = $this->historicStarsOnFrame();
6 | $observedStars = $this->starsFromObservation();
7 | // These sentences get a very large collection
8 |
9 | $this->assertEquals($expectedStars, $observedStars);
10 | // If something fails you will have a very hard time debugging
11 | }
--------------------------------------------------------------------------------
/Code/Chapter 13 Fail Fast/13.06 Redefining Hash and Equality/equalsAndHashCorrelated.java:
--------------------------------------------------------------------------------
1 | public class Person {
2 |
3 | public String name;
4 | // Public attributes are another smell
5 |
6 | @Override
7 | public boolean equals(Person anotherPerson) {
8 | return name.equals(anotherPerson.name);
9 | }
10 |
11 | @Override
12 | public int hashCode() {
13 | return name.hashCode();
14 | }
15 | // This is just an example of non-correlation
16 |
17 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.01 Replacing Accidental Ifs with Polymorphism/encapsulated.js:
--------------------------------------------------------------------------------
1 | class Movie {
2 | constructor(rate) {
3 | this._rate = rate; // Rate is now private
4 | }
5 | warnIfNotAllowed(age) {
6 | this._rate.warnIfNotAllowed(age);
7 | }
8 | }
9 |
10 | class Moviegoer {
11 | constructor(age) {
12 | this.age = age;
13 | }
14 | watchMovie(movie) {
15 | movie.warnIfNotAllowed(this.age);
16 | // watch movie
17 | }
18 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.04 Replacing SwitchCaseElseif Statements/converters.js:
--------------------------------------------------------------------------------
1 | class Mp3Converter {
2 | convertToMp3(source, mimeType) {
3 | if(mimeType.equals("audio/mpeg")) {
4 | this.convertMpegToMp3(source)
5 | } else if(mimeType.equals("audio/wav")) {
6 | this.convertWavToMp3(source)
7 | } else if(mimeType.equals("audio/ogg")) {
8 | this.convertOggToMp3(source)
9 | } else if(...) {
10 | // Lots of new clauses
11 | }
--------------------------------------------------------------------------------
/Code/Chapter 14 IFs/14.13 Extracting from Long Ternaries/polymorphic.js:
--------------------------------------------------------------------------------
1 | const invoice = isCreditCard ?
2 | createCreditCardInvoice() :
3 | createCashInvoice();
4 |
5 | // or better...
6 |
7 | if (isCreditCard) {
8 | const invoice = createCreditCardInvoice();
9 | } else {
10 | const invoice = createCashInvoice();
11 | }
12 |
13 | // Even better with polymorphism...
14 |
15 | const invoice = paymentMethod.createInvoice();
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.06 Breaking Long Chains of Collaborations/direction.js:
--------------------------------------------------------------------------------
1 | class Dog {
2 | constructor(feet) {
3 | this.feet = feet;
4 | }
5 | walk() {
6 | // This is encapsulated on how the dog walks
7 | for (var foot of this.feet) {
8 | foot.move();
9 | }
10 | }
11 | }
12 |
13 | class Foot {
14 | move() { }
15 | }
16 |
17 | feet = [new Foot(), new Foot(), new Foot(), new Foot()];
18 | dog = new Dog(feet);
19 | dog.walk();
--------------------------------------------------------------------------------
/Code/Chapter 16 Premature Optimization/16.08 Removing Callback Events Based On Implementation/README.md:
--------------------------------------------------------------------------------
1 | # Sources for Chapter 16 Premature Optimization - 16.8 Removing Callback Events Based On Implementation
2 |
3 |
4 | [https://gist.github.com/mcsee/0a96468b7877744c0ec41d60378df4cd](https://gist.github.com/mcsee/0a96468b7877744c0ec41d60378df4cd)
5 |
6 | [https://gist.github.com/mcsee/185fef9ac202fed779fcf8a6c8f0bac3](https://gist.github.com/mcsee/185fef9ac202fed779fcf8a6c8f0bac3)
--------------------------------------------------------------------------------
/Code/Chapter 22 Exceptions/22.07 Hiding Low Level Errors from End Users/handled.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | // A user-defined exception handler function
4 | function myException($exception) {
5 | logError($exception->description())
6 | // You don’t show Exception to final users
7 | // This is a business decision
8 | // You can also show a generic user message
9 | }
10 |
11 | // Set user-defined exception handler function
12 | set_exception_handler("myException");
--------------------------------------------------------------------------------
/Code/Chapter 10 Complexity/10.02 Removing SettingsConfigs/configs.js:
--------------------------------------------------------------------------------
1 | class VerySpecificAndSmallObjectDealingWithPersistency {
2 | retrieveData() {
3 | if (GlobalSettingsSingleton.getInstance()
4 | .valueAt('RetrievDataDirectly')) {
5 | // Notice the unnoticed typo in 'RetrievDataDirectly'
6 | this.retrieveDataThisWay();
7 | }
8 | else {
9 | this.retrieveDataThisOtherWay();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------