|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic Page: 1 2 3 4 5 6 7 8 9 »» |
Last Thread Next Thread ![]() |
| do you comment? |
|
![]() Gaiiden GDNet Content Lead Member since: 8/30/2000 From: Lincroft, NJ, United States |
||||
|
|
||||
| Hello!! For those just joining in after reading the article I wrote, prepare yourself. This is a long thread and I doubt you'll want to read it all. However, I urge you to try and skim through everything. We had a really great argument going on here with CloneMaker battling against the rest of the world against commenting code. Spaced elswhere throughout the thread are some really great comments, arguments, and suggestions. Just recently I added an email response I got from a reader with a great suggestion. It's on page 7, have a look. I started this thread with the intent of seeing how many others commented like me, and not only did it take off, I learned a lot! Hope you do too. Below is the post that started it all... quote: ============================== "Need more eeeenput...." - #5, Short Curcuit ============================== Edited by - Gaiiden on 10/31/00 3:10:25 PM |
||||
|
||||
![]() Ironblayde Member since: 4/13/2000 From: Miyaron, Altea |
||||
|
|
||||
| Sounds like me... I used to not do any commenting at all, but I got irritated when the code for one too many of my programs went from painfully obvious to painfully crpytic after only a month of not looking at it. -Ironblayde Aeon Software |
||||
|
||||
![]() Gaiiden GDNet Content Lead Member since: 8/30/2000 From: Lincroft, NJ, United States |
||||
|
|
||||
| exactamundo! My own monitor is now safer as as result of commenting, tho my mouse and keyboard still take abuse. I wonder if there's anuyone out there who hates commenting for some arcane reason. Well? Anyone?? ============================== \\// live long and prosper; \||/ die short and rot. ============================== |
||||
|
||||
![]() MadKeithV Moderator Member since: 2/18/2000 From: Hasselt, Belgium |
||||
|
|
||||
| You do learn the hard way when doing lots of heavy coding. On the MXMCLIV'th iteration of debugging my mesh subdivision code, suddenly everything goes blurry. What does this code do? Why did I call that index xi? What's this variable tempTriPtr32? Since that happened ( about 24 times ), I've tried to comment WHILE I was programming, as opposed to my old style of "I'll do the comments when the code works". Comments are there for when the code DOESN'T work! That was a very important paradigm shift for me - the comments are no longer there for someone else to figure out how beautiful my code is, it's there for me when I'm trying to find out what kinds of stupid mistakes I've made typing that stuff out. Ps: my commenting style when sharing code with other people is like this:
That way, people know who wrote the message when looking at the code, so they know who to blame if it doesn't work right I also have a set of DevStudio macros that I use to layout my files( from Code on the Cob, right here on gamedev ), because it really helps when looking stuff up later. Give me one more medicated peaceful moment. ~ (V)^|) |<é!t|-| ~ ERROR: Your beta-version of Life1.0 has expired. Please upgrade to the full version. All important social functions will be disabled from now on. Edited by - MadKeithV on September 5, 2000 10:34:59 AM |
||||
|
||||
![]() Krylar Member since: 5/24/2000 From: Ashburn, USA |
||||
|
|
||||
| One thing that really bugs me is when I pay for a product that includes source code for customization, and it's not commented. I had to do a project recently that required code changes to a product purchased with source...took me 18 (literally) hours to do what should have taken 2 hours. Was VERY annoying and mushed my brain. So, yes, I comment my code because some day someone else is going to have to modify it...and that somebody may be me! -Krylar Christian Coders Network |
||||
|
||||
![]() justj Member since: 8/28/2000 From: Jawja, USA |
||||
|
|
||||
| At my job, I'm notorious for not commenting. I've never had a problem with my own code (IBM MVS Assembler), even after some years, but others are not too happy with it. I think the biggest reason is that I can think of code faster than I can type and I just hate to stop and comment. Working in C++, though, I comment the hell out of everything, mostly because I don't understand it that well myself and I sure can't code faster than I can type. I don't think C++ will ever lend itself as well to 'speed coding' as assembler does. "things are more like they are now than they ever have been" |
||||
|
||||
![]() furby100 Member since: 3/13/2000 From: London, United Kingdom |
||||
|
|
||||
| When I write code, I do not seem to need to comment it very frequently. This is due to my good interpreter brain, my very good memory for code, and the fact that I use very descriptive funtion and variable names. I usually only get a comment every five lines. ------------------------------ #pragma twice |
||||
|
||||
![]() Gaiiden GDNet Content Lead Member since: 8/30/2000 From: Lincroft, NJ, United States |
||||
|
|
||||
| Just remember, Furby, that if you ever have to give your code to someone else for some reason (a partner perhaps) you should make sure he can understand it without your help. Commenting is not only for you, but for other people. I would hate to give a sheet of code to a friend and have him calling me every five minutes saying "What does this function do?" I'd show you all my commenting style, but for two reasons: one, its too long an explanaition to bore you with, and two, it's my style, and I can't garuntee you'll like it. The only rule I use when commenting is not to let it interfere with the readability of the code itself. Its good if you comment every line meticulously (like me) but if you do it to the point were the code and comments start to intermix and jumble, well, you've just defeated the purpose!! ============================== \\// live long and prosper; \||/ die short and rot. ============================== |
||||
|
||||
![]() Peon Member since: 5/22/2000 From: San Jose, USA |
||||
|
|
||||
| I'm busy doing cout and pointers and stuff (*yawn!*) and I still comment... everything. I comment variable intialization, every function... pretty much everything. Maybe that's bad, I dunno. I just want to get in the good habit of commenting (even if it takes more time), cuz I know it'll be good for me later (like brushing your teeth, hehe |
||||
|
||||
![]() Moe Member since: 1/24/2000 From: Calgary, Canada |
||||
|
|
||||
| I guess I am a little like furby100 except that I like to comment, at least every 5 lines (unless filling out something like a RECT structure). I also like to use descriptive variable/function names. |
||||
|
||||
![]() MadKeithV Moderator Member since: 2/18/2000 From: Hasselt, Belgium |
||||
|
|
||||
| Commenting every five lines in C++ ? Wow, I tend to stick to one big comment per function and a few short comments where the code gets ugly. People reading it are programmers, and most of your code should be fairly self-explanatory. Give me one more medicated peaceful moment. ~ (V)^|) |<é!t|-| ~ ERROR: Your beta-version of Life1.0 has expired. Please upgrade to the full version. All important social functions will be disabled from now on. |
||||
|
||||
![]() alexmoura GDNet+ Member since: 11/14/1999 From: Redmond, WA, United States |
||||
|
|
||||
| Sometimes when things get confusing I actually comment the code before i write it I haven't still absorved the habit of commenting thoroughly, though You know, I never wanted to be a programmer... Alexandre Moura |
||||
|
||||
![]() Gaiiden GDNet Content Lead Member since: 8/30/2000 From: Lincroft, NJ, United States |
||||
|
|
||||
| Hey alexmora, that's a cool idea. Sometimes I like to write some psuedo-code first, comment it, then replace it with real code. And as for the only people reading it are programmers, not all the time. More often than not you'll get stuck with a boss that likes to stay on top of things, and he may not be a programmer. I've had to show my boss a few code samples so the documenting helps a lot cause then he can understand it and, of course, it gets me some suck-up points ============================== \\// live long and prosper; \||/ die short and rot. ============================== |
||||
|
||||
![]() rockslave Member since: 6/9/2000 From: Lins, Brazil |
||||
|
|
||||
| Everyone's gotta comment! It's good for understanding the algorithm, specially when your programming in groups. But the best is to make a "pseudo-code" like you said, or better, write the picture of the program working. But you don't need to comment that little test programs, though. Thanks, Arthur(rockslave) |
||||
|
||||
![]() isrking Member since: 7/6/2000 From: Alberta, Canada |
||||
|
|
||||
| Commenting is great and I try to comment functions and complicated sections of code as much as possible. I have had the misfortune of reading several programs where the commenting style was chaotic. If you don't organize you comments well it can make reading and understanding the code even more difficult. I find that a good practise to have is using variable and function names which are meaningful. By doing this you can avoid having to write too many comments. I don't know about anyone else, but I hate reading code where someone uses a variable x all over the place and you sit there wondering what x is supposed to mean. |
||||
|
||||
![]() Gaiiden GDNet Content Lead Member since: 8/30/2000 From: Lincroft, NJ, United States |
||||
|
|
||||
| well, rockslave, I don't comment the psuedo code as much as ther real code but I still do just to keep up the routine and to keep it from getting confusing, cause I make up my own functions and stuff. ============================== \\// live long and prosper; \||/ die short and rot. ============================== |
||||
|
||||
![]() felisandria Member since: 7/15/1999 From: Denver, CO, United States |
||||
|
|
||||
| Having been a firefighter on legacy code for a while, I find comments invaluable. Remember, someday even 5 years from now when you're possibly long gone, someone will have to figure out what the heck you were thinking. Comments as simple as "sorry, this is a kluge" can even be helpful. Personally, if something isn't painfully obvious, I comment. If something is "tricky", then I put a long comment before I go into it explaining what it does, and how to expand it (for instance, right now I have about 20 buttons on a dialog going through a single function which decides who sent it a message and processes it. If anyone ever tries to add another control to it, they're going to be more than a little confused, so I will put a comment block in in a minute here telling them how to do new buttons right.) A few things: Whitespace is gooooooood. It improves readability. Use it, darnit. Variable names that have some bearing on what they refer to are gooooood. "j" means nothing to me, unless it's obvious it's for a "for" loop right there. We have splendid machines with plenty of room for the extra letters for variable names. Use that space. If I find out any of you are doing incrementals in an "if" statement or the like, I will hurt you unless you have a darn good reason. That's so hard to find when you're trying to do a badly needed and time-crunched fix. ex: if (a > i++ && i < b++ && b++ < c) Too many comments is better than too few. -fel |
||||
|
||||
![]() braves Member since: 3/18/2000 From: USA |
||||
|
|
||||
| Do you know what commenting I really hate? x = 0 //sets x to zero while(x < 5) //beginning of loop { x++;//Increments x by 1 }//end of loop I can't stand this commenting.... Braves Edited by - braves on September 6, 2000 12:47:08 PM |
||||
|
||||
![]() Thrump Member since: 8/22/2000 From: Lunenburg, Canada |
||||
|
|
||||
| Never comment. It lessens your ability to read uncommented code... |
||||
|
||||
![]() Gorky Member since: 11/3/1999 From: Olathe, Kansas City, USA |
||||
|
|
||||
| Have fun with the comments if you can. Some of my co-workers don't appreciate humour in comments, but some do. I think it helps lighten the moode of the viewer. No: delete(b_ticketingMod) // Delete the ticketing mod item Yes: delete(b_ticketingMod) // Toast the puppy! Of course, only do this on lines that are fairly obvious. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
quote: I don't do it often but sometimes the temptation is just too strong // - We will need a search running. // - It has already begun. pfoo->RunSearch(); |
||||
|
||||
![]() BitBlt Member since: 3/4/2000 From: New York, NY, United States |
||||
|
|
||||
I know what you mean braves. Like where people go:#include or like you said:
if (x==0) // test if x is equal to zero
{
x=5; // make x equal to 5
} // end the "if x is equal to zero" statement
A little exaggeration but you get the idea. In game programming, I pretty much only comment the algorithms and functions that may be confusing. I don't comment Initialization and stuff. In regular programming, I find it helpful to comment the things felisandria was talking about. ------------------------------------"We are the music makers, and the dreamers of the dreams." - Willy Wonka |
||||
|
||||
![]() Rock2000 Member since: 9/3/1999 From: US, CT |
||||
|
|
||||
| Comments are mandatory. But they need to be smart comments. I prefer to comment what a block of code does (in english), and if need be why it works that way. Let the code speak for itself, unless you're like some of the guys I work with who use 90% magic numbers, no comments, and no design documents. Its a nightmare! But commenting is something that any good company requires, and any interviewer should ask about and look for in sample code. You have to get in the habit. I think they're very helpful even for single person projects, but any good company will trade off some development time for well documented code. It saves time in the end, without a doubt. Rock |
||||
|
||||
![]() Davaris Member since: 6/5/2000 From: Australia |
||||
|
|
||||
| I think commenting is a waste of time. You should learn to read code as you would English text. Many times code is modified and the coders are too busy or lazy to update the comments. I remember one lecturer at my old university would strip the comments out of code and tell us to figure out what it did. The lecturers name was Rob Pike. |
||||
|
||||
|
Page: 1 2 3 4 5 6 7 8 9 »» All times are ET (US) ![]() |
Last Thread Next Thread ![]() |
|