Smells and refactorings annotated with [BC]
are my (Ben
Christel's) original research. In other words, don't expect
to find much if you Google them. I've included them here
because I think they're relevant for fixing the types of
problems represented in autoclop.rb
. Other smells are
drawn from the C2 Wiki and elsewhere; it's often hard to determine
whom to credit.
Unless otherwise noted, all refactorings are from Martin Fowler's book, Refactoring: Improving the Design of Existing Code.
- Explanatory Comment. Fix using Extract Method combined with Remove Comment [BC], or Replace Inline Code with Function Call.
- Commented-out Code. Fix using Remove Comment [BC].
- Telic Comment in Code. Fix using Move Telic Comment To Test [BC].
- Doc Comment. Fix using Remove Comment [BC].
- Inconsistent Formatting. Fix using Rearrange Whitespace [BC].
- Missing Editing Affordance [BC]. Often fixed by Rearrange Whitespace [BC].
- Unclear Name. Fix using Rename Variable, Rename Method.
- Idea Fragment [Katrina Owen]. Fix using Inline Method.
- Data Clump. Fix using Preserve Whole Object or Introduce Parameter Object.
- Alternative Classes with Different Interfaces. Fix using Rename Method.
- Dead Code. Fix using Remove Dead Code.
- Long Method. Fix with Replace Inline Code with Function Call or Extract Method.
- Nested Loops and Conditionals. Fix with Replace Inline Code with Function Call, Replace Loop with Pipeline, or Extract Method.
- Global State. Fix using Inject Global State [BC]. If code is writing to global state, use Return Modified Value.
- Casual Mutation [BC]. In straight-line code, fix with Split Variable. In looping code, use Replace Loop with Pipeline.
- Asymmetrical Code. Fix with Extract Method, Inline Method, or Rename Method.
- Duplicated Code. Fix by applying the Flocking Rules [Sandi Metz and Katrina Owen].
- Null Check. Fix with Introduce Null Object or Introduce Continuation [BC].
- Feature Envy. Fix with Move Method, possibly preceded by Extract Method.
- Primitive Obsession. Fix using Replace Primitive with Object. See also Avoid Hashy Syntax In Ruby for a language-specific refactoring technique.
- Switch on Type. Fix using Replace Conditional with Polymorphism.
- Middleman. Fix using Inline Method.
- Deep Hierarchy [BC]. Flatten deep call trees using Inline Method and Inline Class. Then create shallower trees using Extract Method.
- Message Chain. A.K.A. "Train Wreck" or "Law of Demeter Violation". Fix using Replace Query with Parameter or Extract Method and Move Method.
- Option Parameter [BC]. Fix with Move Statements To Callers.