Refactoring Exercises for Deliberate Practice

In this series of exercises, we practice various refactoring techniques. You may want to run pylint on this script to find any pep8 compliance issues. Fix as much as issues you can.

Exercise 1: 'Extract Method' Technique

Study the file 'extract_method.py'. Use 'extract method' technique to improve modularity of the code.

Exercise 2: 'Inline Method' Technique

Study the file 'inline_method.py'. Use 'inline method' technique to improve readability of the code.

Exercise 3: 'Replace Temp with query' Technique

Study the file 'replace_temp_with_query_fowler.py'. Use Replace Temp with query' technique to improve readability of the code.

Exercise 4: 'Introducing Explaining Variable' Technique

Study the file 'introduce_explaining_variable3.py'. Use Replace Temp with query' technique to improve readability of the code.

Exercise 5: 'Extract Method' Technique

Study the file 'extract_method3.py'. Use 'extract method' technique to improve modularity of the code.

Exercise 6: Various Techniques

Study the file 'replace_temp_with_query.py'. Use 'Replace Temp with query' and 'Extract Method' techniques to improve readability of the code.

Exercise 7: 'Split Temporary Variable' Technique

Study the file 'split_temp_variable.py'. Use 'split temporary variable' technique to clarify the code (make it easier to understand its intent.)

Exercise 8: 'Remove Assignment to Method Parameter' Technique

Study the file 'remove_assignment_to_param.py'. Use 'remove assignment to method parameter' technique to prevent future mistakes/bugs.

Exercise 9: 'Rename Method' Technique

Study the file 'rename_method.py'. Use 'rename method' technique to clarify the code (make it easier to understand its intent.)

Exercise 10: 'Split Temporary Variable' Technique

Study the file 'split_temp_variable2.py'. Use 'split temporary variable' technique to clarify the code (make it easier to understand its intent.)

Exercise 11: 'Introducing Explaining Variable' Technique

Study the file 'introduce_explaining_variable.py'. Use 'Replace Temp with query' technique to improve readability of the code.

Exercise 12: 'Decompose Conditional' Technique

Study the file 'decompose_conditional2.py'. Use 'decompose conditional' technique to improve readability of the code.

Exercise 13: 'Consolidate Conditional Expression' Technique

Study the file 'consolidate_conditional.py'. Use 'consolidate conditional expression' technique to improve readability of the code.

Exercise 14: 'Consolidate Duplicate Conditional Fragments' Technique

Study the file 'consolidate_duplicate_conditional_fragments.py'. Use 'consolidate duplicate conditional fragments' technique to improve readability of the code.

Exercise 15: 'Remove Control Flag' Technique

Study the file 'remove_control_flag'.py. Use 'remove control flag' technique to improve readability of the code.

Exercise 16: 'Replace Nested Conditional with Gaurd Clauses' Technique

Study the file 'replace_nested_conditional_with_gaurd_clauses2.py'.py. Use 'Replace Nested Conditional with Gaurd Clauses' technique to improve readability of the code.

Exercise 17: 'Decompose Conditional' Technique

Study 'decompose_conditional.py' file. Use 'decompose conditional' technique in combination with any other refactoring technique you've learned to improve readability/modularity of the code.

Exercise 18: 'Consolidate Duplicate Conditional Fragments' Technique

Study 'consolidate_duplicate_conditional_fragments2.py' file. Use 'consolidate duplicate conditional fragments' Technique to improve the code.

Exercise 19: 'Remove Control Flag' Technique

Study 'remove_control_flag2.py' and 'remove_control_flag3.py'. Use 'remove control flag' technique in combination with any other refactoring technique you've learned to improve readability of the code.

Exercise 20: 'Replace Nested Conditional With Gaurd Clauses' Technique

Study 'replace_nested_conditional_with_gaurd_clauses.py'. Use 'replace nested conditional with gaurded clauses' technique in combination with any other refactoring technique you've learned to improve readability/modularity of the code.

Exercise 21: 'Move Attribute' Technique

Study 'move_field2.py'. Use 'move attribute' technique in combination with any other refactoring technique you've learned to improve readability/modularity of the code.

Exercise 22: 'Extract Class' Technique

Study 'extract_class.py'. Use 'extract class' technique in combination with any other refactoring technique you've learned to improve readability/modularity of the code.

Exercise 23: 'Extract Class' Technique

Study 'extract_class2.py'. Use 'extract class' technique in combination with any other refactoring technique you've learned to improve readability/modularity of the code.

Exercise 24: 'Extract Class' Technique

Study 'extract_class3.py'. Use 'extract class' technique in combination with any other refactoring technique you've learned to improve readability/modularity of the code.

Exercise 25: 'Replace Magic Number with Symbolic Constant' Technique

Study 'replace_magic_numbers_with_named_constants.py'. Use 'replace magic number with symbolic constant' technique in combination with any other refactoring technique you've learned to improve readability/modularity of the code.

Exercise 26: 'Extract Superclass' Technique

Study 'extract_superclass2.py'. Use 'extract class' technique in combination with any other refactoring technique you've learned to improve readability/modularity of the code.

Where to Submit Your Answer

Please submit your work to Gradescope.