Commenting your code

I was just wondering about commenting of code lately, how do you guys comment your code.

When I started to program everybody always told me to comment almost every little step, like

// open file
fhandle = fopen() ;

// read line-per-line of the file until eof
while(!feof(fhandle)) {
}

Anyways, lately I’ve become lazy and just programmed as the thoughts came to me, but then my manager visited my desk one day and notified me to start commenting my code thoroughly.

Since then I respected my “elders” and started coding by first writing all the steps as comments

// open file
// if file not exist do this, otherwise continue
// read line
// analyze line
// if junk do nothing, if not junk handle with care

and then filling in all the “code”

// open file
fopen()
// if file not exist do this, otherwise continue
if(!fread)
// read line
freadln
// analyze line
// if junk do nothing, if not junk handle with care
if(read == junk) blablabla

Leave a Reply

Your email address will not be published. Required fields are marked *