Skip to content

Latest commit

 

History

History
 
 

5_refactoring

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Week 6 Home

U2.W6: Refactoring for Code Readability

Learning Competencies

  • Explain what code is doing
  • Refactor for clarity and readability

Summary

Using the goals below, choose a challenge solution from Class Warfare, Validate a Credit Card Number. This can be anyone's solution, but if you notice there's a lot of room for improvement with your own code, start with that. Find other's solutions by browsing the branches (just like you would to comment on a random person's solution).

Paste the original unrefactored code in your gist, and as you refactor, make notes of the changes you are making to achieve optimal readability. Include those notes along with the refactored version in your my_solution.rb file.

Goals of Readable Code

  • Eliminate repetition by using looping and branching wisely
  • Complex operations are decomposed into constituent parts
  • Descriptive names for methods, variables, classes, and modules
  • Methods are small and behavior is obvious
  • Minimizes need for comments because the code tells you what it is doing
  • Code is formatted with proper indentation for optimal readability

Release 0: Write assert statements

Take the driver code and turn it into assert statments with valid and invalid card numbers.

Release 1: Pseudocode

Release 2: Comment the code

Comment each chunk of code in the original solution

Release 3: Refactor the solution for readability

Release 4: Reflect

Release 5: Push your solution to Github

Release 6: Review

Write feedback for at least two other solutions!