- Class Slides
- Week 4 Exercises Redux
- Refactoring
- Example 1 / Refactored
- Example 2 / Refactored
- Example 3 / Refactored
- Example 4
- Refactored part 1
- Refactored part 2
- Refactored part 3
(refactored with generic random number generator and bounce functions
using the
return
keyword. "What are return values? Return values are just what they sound like — the values that a function returns when it completes.")
- Refactoring: Improving the Design of Existing Code, 2nd Edition by Martin Fowler, especially “Chapter 2: Principles in Refactoring” and “Chapter 3: Bad Smells in Code.” (NYU Library online access)
- Refactoring Guru: Refactoring (What is refactoring? Clean Code, Refactoring Process, Code Smells, and Refactoring Techniques)
- “Chapter 24: Refactoring,” Code Complete, 2nd Edition, by Steve McConnell (NYU Library online access)
- “Topic 41: Refactoring,” The Pragmatic Programmer, 2nd Edition, by David Thomas and Andrew Hunt (NYU Library online access)
- Naming things in JavaScript
- The ideas this week are to practice refactoring code that you have already written and to continue practicing version control with Git.
- Tip: Refactor your code in Git branches! See the steps in this week's (or last week's) class slides. Consider installing the Oh My Zsh shell framework (if not already implemented) to automatically display when you are in a Git repository along with the current branch.
- Create a local directory with a p5 project, initialize it at as a Git repository, and refactor a previous sketch so that the output is the same but the the code has been restructured.
- You can refactor a sketch from this course or another one. If your sketch is in the p5 web editor, copy and paste the code into your local p5 project on your computer.
- Challenge yourself to refactor a prior sketch that you really enjoyed but feels messy because you ran out or time, have a different understanding of how to implement programming concepts, and/or you have inklings that the code could be written in more efficient ways, i.e. "bad smells"
- As you refactor, commit notable changes or milestones:
- Look for repeating elements to convert into a loop, a function, or a class to make objects.
- Is there any unused code to remove?
- Can you make your code more readable? e.g. Any variables or functions to rename so that someone else reading your code can follow along without needing comments?
- Adding comments are okay too! Especially to reinforce YOUR understanding of programming concepts and how your sketch works.
- If there’s a lot of code, can you organize separate into different files? (See Coding Train video on how organize your code into multiple JavaScript files.)
- Write a blog post that includes a link to your refactored code.
- Describe and reflect on the changes you made and why you made them. How did it go with Git this week? For all of it (including the coding part), where did you get stuck, and what steps did you take troubleshoot? Anything that you would like to explore and practice more?
- Submit here