└── 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | readFileToMemory(); 5 | $this->translateContents(); 6 | $this->generateStatsAndSaveFileContents(); 7 | } -------------------------------------------------------------------------------- /Code/Chapter 06 Declarative Code/6.15 Avoiding Magic Corrections/failFast.php: -------------------------------------------------------------------------------- 1 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | {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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | } --------------------------------------------------------------------------------