Click here to Skip to main content
15,886,110 members

Survey Results

Do you comment your code?   [Edit]

Survey period: 19 Jul 2010 to 26 Jul 2010

Some preach that good code requires no comments, while others preach that (good) comments can be as valuable as the code itself. On which part of the spectrum do you lie?

OptionVotes% 
I add comment headers for all public classes, objects and methods, events, fields etc36244.15
I add comment headers for all non-public classes, objects and methods, as well as non-obvious logic inside these24630.00
I provide comments at the top of files17821.71
I comment any code that may be obscure (the "what") to a reader51162.32
I comment any code where the purpose (the "why") may be obscure54466.34
I comment on expected inputs, outputs and other results17621.46
I comment on exceptions, side effects or error codes20525.00
I comment on structures (loop endings, function endings etc)10713.05
I comment as a last resort when I can't make my code any clearer22227.07
I do not comment code.465.61
Respondents were allowed to choose more than one answer; totals may not add up to 100%

View optional text answers (45 answers)


 
GeneralRe: I wish Pin
Stephen F. Heffner19-Jul-10 12:09
Stephen F. Heffner19-Jul-10 12:09 
GeneralRe: I wish Pin
destynova20-Jul-10 22:40
destynova20-Jul-10 22:40 
GeneralComments are just a way to use SVN as a communication protocol. Pin
elchupathingy19-Jul-10 4:43
elchupathingy19-Jul-10 4:43 
GeneralIn Some Cases Pin
Kunal Chowdhury «IN»19-Jul-10 4:27
professionalKunal Chowdhury «IN»19-Jul-10 4:27 
GeneralRe: In Some Cases Pin
thatraja19-Jul-10 5:44
professionalthatraja19-Jul-10 5:44 
GeneralRe: In Some Cases Pin
Stephen F. Heffner19-Jul-10 12:16
Stephen F. Heffner19-Jul-10 12:16 
GeneralRe: In Some Cases Pin
Kunal Chowdhury «IN»19-Jul-10 19:46
professionalKunal Chowdhury «IN»19-Jul-10 19:46 
GeneralRe: In Some Cases Pin
Stephen F. Heffner19-Jul-10 20:23
Stephen F. Heffner19-Jul-10 20:23 
I strongly disagree. The examples you gave are silly; if I were the programming manager who saw those, I would have a serious talk with the coder about making comments meaningful, instead of just repeating what the code says. Some notes about the examples:

1. "i" is a horrible variable name except for very local, very limited use. The variable name should say what the variable does.

2. "int" was a bad idea in C/C++. You don't know from one day to the next what size it is.

3. We don't use native data types anyway; we typedef them all in a common header, to protect ourselves from compilers and platform shifts.

4. We break lines, with a "continuation" indent of 2, if they would otherwise protrude into the on-line tabbed comment area.

Here's what that code would look like in our shop:

Ulong bugcntr = 0; //init: no bugs seen yet
String tempValue = String.empty; //init: no temp value yet

// Save first and last names for use later, in a format we can easily
// detokenize:

tempValue = string.Format("{0} {1}",
firstName, lastName); //save names as temp

(Note: The comments are tabbed properly; somehow the blog display is messing them up.)

I have created, and currently maintain and enhance, a software product comprising over 1/2 million code lines of C, in over 2,700 modules and over 2,400 header files. It is all commented to the quality level shown above. Some of it is over 25 years old, but when I go back to it I spend NO time figuring it out. It is very complex and sophisticated code, yet I spend very little time debugging; the majority of my coding time is adding features. The heavy commenting in the code is what makes that possible.
GeneralRe: In Some Cases Pin
Kunal Chowdhury «IN»19-Jul-10 21:15
professionalKunal Chowdhury «IN»19-Jul-10 21:15 
GeneralCan can't say I actually do it... Pin
AlexCode19-Jul-10 3:40
professionalAlexCode19-Jul-10 3:40 
GeneralRe: Can can't say I actually do it... Pin
Deus ex Machina19-Jul-10 12:01
Deus ex Machina19-Jul-10 12:01 
JokeDoes anyone provide misleading and ambiguous comments Pin
Xiangyang Liu 刘向阳19-Jul-10 2:37
Xiangyang Liu 刘向阳19-Jul-10 2:37 
GeneralRe: Does anyone provide misleading and ambiguous comments Pin
W Balboos, GHB19-Jul-10 2:55
W Balboos, GHB19-Jul-10 2:55 
GeneralRe: Does anyone provide misleading and ambiguous comments Pin
Stephen F. Heffner19-Jul-10 12:23
Stephen F. Heffner19-Jul-10 12:23 
GeneralOnly 8 people not commenting their code at all Pin
peterchen19-Jul-10 2:07
peterchen19-Jul-10 2:07 
GeneralRe: Only 8 people not commenting their code at all Pin
Dalek Dave19-Jul-10 4:34
professionalDalek Dave19-Jul-10 4:34 
GeneralRe: Only 8 people not commenting their code at all Pin
Marc Clifton19-Jul-10 4:40
mvaMarc Clifton19-Jul-10 4:40 
GeneralInteresting options... Pin
Dalek Dave18-Jul-10 21:45
professionalDalek Dave18-Jul-10 21:45 
JokeRe: Interesting options... Pin
Johnny J.18-Jul-10 22:47
professionalJohnny J.18-Jul-10 22:47 
GeneralRe: Interesting options... Pin
Dalek Dave18-Jul-10 22:54
professionalDalek Dave18-Jul-10 22:54 
GeneralRe: Interesting options... Pin
The Man from U.N.C.L.E.18-Jul-10 22:55
The Man from U.N.C.L.E.18-Jul-10 22:55 
GeneralRe: Interesting options... Pin
Niklas L18-Jul-10 23:08
Niklas L18-Jul-10 23:08 
GeneralRe: Interesting options... Pin
codemunkeh19-Jul-10 13:30
codemunkeh19-Jul-10 13:30 
GeneralWhen client asked for it :) Pin
Noman Aftab18-Jul-10 21:25
Noman Aftab18-Jul-10 21:25 
GeneralVery good question this week Pin
Johnny J.18-Jul-10 20:29
professionalJohnny J.18-Jul-10 20:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.