Duplication is far cheaper than the wrong abstraction

Sandy Metz said that if you find yourself passing parameters and adding conditional paths through shared code, the abstraction is incorrect. Then you should go back:

  1. Re-introduce duplication by inlining the abstracted code back into every caller.
  2. Within each caller, examine the parameters that got passed in order figure out which bits of the inlined code you actually use.
  3. Delete the bits that aren’t needed for this particular caller.


Categories: Ruby on Rails & other tech

%d bloggers like this: