chapter 6 Flashcards
(31 cards)
what is refactoring?
is the process of changing sw in away that:
- doesn’t change external behavior
- but internal structure is improved
__________ is the art of improving the art of an existing code [ cleaning up ]?
refactoring
what are bad smells?
problem areas due to poor coding and design choices
why should we refactor?
RR II HH P
- reduce redundant code
- reduce complexity
- improves design [ prevents “Decay” ]
- improves code readability
- helps code run faster
- helps find bugs
- provides a more expressive internal structure
which bad smell is due to too many lines of code, or too many parameters?
long method
explain a long class bad smell?
- classes do too much
- reduced cohesion
explain a divergent change bad smell?
- changes require changes in various d/t subsets of methods
- multiple changes are made to a single class
- weak cohesion
which bad smell is the result of a method requiring lots of info from another class?
feature envy
explain a lazy class bad smell?
- class isn’t doing enough to justify its existence
explain a switch case bad smell?
- result in duplicate codes
- can be replaced with polymorphism for a more effective approach
explain a shotgun surgery bad smell?
a single change requires changes to be made to multiple classes simultaneously
what is the opposite of shotgun surgery?
divergent change
explain a data clump bad smell?
is a result of multiple attributes clumped together but not belonging to the same class
explain a parallel inheritance hierarchy bad smell?
addition of a subclass to a hierarchy tree requires similar additions in related hierarchies
which bad smell is often used as a deodorant for bad code?
comments
explain a middle man bad smell?
a class delegates many of its responsibilities another class
describe a temporary field bad smell
is an attribute [ variable ] of an object that is not really needed or is used in limited circumstances.
describe a message chain bad smell
occurs when a class is highly coupled with other classes in a chain like delegation
[ client asks obj for another obj and so on ]
describe a data class bad smell
these are classes that do not define methods besides generic getters and setters
what are the requirements for refactoring?
CPR CCT S
- collective code ownership
- pair programing
- rested programmers
- coding standard
- continuous integration
- tests
- simple design
when should you refactor?
AAC3FL
- all the time
- when you add new features
- when the code smells
- rule of 3
- when you fix a bug
- when you learn something new
when should you not refactor?
- when the tests are failing
- when you should just rewrite the code
- when you have a deadline
what are obstacles when refactoring?
TMCPE - too much pressure
- time pressure - ref takes time
- management issues - “ we pay you to add new features not ref “
- complexity
- performance issues - ref slows down execution
- error possibilities
why are programers avoidant to refactoring?
LSNF - loser senef
- lack of refactoring skills
- short term focus
- not paid for overhead tasks like ref
- fear of breaking code