Learning from Solution CodeThis article guides learners through comparing their code to the solution code, and maximizing learning through this process.
Learning from Solution Code
When you compare your solution to the official solution code, you’ll likely find that there are more differences than you were expecting. This is to be expected, and does not mean that your solution is wrong!
Reviewing solution code is one of the most effective ways of getting better at programming. When you are coding on the job, you will likely be working with code that was written by many different people and throughout a wide time-frame. Being able to read and get up to speed with someone else’s code is a valuable skill that will enable you to be more confident when contributing to shared projects.
Furthermore, comparing your work to the solution code gives you the chance to:
- Think back to the decisions that you made when doing the project. What reasons did you have for making the decisions that you did? After seeing the solution, would you still make the same decisions?
- Think about readability. Often times, the solution code will prioritize readability and maintainability. On long-term collaborative projects, writing clear and readable code is a priority to ensure that other software engineers can understand the codebase well enough to add to it.
- Think about performance. For web apps, this usually means paying attention to the slower steps in the process: when the client sends a request across the internet to the server, and when the server queries the database. Is your code making any unnecessary requests? Are there any steps that could be batched together to limit the number of round-trips between the browser, server, and database? How does the performance of your code compare to the performance of the solution code? Performance should generally not be prioritized over readability/maintainability, but it is something worth considering when reviewing solution code.
Remember that struggle is important when permanently developing a new skillset and that debugging is also a skill that you need to build! Try not to peek at the solution code until you’ve completed the project, or unless you’re really stuck and your struggle has become totally unproductive. Have fun!