We comment whilst programming, but these days it's actually becoming more common to have fewer and fewer comments. I remember when I was first learning, the standard was to have *lots* of comments, but these days the emphasis tends to be more on "self documenting" code, i.e. it should be clear enough to understand without comments.
That is you don't write something in a convoluted way to make it run 0.001% faster, you write it in a clear way which any programmer can understand without comments.
You still have comments to explain non-obvious stuff, and perhaps to explain *why* you are doing something, not *what* you are doing. *what* you are doing should be clear from the code.
Certainly don't feel you need stuff like this:
- //Get database connection
- var db = getDatabaseConnection();
- //Get users.
- var allUsers = db.getUsers();
- //Iterate over users.
- for (var user in allUsers) {
- //blah
- }
Really none of those comments should be there, because it's plainly obvious what is happening
No comments:
Post a Comment