Answers
Question #3 – Refactoring Programs
Refactor the following code; i.e. improve its quality without modifying its behavior;
Use meaningful names for variables, parameters & functions
Provide proper documentation as required in the PAs
Provide proper indentation & programming style similar to the examples from the textbook, videos & PAs
Remove useless code
Simplify program
Improve performance
You will provide your version in the “Your Modified Version” subsection which is already pre-filled with the original. Then, for each improvement you applied, use the table in the “Summary” subsection to explain what you did & why you did it.
Program to Refactor
int mystery(int v1, int v2){
if( (v1 < 1) || (v2 < 1) ) return 0;
if( v1 < v2 ) return mystery(v1, v2-1)+1;
if( v2 < v1 ) return mystery(v1-1, v2)+1;
return mystery(v1-1, v2-1);
}
Your Improved Version
int mystery(int v1, int v2){
if( (v1 < 1) || (v2 < 1) ) return 0;
if( v1 < v2 ) return mystery(v1, v2-1)+1;
if( v2 < v1 ) return mystery(v1-1, v2)+1;
return mystery(v1-1, v2-1);
}
Summary of Improvements
Feel free to add rows to, or remove rows from, this table as needed;
12 years ago
5
- Database Design Assignment
- which of the following chemical compunds prevents the citric acid cycle from using the citric acid.? lactic acid hydrochloric acid citrate fluocitrate
- Java PEOPLE come on easy money
- Issues
- Business Forecasting with Excel
- ENG-215: Monsters in Literature
- Bus-445
- as soon as possible
- Organizational Behaviour - Article Critique
- COM 325 Week 2 Assignment ( What Would You Do Ethics and Today’s Administrative Professional ) ~ A + Tutorial With References