3 ms·
When I write code, the first thing I do is write out the code inside comments - including stuff like "Loop over the collection:". Once I've written the comments
by kaolinite 14y ago
When I write code, the first thing I do is write out the code inside comments - including stuff like "Loop over the collection:". Once I've written the comments, I start filling in the code. I find that whilst this generates "unhelpful" comments, it leads to much cleaner and well designed code. There's another advantage too. If your IDE or text editor changes the colour of comments, as it should, to a colour different to that of the code, then you can ignore all the code and simply read the comments. I find this makes skimming through code much faster.
Granted, this won't work in all situations. If you can't trust your colleagues to keep the comments updated (and if you don't review commits), then this is going to cause problems - however if you're writing for yourself or with a small group of people you trust, I strongly recommend giving it a go.