Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×

Comment Re:Comments are good (Score 1) 660

Well, it seems like if you left the comments and followed the algorithm:

Read comment,
Read code,
Do they agree?
    - Yes, good, this is probably not the bug
    - No, is this a bug?
        - Yes, comment is correct, fix code, check if bug still exists
        - No, correct comment.

It seems faster, and leaves the comments for the next time you or someone else looks at the code. Also, the comments are correct now.

More often than not, people *THINK* correctly and code incorrectly, so the comments are useful. If the thought is incorrect, you've probably just found a bug in the software. Yeah, it is useful to understand the entire code base yourself, but that will come naturally as you have to dig down farther to find the flaws.

Comment Re:The comment may also be complex.. (Score 4, Interesting) 660

I've gotten into the habit of commenting first, coding second. It is especially useful in complex systems.

I find that if I write the high level logic in comments of all the functions I'm going to write, it helps me find where I should break out repeated logic and solidifies the design. Once everything has been commented, I can go back and write the code.

This lets me know what the variables are going to be and can name them appropriately (why name it `i` when I can call is `block_index`). I don't lose the big picture of what needs to get done. It gives me targets to meet and stopping points at the end of the day (a sense of accomplishment and goals for tomorrow is *really* nice). Future coders can read my comments and see what I was thinking (this has actually happened to me). As a bonus, I can worry more about corner cases as I'm writing the code instead of creating corner cases to worry about later.

I've done it with a Flash memory interface, O/S memory manager, and a kernel module. Each time I've finished, even if it isn't the best code in the world, I know that if the next person reads the comments, they'll know what I was thinking.

Better code all around.

Slashdot Top Deals

On the eighth day, God created FORTRAN.

Working...