| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
shiro
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 1,657
|
Do you comment your code?
I suck at commenting my code. When I do it, which I usually don't, I do it as an afterthought, and I never know how much I actually should write. So I was talking with my buddy this past weekend who is running a programming agency back home in Canada. I asked how he feels about staff not commenting code, and he said he thinks commenting is a waste of time. "It's like writing a book, then writing a play-by-play in the margins". Now that works for me, because I'm not so great about doing it. But are other bosses ok with not commenting? Do you guys do it? And if you do, do you do it because you like to, or because you are made to? |
|
|
|
|
|
#2 (permalink) |
|
Semantics, yay.
Join Date: Nov 2005
Location: Salem, Massachusetts
Posts: 1,077
|
I comment all websites that aren't mine (because nobody else will ever work on *my* websites) and I comment them at the end of every major layout </div>, sometimes an 'updated xx/xx/200x' at the top of the file, and all JavaScript/PHP/.Net files practically get documentation at every step in the file (or at least the non-obvious steps). Commenting is good because someday, somebody else will open that file and scratch their head. |
|
|
|
#3 (permalink) |
|
goober :-)
|
Agreed. I comment at the beginning and end of all majr layout sections, and in other places where needed. I work a lot with jsp pages, where there is jstl login in place within the file, so often I comment those sections to explainthe logic as well. All of this is largely because I work frequently in a team on one project, so there is a good chance that someone else may have to do something with my work. I also like to comment javascript fairly thoroughly for the same reason (and to remind myself of what I was doing in the future!)... It just seems to make sense to me to provide a plain english explanation of what is going on in a script for the uninitiated. David My signature sucks.
|
|
|
|
#4 (permalink) |
|
On yer bike...
Join Date: Feb 2005
Posts: 4,951
|
I only comment closing structural elements e.g. </div> <!-- end content --> ... </div> <!-- end navigation --> an I'm totally pedantic about stylesheets - I crack the whip here about well laid out CSS - makes it much easier to edit if it's well presented - especially if it's someone elses work. That book analogy is terrible. Sack him. |
|
|
|
#5 (permalink) |
|
rock n' roller
|
I comment commonly in php and js. Html not so. I comment even if it's my project. I like commenting PHP Code:
|
|
|
|
#6 (permalink) |
|
i'm done, son
Join Date: Jan 2005
Posts: 12,262
|
I don't comment HTML at all. It's so structural that it's pointless. Though Limbo's comments are useful. Programming, in some cases, I comment the hell out of it in other cases I don't comment at all. If it's something only I'm editing and using, I do only "reminder" comments to myself. However, I've got a small set of JavaScript scripts together for our subsidiary companies that is insanely commented (there's also a production version of each without comments): Code:
|
|
|
|
#9 (permalink) |
|
On yer bike...
Join Date: Feb 2005
Posts: 4,951
|
CSS Sample - commented throughout. Code:
Examplified. |
|
|
|
#10 (permalink) |
|
Biscuit
Join Date: Jun 2006
Location: Ireland
Posts: 863
|
I remember having a divilicious layout once and commenting on it because there were so many of them. caused some weird side effects ( i opted for overuse of whitespace). I never comment on code, css html or php. I don't work with a team so nobodys ever going to use my code apart from me.............and if they try....God help them!! mwhahahahahaha "Get out of my face!"
"NO! I'll get in your FACE!" |
|
|
|
#11 (permalink) |
|
gotsa a malanga!
Join Date: Apr 2006
Location: ottawa, canada
Posts: 480
|
basically, if you do very simple stuff, then its probably not needed. very silly to say comments aren't needed though. i generally do the same as limbo and comment which div closes which div so i can 'see' the layout better. for php i definitely comment what certain functions do. |
|
|
|
#12 (permalink) |
|
inventer of the left-hand
Join Date: Aug 2006
Location: Leeds / Lincoln
Posts: 1,298
|
I don't code but when I'm writing mark-up like HTML or CSS I only comment on bigger projects and I have loads of elements flying all over I might consider commenting the CSS. If I coded with PHP etc. I think I'd have to because it's totally lost on me right now. |
|
|
|
#13 (permalink) |
|
Registered User
Join Date: Mar 2006
Location: Colleyville, Tx
Posts: 48
|
I tend to try to use "self commenting code" or [link=http://en.wikipedia.org/wiki/Hungarian_notation]hungarian notation[/link] whenever possible, this cuts down on commenting but adds to the readability of the code... i also try to not use cryptic variable names such as $a or whatever. and whenever i do some complicated logic, i try to explain it in a comment for either myself in the future or a possible colleague that may be working with the file |
|
|
|
#14 (permalink) | |
|
shiro
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 1,657
|
Quote:
He's the boss! I think the problem (not for him though) is that the guy is pretty much a genius when it comes to code, and he can read through code and see whats going on without the comments, so he doesn't see the worth in them. For everyone who comments, do your bosses require it as well? |
|
|
|
|
#15 (permalink) | |
|
Registered User
Join Date: Mar 2006
Location: Colleyville, Tx
Posts: 48
|
Quote:
more like writing a book and then writing the cliff notes for it... what would you rather do, read the book, or the cliff notes? |
|
|
|
|
#16 (permalink) |
|
Web Developer
Join Date: Oct 2006
Posts: 1,984
|
I don't comment XHTML or CSS (well, apart from to add my contact details) but I do try to comment as much of the server side programming that I can (PHP/ASP.NET). 9 times out of 10 it will just be me working on something on my own, but in the past I have worked on something, then someone else is asked to do some work on it afterwards, and I have been contacted by them. Though commenting is good, writing neat and clear code is better. It would be worse to comment a load of messy shit than to not comment something that is easily followed. Most books I have read try to get this message across. This is a good guide: phpBB3 • Coding Guidelines |
|
|
|
#17 (permalink) | |
|
On yer bike...
Join Date: Feb 2005
Posts: 4,951
|
Quote:
Most coders can do that on projects THEY have developed - but for team environments commenting is useful - especially when maintenance might be carried out on a site developed by another. That, said Good code will always be be good code. regardless of comments. Simply spacing elements within the page can work equally well. Tab - double tab - double return - treble return etc... |
|
|
|
|
#18 (permalink) |
|
dt immigrant
|
I only comment bits in the css that I feel might pose problems. I did use extensive comments on a couple of large projects, but it's extremely time consuming. I am also working on poorly written code with no comments. That is indeed a nightmare. Nice avatar Limbo. |
|
|
|
#19 (permalink) |
|
blam blam
Join Date: Aug 2006
Location: ann arbor, mi usa
Posts: 525
|
even if it's your code, maintaining or updating a project you haven't had to touch in a long while can be made much easier with comments. i'm talking about actual code, not mark-up. how many of you have looked at code you wrote 6+ months ago and said "what the hell was i trying to do here?!" i have. especially since my coding style, structure, flow, and methodology is constantly evolving. I often don't even recognize code that is more than a year old. so comments are good if you work solo, and essential if you work collaboratively. |
|
![]() |