Notes for Code & Coffee on 7/23/2021
Topic for 7/23: POP QUIZ: Name a few code smells
- Identified smells:
- Player 1 - (anonymized players in case they prefer it that way)
- Overused singleton
- Overly complex test code (to get 100% coverage)
- test private ctor throws exception (Bruce’s example)
- Side effects
- Pushing to a dev branch that hasn’t been green in three months
- Broken builds
- See also disabled tests
- Player 2
- Lack of type safe code in Java
- extra tests required to assert types
- Git commit messages that just tell exactly what was done
- maybe useful maybe not
- “Undoing last commit”
- For better commits try:
- Arlo’s git notation
- https://github.com/RefactoringCombos/ArlosCommitNotation
- R!! rewrote everything
- Lack of tooling support (gitlab stinks, git log ftw)
- Do it intra story, then squash and merge
- Make it easy to make the change (this may be hard) then make the easy change (Kent Beck)
- Player 3
- Shotgun surgery
- Making one change causes need to change in other places
- Feature envy
- Got a function doing work and needs or over uses collaborators
- Long methods
- Badly named variables
- Player 4
- Inconsistent IDE linting settings.
- What to do about code smells
- “When I was at x-company that was our job”
- 2 million line code base
- 30% dead code
- 20% duplicate code
- Copy/Paste coding
- Aggressively adding huge amounts of dead code
- Removed dead code and worthless comments
- 5000 loc -> 400 loc (extreme case)
- Nothing makes me happier than deleting code
- Eclipse and Intellij
- if statements that explicitly compare against true or false.
- little t true and big true and other notes I missed
- Do some uncomfortable low risk cleanups
- Links:
- “Get a whiff of this” - Sandi Metz:
- About refactoring and code smells
- Recorded talk: https://www.youtube.com/watch?v=PJjHfa5yxlU
- Slides from the talk: https://speakerdeck.com/skmetz/get-a-whiff-of-this
- See slide 6 for the “Classic Smells”
- Slide 10 & 11 take and organize them into categories
- This looks interesting but have not tried it:
- Smells to refactorings cheatsheet:
- https://www.industriallogic.com/blog/smells-to-refactorings-cheatsheet/
- https://www.industriallogic.com/img/blog/2005/09/smellstorefactorings.pdf