Coding
Posted
The Wrong Abstraction
When coding, we sometimes find ourselves having to work with a certain abstraction which made sense when it was first introduced, but if we were to extend it, it could be pushing its purpose a bit too much–we could end up with the wrong abstraction.
In these cases, Sandi Metz suggests:
When dealing with the wrong abstraction, the fastest way forward is back. Do the following:
- Re-introduce duplication by inlining the abstracted code back into every caller.
- Within each caller, use the parameters being passed to determine the subset of the inlined code that this specific caller executes.
- Delete the bits that aren’t needed for this particular caller.
Function Size
A function does one thing if you cannot meaningfully extract another function out of it.