Refactoring
The video here will explain what refactoring is, and why it can be helpful:
To follow along with the video, you can download the source code by using the links below. You can pause the video every few minutes and look through the code.
Part 3: After changing the data structure
Details on refactoring
In large projects, software developers read through the code often. This means that it is valuable to have code that is easier to understand and work with.
Improving code in any of these ways is considered a type of refactoring:
- Naming
- Improving the variable names, method names, and file names
- Readability, intention
- Making the purpose of the classes and methods more clear to people reading the code
- Readability, implementation
- Making the implementation - how the program works - more clear to people reading the code
- Testability
- Restructuring the program so that automated tests can be written
- Flexibility
- Making the pieces of the program not be tangled to the details of other pieces of the program
Why should we spend time organizing code in a way that allows us to make changes in the future?
Because in the world of professional software development, code is always changing. Some reasons why a program will need to change:
- New requirements
- Realizing that the program needs to have different capabilities
- Feature requests
- Needing to add or modify a feature
- Reuse
- Taking code from one project and repurposing it to use in another project
- Bug fixes
- Needing to fix bugs and errors
- Platform changes
- Maintaining compatibility with the newest versions of Python, and newest versions of the Python modules being used
Wrap up
This brings us to the end of new content for the course. Next week we will focus on revision of content: Make sure to come prepared to discuss topics you still feel unsure about.
We will also release your final project early next week! You will have two weeks to work on it, and it will be your biggest coding exercise yet. Organize your time to start as early as possible, and use office hours wisely!