- Code Along,Recognize common anti-patterns that lead to excess code
- Identify unused and/or excessive expressions
- Interpret existing functions to derive purpose
- Recognize how refactoring code improves readability
In this lesson, we will be looking in more detail at part of the process of refactoring - removing excess code.
Tidying up code serves multiple purposes. It makes it easier for our future selves to understand what we've written. But more than that, it also improves our current understanding of the code we've written.
- Provide a few code examples that are convoluted, contains extra/unused variables, irrelevant steps for students to clean out.
- Simple at first to help the student understand the process. Each example can be a slightly different problem.
Some anti-patterns to discuss:
- Assigning inputs to variables
- Unused inputs
- Assigning variables and not using them
- Overly complicated loops
- Multiple nested if statements
- Using a final, larger code example, go through the process of on unknotting and cleaning up the code by looking for the anti-patterns discussed in the previous section
- Reiterate value of tidying up code