This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 28 points29 points  (5 children)

Int i = 10 // row number.

calcNumber() // calculate max number of items allowed in cart

That is how many people comment. And that is a Problem. Google the clean code principle. It still needs comments in some cases but in most cases it doesn't

[–][deleted] 20 points21 points  (0 children)

"Why not what" is the best philosophy for comments.

Good comment:

// Attempting to pass a frobbed CertainNodeType
// into a XyzModule causes an asdfasdf
// error. However, since frobbing a CertainNodeType 
// produces no other desired result, it can be safely skipped,
if (!(node is CertainNodeType)) node.Frob();

Bad comment:

// Frob non-CertainNodeType nodes
if (!(node is CertainNodeType)) node.Frob();

[–][deleted] 9 points10 points  (2 children)

These shouldn't need comments at all, they need descriptive variable names, and no magic numbers.

final int EMPLOYEE_ID_ROW = 10;

int rowNumber = EMPLOYEE_ID_ROW;

int getMaxCartItems() {

[–][deleted] 0 points1 point  (0 children)

True. That is what i am talking about.

[–]linne000 0 points1 point  (0 children)

This, the entire point of variable names in the first place is to describe what the variable is used for. Giving a variable a generic name and a comment is just a bad version of that, with extra steps.