From the course: Computer Science Principles: Programming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Refactor code to make improvements

Refactor code to make improvements

From the course: Computer Science Principles: Programming

Start my 1-month free trial

Refactor code to make improvements

- Coding is an iterative process. You'll create code that solves a problem and then, perhaps weeks or months later, you'll come back to that same code, and wonder what you were thinking when you wrote it. Perhaps you learned a new practice that makes the code better, or you overlooked something when you first wrote it. Regardless of the reason, when you update your code to make it work better, you are refactoring it. Refactoring is a common practice with programming. As you add new capabilities to your programs, you'll revisit and update older code. The trick with refactoring is to make sure that any changes you make won't have adverse affects on the rest of the program. Take this example. If I have a program that stores three values, I might later decide it makes more sense to store those values in an array. When I refactor the code, I set up the values differently as an array. But I'm only partially done. Because I need to make sure that all the old references to the previous…

Contents