Refactoring for C# developers Flashcards
What is refactoring?
Changes to the internal structure of a software to make it easy to understand and modify.
What does refactoring should NOT affect?
The observable behavior of the software.
What happens if we don’t refactor often?
The software might get too complex to change.
When to refactor?
After making the unit test pass (part of tdd);
As part of fixing a bug;
As part of creating a new feature;
When not to refactor?
When current code does not work;
Massive technical debt (not developer’s call);
Imminent deadline;
What does martin fowler says about refactoring?
Othen than when you’re very close to a deadline… you should not put off refactoring because you haven’t time.
Does the boy scout rule apply in refactorings?
yes.
What are the four steps of refactoring?
Commit (or restore) current working code;
Verify existing behavior (ideally with automated tests);
Apply a refactoring;
Confirm original behavior has been preserved.
What is characterization tests and when they are most useful?
Characterization tests asserts the current behavior of the software (even without knowing if it is correct). Most useful for legacy software which does not have unit tests.
What are the four steps of characterization tests?
Write tests you know will fail;
Get the output of the test;
Update the test to assert the current behavior;
Run the test again; should pass;
What to refactor to achieve a cleaner code base?
remove duplication; improve naming; break up large code elements; reduce coupling; reduce complexity; split responsability (SRP);
what is a code smell?
surface indication that usually correspond to a deeper problem in the system.
What is the “Principle of Least Astonishment”?
Do what users expect;
Be simple;
Be clear;
!!!Be consistent!!!;
What are the five classifications of code smells?
Bloaters, object-orientation abusers, change preventers, dispensables and couplers.
What is a Bloater?
More code than it is actually necessary.