Guidance Cards - Refactor

From School of CS Student Wiki
Revision as of 17:02, 25 July 2014 by gravatar Mbax9mb5 [userPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs) (Refactor Card 6)
Jump to navigation Jump to search

Part of Red-Green-Go!

Refactor Card 1

Requires Review/Re-wording

Use helper methods with descriptive names to wrap low-level code, so that your code reads as much like natural language as possible.

Refactor 1.jpg

A good coder writes code that looks like it was easy and straightforward to do. Many of the examples by Brian Kernighan in his books follow this pattern. Part of the "trick" is coming up with a proper conceptualization of the problem and its solution. When we don't understand a problem well enough, we're more likely to over-complicate our solutions, and we will fail to see unifying ideas.

With a proper conceptualization of the problem, you get everything else: readability, maintainability, efficiency, and correctness. Because the solution seems so straightforward, there will likely be fewer comments, because extra explanation is unnecessary. A good coder can also see the long term vision of the product, and form their conceptualizations accordingly.

What does it mean to write good code? | QR Code

Refactor Card 2

Requires Review/Re-wording

Replace if-statements describing how to process 0, 1, 2 and 3 items with a loop showing how to process N items.

Refactor 2.jpg | QR Code

Refactor Card 3

Requires Review/Re-wording

Embedding literal values in your production code is a form of technical debt. Define key literals as constants to make their meaning explicit.

Refactor 3.jpg

Magic String

Eliminating Magic Numbers: When is it time to say “No”?

Avoid using magic numbers and string literals in your code | QR Code

Refactor Card 4

Requires Review/Re-wording

Remember that test code is code, too, and should also be refactored to keep the design clean.
Refactor 4.jpg
How do people maintain their test suite? | QR Code

Refactor Card 6

Requires Review/Re-wording

It's mandatory to look for refactoring opportunities in each red-green-green cycle. It is not mandatory to actually refactor. Do so only when the benefits are clear.
Refactor 6.jpg

When should you refactor?
When is it time to refactor?
When to refactor? | QR Code

Refactor Card 7

Requires Review/Re-wording

Refactor 7.jpg

Refactor Card 8

Refactor 8.jpg

Requires Review/Re-wording

Refactor Card 9

Refactor 9.jpg

Requires Review/Re-wording


  • gravatar Mbasssme [userPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] ·
  • gravatar Mbax9mb5 [userPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+]