Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

View Poll Results: Do you comment your code?
All the time 17 29.31%
Sometimes 35 60.34%
Never 5 8.62%
Commenting? 1 1.72%
Voters: 58. You may not vote on this poll

Reply
 
Thread Tools Display Modes
Old May 20th, 2006, 2:48 AM   #1
msk420
Programmer
 
msk420's Avatar
 
Join Date: May 2006
Posts: 85
Rep Power: 3 msk420 is on a distinguished road
Commenting your code

Commenting your code takes so much time and space, but it is a good practice and makes it so you dont lose what your looking for. And it makes it eaier to read.
__________________
Code Forums
msk420 is offline   Reply With Quote
Old May 20th, 2006, 2:52 AM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
I comment as I see fit. If a function isn't easily described in its name, or has handling issues, I'll comment it. Same with sections of code. But that's about it.
Jimbo is offline   Reply With Quote
Old May 20th, 2006, 2:58 AM   #3
msk420
Programmer
 
msk420's Avatar
 
Join Date: May 2006
Posts: 85
Rep Power: 3 msk420 is on a distinguished road
Me too. I hate cluttering up my code with uneeded comments.
__________________
Code Forums
msk420 is offline   Reply With Quote
Old May 20th, 2006, 3:16 AM   #4
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 319
Rep Power: 4 andro is on a distinguished road
Send a message via AIM to andro
If it's just something quick that will never be used again, nobody will ever see, and never has a chance of being maintained, I won't comment.
andro is offline   Reply With Quote
Old May 20th, 2006, 4:00 AM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
I always comment (javadoc in Java, docstring in Python) every function I make. Whether I comment inside depends on the complexity.
Arevos is offline   Reply With Quote
Old May 20th, 2006, 4:45 AM   #6
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,261
Rep Power: 5 grumpy will become famous soon enough
I generally seek to write code in a manner that avoids unnecessary comments. For example, picking names of variables/functions/types well can mean the code itself is its own documentation; comments are then less necessary.

The only exception will be if it is necessary to keep an audit trail of modifications to a function: then comments will keep track of the history of changes to a function, who did it, when, why, etc.

There are also cases where things have to be done in non-obvious ways, so it is then a good idea to comment code. For example, working around compiler bugs, using hand-crafted code to tweak performance via bit fiddling rather than using mathematical operations, or doing things that are compiler specific. Even then, I will seek to avoid comments by putting such constructs into their own inlined functions so someone looking at the function can work out what it does from the name, even if they don't understand the obscure operations inside it.

I actually use more comments in code posted to forums like this than I would ever want to see in production code, because it is often more necessary to explain things that would be taken for granted in a professional environment.
grumpy is offline   Reply With Quote
Old May 20th, 2006, 5:07 AM   #7
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 343
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
every function has to have pre and post conditions stated, what its intent is and how it is called. all variables are labeled and explained. any step that is not simple needs some form of explanation as to be easily understood when reading the comments.

that is waht i have to do from some of my classes. it's a pain and does tend to cluter things up. but it sure helps you know whats going on in the code 6 months latter when you come back to it.
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old May 20th, 2006, 7:43 AM   #8
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
Quote:
Originally Posted by grumpy
I generally seek to write code in a manner that avoids unnecessary comments. For example, picking names of variables/functions/types well can mean the code itself is its own documentation; comments are then less necessary.
I do the exact same thing!
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old May 20th, 2006, 5:37 AM   #9
msk420
Programmer
 
msk420's Avatar
 
Join Date: May 2006
Posts: 85
Rep Power: 3 msk420 is on a distinguished road
True going back to un-commented code can be kinda hecktic...
__________________
Code Forums
msk420 is offline   Reply With Quote
Old May 20th, 2006, 7:17 AM   #10
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,198
Rep Power: 5 lectricpharaoh will become famous soon enough
My mindset is similar to grumpy's regarding comments. I like using names that are long enough to be clear, which, when coupled with a good coding style, act as implicit commenting. However, I do put a comment above the definition/declaration for each function, because even if the general purpose of the function is clear from its name, its exact semantics may not be. Notes to myself (for example, in a function that still needs tweaking) go here, too. Actual function bodies get few (if any) comments, unless they use code that is easy to misinterpret.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC