Difference between revisions of "Guidance Cards - Refactor"

From School of CS Student Wiki
Jump to navigation Jump to search
gravatar Mbax9mb5 [userPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (Refactor Card 1)
gravatar Mbax9mb5 [userPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
Line 25: Line 25:
 
<div class="mw-collapsible-content">
 
<div class="mw-collapsible-content">
 
<big>''"Repeated patterns in production code can suggest the need for a loop. Replace hard-coded if-statements with while/repeat loops to remove the duplication."''</big><br /><br />
 
<big>''"Repeated patterns in production code can suggest the need for a loop. Replace hard-coded if-statements with while/repeat loops to remove the duplication."''</big><br /><br />
[[File:Refactor 2.png|200px]]
+
[[File:Refactor 2.jpg|200px]]<br />
<br />
 
 
----
 
----
 
http://goo.gl/myM3wE | [http://chart.googleapis.com/chart?cht=qr&chs=150x150&choe=UTF-8&chld=H&chl=http://goo.gl/myM3wE QR Code]<br />
 
http://goo.gl/myM3wE | [http://chart.googleapis.com/chart?cht=qr&chs=150x150&choe=UTF-8&chld=H&chl=http://goo.gl/myM3wE QR Code]<br />
Line 39: Line 38:
 
<div class="mw-collapsible-content">
 
<div class="mw-collapsible-content">
 
<big>''"Using literals in the code is a form of technical debt. Define literals as constants to keep them under control"''</big><br /><br />
 
<big>''"Using literals in the code is a form of technical debt. Define literals as constants to keep them under control"''</big><br /><br />
[[File:Refactor 3.png|200px]]<br />
+
[[File:Refactor 3.jpg|200px]]<br />
  
 
[http://en.wikipedia.org/wiki/Magic_string Magic String]<br />
 
[http://en.wikipedia.org/wiki/Magic_string Magic String]<br />
Line 58: Line 57:
 
<div class="mw-collapsible-content">
 
<div class="mw-collapsible-content">
 
<big>''"Test code is code too. Look for duplication in your test code. Remove it by introducing helper methods. This should increase maintainability of your tests."''</big><br />
 
<big>''"Test code is code too. Look for duplication in your test code. Remove it by introducing helper methods. This should increase maintainability of your tests."''</big><br />
[[File:Refactor 4.png|200px]]
+
[[File:Refactor 4.jpg|200px]]
 
<br />
 
<br />
 
[http://programmers.stackexchange.com/questions/167922/how-do-people-maintain-their-test-suite How do people maintain their test suite?]<br />
 
[http://programmers.stackexchange.com/questions/167922/how-do-people-maintain-their-test-suite How do people maintain their test suite?]<br />
Line 64: Line 63:
 
http://goo.gl/eZM6uu | [http://chart.googleapis.com/chart?cht=qr&chs=150x150&choe=UTF-8&chld=H&chl=http://goo.gl/eZM6uu QR Code]<br />
 
http://goo.gl/eZM6uu | [http://chart.googleapis.com/chart?cht=qr&chs=150x150&choe=UTF-8&chld=H&chl=http://goo.gl/eZM6uu QR Code]<br />
  
</div>
 
</div>
 
 
<div class="toccolours mw-collapsible mw-collapsed">
 
 
== Refactor Card 5 ==
 
<div style="font-size: 140%;"><span style="background:#ff0">'''Requires Review/Re-wording'''</span></div>
 
<div class="mw-collapsible-content">
 
<big>''"Using literals in code is a form of technical debt. Remove literals by replacing them with an expression."''</big><br />
 
[[File:Refactor 5.png|200px]]
 
 
[http://en.wikipedia.org/wiki/Magic_string Magic String]<br />
 
 
[http://programmers.stackexchange.com/questions/56375/eliminating-magic-numbers-when-is-it-time-to-say-no Eliminating Magic Numbers: When is it time to say “No”?]<br />
 
 
[http://www.techrepublic.com/article/avoid-using-magic-numbers-and-string-literals-in-your-code/ Avoid using magic numbers and string literals in your code]
 
----
 
http://goo.gl/Dr2aKu | [http://chart.googleapis.com/chart?cht=qr&chs=100x100&choe=UTF-8&chld=H|0&chl=http://goo.gl/Dr2aKu QR Code]<br />
 
 
</div>
 
</div>
 
</div>
 
</div>
Line 91: Line 72:
 
<div class="mw-collapsible-content">
 
<div class="mw-collapsible-content">
 
<big>''"Refactoring is optional. Refactor only if you think it will improve the quality of your code."''</big><br />
 
<big>''"Refactoring is optional. Refactor only if you think it will improve the quality of your code."''</big><br />
[[File:Refactor 6.png|200px]]
+
[[File:Refactor 6.jpg|200px]]
  
 
[http://sourcemaking.com/refactoring/when-should-you-refactor When should you refactor?]<br />
 
[http://sourcemaking.com/refactoring/when-should-you-refactor When should you refactor?]<br />
Line 106: Line 87:
 
<div style="font-size: 140%;"><span style="background:#ff0">'''Requires Review/Re-wording'''</span></div>
 
<div style="font-size: 140%;"><span style="background:#ff0">'''Requires Review/Re-wording'''</span></div>
 
<div class="mw-collapsible-content">
 
<div class="mw-collapsible-content">
 +
[[File:Refactor 7.jpg|200px]]<br />
 
</div></div>
 
</div></div>
  
 
<div class="toccolours mw-collapsible mw-collapsed">
 
<div class="toccolours mw-collapsible mw-collapsed">
 
== Refactor Card 8 ==
 
== Refactor Card 8 ==
 +
[[File:Refactor 8.jpg|200px]]<br />
 
<div style="font-size: 140%;"><span style="background:#ff0">'''Requires Review/Re-wording'''</span></div>
 
<div style="font-size: 140%;"><span style="background:#ff0">'''Requires Review/Re-wording'''</span></div>
 
<div class="mw-collapsible-content">
 
<div class="mw-collapsible-content">
Line 116: Line 99:
 
<div class="toccolours mw-collapsible mw-collapsed">
 
<div class="toccolours mw-collapsible mw-collapsed">
 
== Refactor Card 9 ==
 
== Refactor Card 9 ==
 +
[[File:Refactor 9.jpg|200px]]<br />
 
<div style="font-size: 140%;"><span style="background:#ff0">'''Requires Review/Re-wording'''</span></div>
 
<div style="font-size: 140%;"><span style="background:#ff0">'''Requires Review/Re-wording'''</span></div>
 
<div class="mw-collapsible-content">
 
<div class="mw-collapsible-content">
 
</div></div>
 
</div></div>

Revision as of 15:35, 25 July 2014

Part of Red-Green-Go!

Refactor Card 1

Requires Review/Re-wording

"Your code should read as natural language as much as possible. Use helper methods to wrap code into meaningful labels."

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?


http://goo.gl/qvPwE4 | QR Code

Refactor Card 2

Requires Review/Re-wording

"Repeated patterns in production code can suggest the need for a loop. Replace hard-coded if-statements with while/repeat loops to remove the duplication."

Refactor 2.jpg


http://goo.gl/myM3wE | QR Code

Refactor Card 3

Requires Review/Re-wording

"Using literals in the code is a form of technical debt. Define literals as constants to keep them under control"

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


http://goo.gl/M66MS5 | QR Code

Refactor Card 4

Requires Review/Re-wording

"Test code is code too. Look for duplication in your test code. Remove it by introducing helper methods. This should increase maintainability of your tests."
Refactor 4.jpg
How do people maintain their test suite?


http://goo.gl/eZM6uu | QR Code

Refactor Card 6

Requires Review/Re-wording

"Refactoring is optional. Refactor only if you think it will improve the quality of your code."
Refactor 6.jpg

When should you refactor?
When is it time to refactor?
When to refactor?


http://goo.gl/2rWgw0 | 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

Authors

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