I’ll do comments first and then code. It’s a lot faster for me to keep a flow and pseudocode and then write the code in between. If the comments are two pedestrian afterwards (increment i), I will erase the comments.
I started this technique early in my career back in the late 90s after reading “Code Complete”.
It also helps me to pick back up faster if I get interrupted.
I’ve heard that styled as “do project the document,
don’t document the project” but I don’t
know a source to attribute this to.
The idea is to write a rough draft that covers what the project is, what it does, the API structure, and how to
use the project, then write the code, “projecting the document”, and finally sort out the documentation -
comments in the source, everything else in a manual page,
article, or research paper.
This sounds a lot like TDD, but with comments instead of tests. It's an interesting technique I never heard of.
Do you ever get back to code you wrote and find a lot of misleading comments that you simply forgot to delete/update? Or are you always updating the comments before you try a new approach if the first one didn't work out?
I started this technique early in my career back in the late 90s after reading “Code Complete”.
It also helps me to pick back up faster if I get interrupted.