Writing / June 19, 2013
Write the same program more than once
The second draft is where understanding actually happens.
The first version of a program is mostly a conversation with the problem. It tells you what you did not understand. Too often we stop there, keep the working code, and move on. A second version, written on purpose from a blank file, is where the learning becomes yours.
Rewrite small things on purpose
Pick an algorithm or a pattern, not an entire system. Implement it once to confirm the behavior. Then delete it and write it again with a different structure. Maybe the first version used nested functions and the second uses a small class. Maybe the second stores data in a flat array instead of a map.
Compare with real notes
After each version, write down how it felt to read, how much memory it used, and where the edges were. The notes matter more than the code. They turn a lucky solution into a set of tradeoffs you can explain to someone else.
Keep the version that teaches
The final version does not have to be clever. It has to be clear enough that future you can change it under pressure. A rewrite is not gold plating if it replaces uncertainty with understanding. When the goal is learning, throwing code away is progress.
This habit pairs well with the profiling approach in profiling before optimizing.
Takeaways
- Choose a small algorithm and implement it more than once.
- Write down memory, speed, and readability notes for each version.
- Prefer the version you can explain and change under pressure.