Software Refactoring & Migration Flashcards
What is refactoring?
“a change made to the internal structure of software to make it easier to UNDERSTAND and cheaper to MODIFY without changing the observable behaviour”
Examples of code changes?
- RENAMING a method or class
- Moving a METHOD up to a superclass or down to a subclass
- Moving a METHOD to a different class
- Converting a variable into a CONSTANT
- Converting a LOCAL (method) variable into a FIELD (class variable)
Importance of testing in refactoring?
We must start in a good state and remain in that state after the refactoring has been done.
Refactoring workflow?
Run test (start from known good state) Refactor Run tests (finish in same known good state)
What is a code smell?
“any characteristic in the source code of a program that possibly indicates a deeper problem”
What is Software Migration?
Move (i.e migrate) some functionality from one context to another (like refactoring with a bigger scope)
Examples of Software Migration
- System on files -> DBMS
- plain text communication -> encrypted communication
- proprietary statistical analysis library -> SPSS
- hosted system -> cloud
Describe the software migration process
- Ensure behaviour is tested
- Migrate tests (initially may fail)
- gradually migrate functionality
- finish when all tests pass
- get rid of old tests
What is a magic number?
A number that has IMPORTANT MEANING for the code but it’s not clear
How do we refactor frequent literals or magic numbers?
Extract Constant
How do we refactor long methods?
Extract Methods
Why are excessive comments a code smell?
- too many means code might not be of the highest quality
- they age and grow OUT OF STEP with the changing code
How to refactor code with excessive comments?
Extract Method