Advertisement

An objective analysis of comments: Are they necessary?

Started by November 03, 2000 09:53 PM
83 comments, last by The1Blade 24 years, 2 months ago
quote:
Original post by LilBudyWizer
Code first, documentation second and comments third is my priorities.



Documentation can be generated two ways - one is during the design process, and the other is after the code has been written.

In the first case, a large chunk of documentation will already exist before the first line of code, and it might make understanding the code a lot easier.

For the second case, it''s better to write comments as you are writing GOOD code. Not the obvious comments, but the ones that will help you write good documentation when you''ve finished that code.

But in general, I agree with the order of importance you''ve given there.
Documentation comes first when trying to understand code. But you need the code first, if you want to understand it. If documentation doesn''t cut it, you can start browsing through the comments and the code to figure it out yourself.




People might not remember what you said, or what you did, but they will always remember how you made them feel.
~ (V)^|) |<é!t|-| ~
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
If you are just going to call other people''s code and use it as a black box, then of course documentation outweighs comments. If you actually try to maintain their code and figure how it works, then comments would outweigh documentation.

As for the PS2, it is mainly MIPS based, with a few twists thrown in, like parallel processing of two instructions at the same time. Optimized PS2 code can be a bitch to understand even with comments, and documentation alone will not save you, this was dave''s point I believe. If there are no comments telling you what each register does (as in all MIPS based languages), there is no easier way to figure how it works than guess and check.

Mike
"Unintentional death of one civilian by the US is a tragedy; intentional slaughter of a million by Saddam - a statistic." - Unknown
Advertisement
LilBudyWizer, do you understand the difference between documentation and comments? Documentation is great for people to USE your functions/classes/library, but comments are for people who will actually be modifying/fixing your code. These are two huge differences and one does not replace the other.

quote:

Bosses DON''T LIKE to hear complaints too. They will get annoyed at your co-workers.



The1Blade, how many companies have you worked for where this was true? I have yet to work for a boss like this. And I DID work for a boss like this, I would look for another job because if he/she doesn''t care about his/her employees then you are in trouble.


What most of you are forgetting is that commenting should explain the code''s intent, and sometimes why, not summarize the code. Have you people ever worked for a company who has a huge application they want you to make an addition to, which you''ve never even looked at? If you think comments aren''t extremely helpful at that point then you''re crazy. I mean, you can look at a line of code and understand it, but you don''t know what the application as a whole is doing. Anyone can look at a line and say, "Yep, they are shifting the bits in this integer 3 to the left, but that doesn''t tell them what that section of code is supposed to do. I mean, what if this section of code has a bug in it? How are you supposed to know what the code was SUPPOSED to do without comments are an intimate knowledge of the program?
Vetinari,

That isn''t true in the generic case of maintainance. Within the specific case of a small system you might get by with that. When you are dealing with 5,000 programs it is a differant story. Admittedly at that point program documentation is low on the totem pole relative to system and sub-system documentation, but it is still more important than the comments in the code. You have to think in terms of maintaining 2 million lines of code. You may think you are going to understand that by reading the comments in the code and you may, but you are not going to in a reasonable length of time. You have a far better chance of understand what 5,000 programs do in an abstract sense, but that is really beyond human capability as well. You have to group it in groups of between 5 and 10 and then people can understand these are the major sub-systems and remember that. They can then even remember five or ten sub-systems each of those sub-systems is broken down into. Rather than taking years to get that understanding and it being locked in your head you document it.

Just as it may help you to understand a small run of code to have a line there giving an abstract the documentation does the same thing for the entire program. This is the the initialization, this is the main processing and this is the termination. During initialization it loads these files, allocates these resources and performs these verifications. Within a complex program that could be several hundred lines if not thousands. Some applications have hundreds of classes with inheritance ten levels deep. What are you going to do? Put a block comment several hundred lines long in showing the heirarchy? Or are you going to force them to muddle through several hundred class definitions. Even with a class browser you need some guide and the source is not the appropriate place for that. Perhaps in a simple system you can get by with just comments just as I can get by without comments, but that doesn''t make it a good practice.

That is one thing I agree with Daveb about. Commenting is a good practice. That I can get by without it doesn''t mean it shouldn''t be done. That you can get by without program documentation doesn''t mean you shouldn''t be doing it. If you have done it plenty of times before and it would only be for your own benefit then certainly there isn''t much point to it if you are not going to use it. If you have never done it then there is a benefit just as there is for a beginning programmer to comment. Not that beginning programmers are the only ones that benefit from comments, but rather they are pretty much the only ones that benefit from the process of commenting. It helps them reason out what they are doing to explain it in english. Program documentation does the same thing at a higher level. Working at a systems level means thinking of the program in the abstract. If you want to do something like STL, MFC, OWL or VCL then it is essential that you not bog down in the details. If you want to write something like Windows or DirectX it is also essential.

Even in a small program with just 30 source files I feel the same way about the lack of a document explaining those 30 source files at a high level as you do about it not being commented. Much of what people have argued here is actually the arguement for program documentation, not comments. I''ve never had a problem with anyone not commenting. Not because I don''t care if they do because on the job I do. Rather because everyone does it. What far too many people don''t do is all the rest of the good programming practices and extremely few write program documentation. If someone wants to now how to present their demo more professionally to a potential publisher or employer then I''m going to tell them to have polished and well written documentation. Certainly I am assuming they have it commented just as I''m assuming their program works and works well. That would be my recommendation because it is what they most likely did not do and the next guy they are competing with didn''t do either.

Daveb,

Just out of curiosity, just how much documentation was used to land a deal with a publisher? Can you get by with just sending them a well commented program and saying look I have a cool program? Would you even send the source to them without a contract? How much documentation is required at a milestone and how much in the form of status updates between milestones? Can you get the milestone payment by just showing the source and saying look we made it? I think you get the general idea. No need to answer every individual question, but I think it would be helpful to me and many others to have some idea what the documentation requirements imposed by publishers are.
Keys to success: Ability, ambition and opportunity.
I've never heard of a case where publishers actually look at code or any other project data files. Typically, the publisher owns the rights to a name/title, but not to the code or data associated with it - that's the developer's domain.

Milestones are delivered on content only. You lay them out at the beginning of the project, and hit them along the way. You land the initial deal with the publisher with a gameplay prototype.

Most publishers don't even have technical people on staff, unless they're also developers, and in that case, they're concerned about their own projects.

I've never worked with a producer who could make heads or tails of a line of code Game development by nature is a pretty "flexible" process. Milestones are more concerned with making sure you're on the right track and have the contractual content.

Edited by - daveb on November 6, 2000 9:55:53 PM
Volition, Inc.
While I think this discussion is good, it doesn''t belong in the Graphics forum. So I''m moving it to the General Programming area.

Kevin

Admin for GameDev.net.

Advertisement
quote:
As for the whole "rewrite the module" argument - that''s completely stupid. What if the module is 15,000 lines of code and you have 2 days to fix a series of bugs. No way.



If you modularized correctly, your modules are divided into modules. There are no 1500 line long individual functions.

quote:
a.) You think that you''re so good you have no need to comment. When you get into the professional world you''re going to find that pretty much everyone is as smart or smarter than you. And they comment. You lose.



Where did I imply that I thought I was too good to comment? I simply stated that it was unnecessary.

quote:
b.) You think there''s no need to comment stuff because you can always re-write it. Real world time constraints make this a complete fallacy.



If there are major errors in a module, you''ll rewrite it anyway. If there are small ones, you can catch them without comments.

quote:
This is ludicrous, and you''re making yourself sound very dumb. In the "real" world, if you''re checking in code that doesn''t even compile because it has syntax errors you''d be fired in a week. The _vast_ majority of bugs in code are no syntax errors.



You''re saying typos are less common than large logical algorithmical errors?

quote:
Proper commenting allows another competent programmer to go in and fix someone else''s code. If you''re 3 days away from a drop-dead ship date, you can''t just go in and re-write major portions of code. And if you have to fix some serious bugs in a major module with no commenting, you may as well be doing surgery with a chainsaw. There''s a super-high chance that all you''ll do is introduce more bugs and further screw your release.



Like I said, if it is modularized correctly, then you can rewrite small modules that have major errors in them.

quote:


Let''s see, most code I work with has one line of comments per ten lines of code, and mabye one per three if it is extremly complex. I would like to know how you came to the conclusion that this happens ''often''.
Of course I put more weight into good variable/function names, but many times that alone is not sufficient and the code needs more.


If you comment this little, you still would need whoever is reading your code to decipher the code often. Most of the time if you do this, the person can either understand that one isolated relatively complex line, or find it out for himself because it is isolated.

quote:


You would be hard pressed to find many here that agree that the nuumber of charecters in comments is greater than thta of code. And if this happens, you may be over commenting. Of course if people write comments like ''want to right in a certian loop'', the reader will get confused.


The ratio of commented to non-commented lines is already being discussed in the previous point. But do you agree that in a single commented line the comments take up more characters than the code?

quote:


Are you on drugs? Exactly what part of what I said do you disagree with? I rarely get syntaxical errors, and generally finding bugs takes incredibly longer than writting the original code. Most large products go through multiple month long debugging processes, where new features are not added. I wonder why they don''t go through month long syntaxical fixing periods?


You''re saying you rarely make typos? Your paragraph prior to my quote had two typos. Out of about 50 characters or so. Surely you can see that you''re going to make typos in code and you''re going to get a fairly decent amount of syntaxical errors. True they don''t take long but most errors are ones like that.

If you modularize correctly, you can debug each separate function at a time. Making the debugging state not that long. The reason debugging states are long is because of general design errors. These can''t be fixed by comments.

quote:
It''s pretty obvious you have no real world experiance. When you get some, come back and we can discuss this further.



I consider your skeptancy on my years of experience in this market an insult. I haven''t personally insulted you, so please, have a professional attitude toward this thread.

quote:
Um, an *objective* view is not what you presented here. An objective view is when you argue for both sides. Your view is strictly subjective.

I did examine both sides. This is irrelevant though.

quote:
Also, you only argued that co-workers should know and it wont help yourself. However, no one reads code as good as English, besides the claims. Its impossible, because I can read badly formatted and to a certain extent misspelled English, but I severly doubt anyone can do the same with code. Pick any random .c file at www.ioccc.org and if you can read it like English, you deserve a quick slap in the face, for lying.



True, but in reality, comments are not english(obviously they are in literal terms, but you know what I mean) because when you read a comment, you formulate pseudocode for this. Then from this pseudocode you examine the code itself and determine its final meaning. This is the same length of time if you read code. You try to picture it the code in more increasing coherent general forms of pseudocode until you understand exactly what it means.

quote:
then you are right, comments are useless. But, as I said, comments are not there to state the obvious. They are there because of so many possible pecualuralities in any given peice of code, it becomes hard to maintain.



If there is one isolated complex line, then you can figure it out because it doesn''t pertain as much to the previous code, or the previous code is obvious enough that you can fit it in the scheme. If it is integrated into the code enough that it is dependant on the rest of the code, you need to comment that code also.

quote:
Heh. I''d wager this guy doesn''t have 20 years of experience. In fact, my rough estimate would be about, oh, zero.

Do not personally insult me. Let''s have a professional attitude in this thread, ok? I have in fact more than 20 years of experience.

quote:
Any supposedly "experienced" programmer who is arguing against the value of comments in his code is equivalent to a experienced soldier who is arguing against the value of bullets in his gun.



Your analogy is wrong. The bullets would symbolize code. Comments would symbolize the detailed instruction manual on how to load and utilize the bullets. The professional soldier doesn''t need to know this.

quote:
Eh, this argumnent is inane. If you''re an "undecided" programmer reading this, take it to heart - you''ll never make it as a professional programmer if you don''t believe in comments.




I would prefer if you would stop generalizing so much.

quote:
If I write out a highly complex texture alteration algorithm, no matter how nicely done it may be, I STILL have to put comments in there, because it is a complex part of code, which requires understanding as to WHY I copy this pixel here and that pixel there.



The question "why" would refer to the general outline of the program. Obviously the pixel is important to the rest of what you put on to the screen, not just the individual pixel. It would be impossible to write comments that integrate each small part like this. Separate documentation is more efficient for this.

quote:
I type relatively fast (never really timed myself). I can think any thought out in English and type it out just as fast as I can think that. I could write 500 lines of comments in a few minutes without ever really stopping to think what I was writing (provided I do know what I am writing about to begin with).



So you write 500 lines of comments straight? No! Before you write a commented line of code, you formulate what you are going to do. The formulating involves both the englishized general pseudocode and the code itself in the same amount of time. You type out the line itself without really thinking about it, hence the comments get typed a little slower because of more characters.

quote:
//-------------------------------------// HRESULT DoSomeThing()// This function does some stuff//-------------------------------------HRESULT DoSomeThing(PARAMETERS param){<...>if(FAILED(hr = DoSomething(somevalue)))return hr; // recurse through if nothing goes wrong.}

First of all, the format of that comment up top takes time. You don''t need to know the return value because it already says. And you should be able to have descriptive enough function names for someone to figure out what they do.
The recurse through part is obvious and does not need to be commented. Most people can understand if statements and can point out recursion quickly.

quote:
I work for Volition. I shipped Freespace (Conflict:Freespace for those of you overseas ), was lead programmer and lead designer on Freespace 2, as well as Silent Threat, the expansion pack for Freespace. I was one of the two main PSX2 guys on Summoner, a PSX2 launch title which shipped several weeks ago.

Feel free to email me, its in my profile.

And I''ll repeat it again - if you''re saying you don''t use comments, and even go as far as to remove comments from code before working on it, you''ve got to be nuts. I''d really like to know what software house _you_ work for which allows this kind of policy.


I must say you''re quite arrogant. George W. won the election, he has(or will have) experience, does that mean his policies are right?

quote:
- does it return the combat value or is that an error/success code? Is it 0 on fail, or < 0? Or nonzero?



You can figure that out from the code.

quote:
- what exactly is the combat value? how is it generated? What is float *val? Is that where the return value comes from? Or is it an input array of numbers? Or a temporary?



The combat value is also easily figured out from the code. And val is a bad variable name. That''s the only reason we can''t tell what it is.

quote:
- no "smart" naming convention in the world is going to be able to undo the need to comment the 20 struct members and complicated functionality of generate_combat_value().



Not if each member has a descriptive name.

quote:
A single line of comments would answer all these questions. I simply cannot see how you can produce release-quality code without them. How can you _possibly_ advocate writing code that causes others to _guess_ at how it works? That''s a surefire way to screw your whole project. For this reason alone, I cannot accept the fact that you''ve got the experience you say you do.



They don''t need to guess. If you modularize correctly, each separate small algorithm is divided well enough that you can figure out what it does.

quote:
You''re working on a small program, say seven source files named "Graphics", "Levels", "Main", etc. Your "Graphics" source file is a few hundred lines long, with around 30 functions, that are pretty much as modularized as is reasonable to make them. It handles loading graphics from a file, drawing them, and the main render loop. You know you have a bug in the file loader, but where is it? It''s much easier to skim the file for a nice, large header-like comment (which sticks out big-time) than to read each function name trying to find a certain function. These take very little time to make, and almost never change, even if the code is edited by other people.



The function names should be descriptive enough to aid you enough as comments do in your query.

quote:
Secondly: I don''t know about anyone else, but if I''m trying to debug a program, I want to be able to read WHY it''s doing whatever (and if I''m understanding properly, this is what that "documentation" would tell you, but if I''m styaring at the code anyway, I don''t want to keep glancing between my screen and some book, I want to be able to read the comments right beside the code.



If you understand the general purpose of each section of code, then you don''t need comments to examine each section and figure out what it does.

quote:
Bud - the examples I gave were just that - examples. I was hoping you''d fill in the blanks and understand what I was trying to say. Even if you had a well-named 20 member struct, what would you give the function for a name?

int generate_a_combat_value_by_taking_members_four_five_and_six_dividing_by_the_number_of_oh_wait_this_is_retarded();

Congrats on zinging me by "assuming" I write that kind of code though! Score : you!


The documentation is sufficient to understand what each function does related to the general larger module.

quote:
A friend of mine used to work at a phone company where they maintained a 50 million line telephone switch codebase. There were people there who spent their entire lives maintaining that piece of code. You''re telling me you expect a new guy to read the documentation on 50 million lines of code and be able to go in and fix uncommented code on a system which runs hundreds of millions of phone lines? No.



The documentation should be sufficiently divided that you can find what a function does.

quote:
But perhaps there''s a blurring here between what you''re calling "documentation" and what I''m calling "comments". Certainly, textual descriptions at the top of a module fall into both categories and can go along way towards revealing the philosophy behind the module. However, I _guarantee_ you I can write you a math-intensive function (for example) that fits perfectly into a well documented module, and it would take you a day to understand what was wrong with the function, _unless_ I put comments in the code. I''m sure your managers would love to see productivity soar like that.



First of all, why would you care if we understand it?
Second of all, if it is math intensive, you are going to spend the same amount of time understand the code alone compared to the comments and the code. Code you turn into more general and general pseudocode. Comments you turn into more specific and specific pseudocode until you get to the actual code.

quote:
I will certainly admit that software engineering, as practiced by the game development industry is far from perfect. There''s no doubt we tend to shoot from the hip in terms of the process of programming. Of course there''s no way we run a ship nearly as tight as your average consulting firm or large software house. Scale does matter. However, I still maintain that generalizing and saying "comments are unneccessary" and that you''d be just as well off by looking at the code and effectively guessing at what it does, is bogus. I would certainly hope large software houses don''t want programmers guessing what individual functions and/or lines of code are doing. If your documentation is so completely thorough that it explains everything, well, then you''ve just got comments in a less useful place. Documentation != comments.



Individual lines should be comprehendible enough to mix with the general surrounding lines, figuring out in general what it does in pseudocode. The documentation generalizes it saying why everything does what it does.


So many posts, this is tiring...

quote:
I think I see your point. If the only documentation you have is in the comments in the code would I read them? Oh yes. If I''m calling some function in a dll that takes a parameter that is bit flags, there are no defines and the only documentation for what values are valid is in the comments then I''m going to read the comments. If the only explaination for the sequence functions have to be called in is comments in the header am I going to read it? Certainly I am. My only other choice is making wild guesses, trying every possible combination and permutation or disassembling it. I don''t consider those to be comments though. It is documentation buried in the code.

Like I said before, most short functions are easily comprehendible, and even if they''re not, comments won''t help.

quote:
If your coworkers want comments then that alone makes it important if nothing else does.

Why?

quote:
For the second case, it''s better to write comments as you are writing GOOD code. Not the obvious comments, but the ones that will help you write good documentation when you''ve finished that code.



Why?

quote:
If you are just going to call other people''s code and use it as a black box, then of course documentation outweighs comments. If you actually try to maintain their code and figure how it works, then comments would outweigh documentation.

If it''s modularized correctly, you can figure out what each small part does as easily as with comments.

quote:
The1Blade, how many companies have you worked for where this was true? I have yet to work for a boss like this. And I DID work for a boss like this, I would look for another job because if he/she doesn''t care about his/her employees then you are in trouble.



In general, more bosses would not prefer getting complaints about the teamwork in the group. Not because of the validity of the claim, but because loss of teamwork will mean loss of production for a while. They get angry at the first person that informs him of such a situation, its natural.

quote:

What most of you are forgetting is that commenting should explain the code''s intent, and sometimes why, not summarize the code. Have you people ever worked for a company who has a huge application they want you to make an addition to, which you''ve never even looked at? If you think comments aren''t extremely helpful at that point then you''re crazy. I mean, you can look at a line of code and understand it, but you don''t know what the application as a whole is doing. Anyone can look at a line and say, "Yep, they are shifting the bits in this integer 3 to the left, but that doesn''t tell them what that section of code is supposed to do. I mean, what if this section of code has a bug in it? How are you supposed to know what the code was SUPPOSED to do without comments are an intimate knowledge of the program?




First of all, the comments themselves could be saying goals that you don''t really want in this line of code, so you can''t always base whether a line is good or not because of the intentions expressed in the comments.
2nd of all, the general role of a large module is better explained in documentation.
3rd of all, if you understand the previous lines, you''ll understand the result of a certain operation. From the code in the future you can find that the operation is not doing something properly.

quote:
That is one thing I agree with Daveb about. Commenting is a good practice. That I can get by without it doesn''t mean it shouldn''t be done. That you can get by without program documentation doesn''t mean you shouldn''t be doing it. If you have done it plenty of times before and it would only be for your own benefit then certainly there isn''t much point to it if you are not going to use it. If you have never done it then there is a benefit just as there is for a beginning programmer to comment. Not that beginning programmers are the only ones that benefit from comments, but rather they are pretty much the only ones that benefit from the process of commenting. It helps them reason out what they are doing to explain it in english. Program documentation does the same thing at a higher level. Working at a systems level means thinking of the program in the abstract. If you want to do something like STL, MFC, OWL or VCL then it is essential that you not bog down in the details. If you want to write something like Windows or DirectX it is also essential.



You haven''t explained why you should comment if you can get by without it.
quote:
As for the whole "rewrite the module" argument - that''s completely stupid. What if the module is 15,000 lines of code and you have 2 days to fix a series of bugs. No way.



If you modularized correctly, your modules are divided into modules. There are no 1500 line long individual functions.

quote:
a.) You think that you''re so good you have no need to comment. When you get into the professional world you''re going to find that pretty much everyone is as smart or smarter than you. And they comment. You lose.



Where did I imply that I thought I was too good to comment? I simply stated that it was unnecessary.

quote:
b.) You think there''s no need to comment stuff because you can always re-write it. Real world time constraints make this a complete fallacy.



If there are major errors in a module, you''ll rewrite it anyway. If there are small ones, you can catch them without comments.

quote:
This is ludicrous, and you''re making yourself sound very dumb. In the "real" world, if you''re checking in code that doesn''t even compile because it has syntax errors you''d be fired in a week. The _vast_ majority of bugs in code are no syntax errors.



You''re saying typos are less common than large logical algorithmical errors?

quote:
Proper commenting allows another competent programmer to go in and fix someone else''s code. If you''re 3 days away from a drop-dead ship date, you can''t just go in and re-write major portions of code. And if you have to fix some serious bugs in a major module with no commenting, you may as well be doing surgery with a chainsaw. There''s a super-high chance that all you''ll do is introduce more bugs and further screw your release.



Like I said, if it is modularized correctly, then you can rewrite small modules that have major errors in them.

quote:


Let''s see, most code I work with has one line of comments per ten lines of code, and mabye one per three if it is extremly complex. I would like to know how you came to the conclusion that this happens ''often''.
Of course I put more weight into good variable/function names, but many times that alone is not sufficient and the code needs more.


If you comment this little, you still would need whoever is reading your code to decipher the code often. Most of the time if you do this, the person can either understand that one isolated relatively complex line, or find it out for himself because it is isolated.

quote:


You would be hard pressed to find many here that agree that the nuumber of charecters in comments is greater than thta of code. And if this happens, you may be over commenting. Of course if people write comments like ''want to right in a certian loop'', the reader will get confused.


The ratio of commented to non-commented lines is already being discussed in the previous point. But do you agree that in a single commented line the comments take up more characters than the code?

quote:


Are you on drugs? Exactly what part of what I said do you disagree with? I rarely get syntaxical errors, and generally finding bugs takes incredibly longer than writting the original code. Most large products go through multiple month long debugging processes, where new features are not added. I wonder why they don''t go through month long syntaxical fixing periods?


You''re saying you rarely make typos? Your paragraph prior to my quote had two typos. Out of about 50 characters or so. Surely you can see that you''re going to make typos in code and you''re going to get a fairly decent amount of syntaxical errors. True they don''t take long but most errors are ones like that.

If you modularize correctly, you can debug each separate function at a time. Making the debugging state not that long. The reason debugging states are long is because of general design errors. These can''t be fixed by comments.

quote:
It''s pretty obvious you have no real world experiance. When you get some, come back and we can discuss this further.



I consider your skeptancy on my years of experience in this market an insult. I haven''t personally insulted you, so please, have a professional attitude toward this thread.

quote:
Um, an *objective* view is not what you presented here. An objective view is when you argue for both sides. Your view is strictly subjective.

I did examine both sides. This is irrelevant though.

quote:
Also, you only argued that co-workers should know and it wont help yourself. However, no one reads code as good as English, besides the claims. Its impossible, because I can read badly formatted and to a certain extent misspelled English, but I severly doubt anyone can do the same with code. Pick any random .c file at www.ioccc.org and if you can read it like English, you deserve a quick slap in the face, for lying.



True, but in reality, comments are not english(obviously they are in literal terms, but you know what I mean) because when you read a comment, you formulate pseudocode for this. Then from this pseudocode you examine the code itself and determine its final meaning. This is the same length of time if you read code. You try to picture it the code in more increasing coherent general forms of pseudocode until you understand exactly what it means.

quote:
then you are right, comments are useless. But, as I said, comments are not there to state the obvious. They are there because of so many possible pecualuralities in any given peice of code, it becomes hard to maintain.



If there is one isolated complex line, then you can figure it out because it doesn''t pertain as much to the previous code, or the previous code is obvious enough that you can fit it in the scheme. If it is integrated into the code enough that it is dependant on the rest of the code, you need to comment that code also.

quote:
Heh. I''d wager this guy doesn''t have 20 years of experience. In fact, my rough estimate would be about, oh, zero.

Do not personally insult me. Let''s have a professional attitude in this thread, ok? I have in fact more than 20 years of experience.

quote:
Any supposedly "experienced" programmer who is arguing against the value of comments in his code is equivalent to a experienced soldier who is arguing against the value of bullets in his gun.



Your analogy is wrong. The bullets would symbolize code. Comments would symbolize the detailed instruction manual on how to load and utilize the bullets. The professional soldier doesn''t need to know this.

quote:
Eh, this argumnent is inane. If you''re an "undecided" programmer reading this, take it to heart - you''ll never make it as a professional programmer if you don''t believe in comments.




I would prefer if you would stop generalizing so much.

quote:
If I write out a highly complex texture alteration algorithm, no matter how nicely done it may be, I STILL have to put comments in there, because it is a complex part of code, which requires understanding as to WHY I copy this pixel here and that pixel there.



The question "why" would refer to the general outline of the program. Obviously the pixel is important to the rest of what you put on to the screen, not just the individual pixel. It would be impossible to write comments that integrate each small part like this. Separate documentation is more efficient for this.

quote:
I type relatively fast (never really timed myself). I can think any thought out in English and type it out just as fast as I can think that. I could write 500 lines of comments in a few minutes without ever really stopping to think what I was writing (provided I do know what I am writing about to begin with).



So you write 500 lines of comments straight? No! Before you write a commented line of code, you formulate what you are going to do. The formulating involves both the englishized general pseudocode and the code itself in the same amount of time. You type out the line itself without really thinking about it, hence the comments get typed a little slower because of more characters.

quote:
//-------------------------------------// HRESULT DoSomeThing()// This function does some stuff//-------------------------------------HRESULT DoSomeThing(PARAMETERS param){<...>if(FAILED(hr = DoSomething(somevalue)))return hr; // recurse through if nothing goes wrong.}

First of all, the format of that comment up top takes time. You don''t need to know the return value because it already says. And you should be able to have descriptive enough function names for someone to figure out what they do.
The recurse through part is obvious and does not need to be commented. Most people can understand if statements and can point out recursion quickly.

quote:
I work for Volition. I shipped Freespace (Conflict:Freespace for those of you overseas ), was lead programmer and lead designer on Freespace 2, as well as Silent Threat, the expansion pack for Freespace. I was one of the two main PSX2 guys on Summoner, a PSX2 launch title which shipped several weeks ago.

Feel free to email me, its in my profile.

And I''ll repeat it again - if you''re saying you don''t use comments, and even go as far as to remove comments from code before working on it, you''ve got to be nuts. I''d really like to know what software house _you_ work for which allows this kind of policy.


I must say you''re quite arrogant. George W. won the election, he has(or will have) experience, does that mean his policies are right?

quote:
- does it return the combat value or is that an error/success code? Is it 0 on fail, or < 0? Or nonzero?



You can figure that out from the code.

quote:
- what exactly is the combat value? how is it generated? What is float *val? Is that where the return value comes from? Or is it an input array of numbers? Or a temporary?



The combat value is also easily figured out from the code. And val is a bad variable name. That''s the only reason we can''t tell what it is.

quote:
- no "smart" naming convention in the world is going to be able to undo the need to comment the 20 struct members and complicated functionality of generate_combat_value().



Not if each member has a descriptive name.

quote:
A single line of comments would answer all these questions. I simply cannot see how you can produce release-quality code without them. How can you _possibly_ advocate writing code that causes others to _guess_ at how it works? That''s a surefire way to screw your whole project. For this reason alone, I cannot accept the fact that you''ve got the experience you say you do.



They don''t need to guess. If you modularize correctly, each separate small algorithm is divided well enough that you can figure out what it does.

quote:
You''re working on a small program, say seven source files named "Graphics", "Levels", "Main", etc. Your "Graphics" source file is a few hundred lines long, with around 30 functions, that are pretty much as modularized as is reasonable to make them. It handles loading graphics from a file, drawing them, and the main render loop. You know you have a bug in the file loader, but where is it? It''s much easier to skim the file for a nice, large header-like comment (which sticks out big-time) than to read each function name trying to find a certain function. These take very little time to make, and almost never change, even if the code is edited by other people.



The function names should be descriptive enough to aid you enough as comments do in your query.

quote:
Secondly: I don''t know about anyone else, but if I''m trying to debug a program, I want to be able to read WHY it''s doing whatever (and if I''m understanding properly, this is what that "documentation" would tell you, but if I''m styaring at the code anyway, I don''t want to keep glancing between my screen and some book, I want to be able to read the comments right beside the code.



If you understand the general purpose of each section of code, then you don''t need comments to examine each section and figure out what it does.

quote:
Bud - the examples I gave were just that - examples. I was hoping you''d fill in the blanks and understand what I was trying to say. Even if you had a well-named 20 member struct, what would you give the function for a name?

int generate_a_combat_value_by_taking_members_four_five_and_six_dividing_by_the_number_of_oh_wait_this_is_retarded();

Congrats on zinging me by "assuming" I write that kind of code though! Score : you!


The documentation is sufficient to understand what each function does related to the general larger module.

quote:
A friend of mine used to work at a phone company where they maintained a 50 million line telephone switch codebase. There were people there who spent their entire lives maintaining that piece of code. You''re telling me you expect a new guy to read the documentation on 50 million lines of code and be able to go in and fix uncommented code on a system which runs hundreds of millions of phone lines? No.



The documentation should be sufficiently divided that you can find what a function does.

quote:
But perhaps there''s a blurring here between what you''re calling "documentation" and what I''m calling "comments". Certainly, textual descriptions at the top of a module fall into both categories and can go along way towards revealing the philosophy behind the module. However, I _guarantee_ you I can write you a math-intensive function (for example) that fits perfectly into a well documented module, and it would take you a day to understand what was wrong with the function, _unless_ I put comments in the code. I''m sure your managers would love to see productivity soar like that.



First of all, why would you care if we understand it?
Second of all, if it is math intensive, you are going to spend the same amount of time understand the code alone compared to the comments and the code. Code you turn into more general and general pseudocode. Comments you turn into more specific and specific pseudocode until you get to the actual code.

quote:
I will certainly admit that software engineering, as practiced by the game development industry is far from perfect. There''s no doubt we tend to shoot from the hip in terms of the process of programming. Of course there''s no way we run a ship nearly as tight as your average consulting firm or large software house. Scale does matter. However, I still maintain that generalizing and saying "comments are unneccessary" and that you''d be just as well off by looking at the code and effectively guessing at what it does, is bogus. I would certainly hope large software houses don''t want programmers guessing what individual functions and/or lines of code are doing. If your documentation is so completely thorough that it explains everything, well, then you''ve just got comments in a less useful place. Documentation != comments.



Individual lines should be comprehendible enough to mix with the general surrounding lines, figuring out in general what it does in pseudocode. The documentation generalizes it saying why everything does what it does.


So many posts, this is tiring...

quote:
I think I see your point. If the only documentation you have is in the comments in the code would I read them? Oh yes. If I''m calling some function in a dll that takes a parameter that is bit flags, there are no defines and the only documentation for what values are valid is in the comments then I''m going to read the comments. If the only explaination for the sequence functions have to be called in is comments in the header am I going to read it? Certainly I am. My only other choice is making wild guesses, trying every possible combination and permutation or disassembling it. I don''t consider those to be comments though. It is documentation buried in the code.

Like I said before, most short functions are easily comprehendible, and even if they''re not, comments won''t help.

quote:
If your coworkers want comments then that alone makes it important if nothing else does.

Why?

quote:
For the second case, it''s better to write comments as you are writing GOOD code. Not the obvious comments, but the ones that will help you write good documentation when you''ve finished that code.



Why?

quote:
If you are just going to call other people''s code and use it as a black box, then of course documentation outweighs comments. If you actually try to maintain their code and figure how it works, then comments would outweigh documentation.

If it''s modularized correctly, you can figure out what each small part does as easily as with comments.

quote:
The1Blade, how many companies have you worked for where this was true? I have yet to work for a boss like this. And I DID work for a boss like this, I would look for another job because if he/she doesn''t care about his/her employees then you are in trouble.



In general, more bosses would not prefer getting complaints about the teamwork in the group. Not because of the validity of the claim, but because loss of teamwork will mean loss of production for a while. They get angry at the first person that informs him of such a situation, its natural.

quote:

What most of you are forgetting is that commenting should explain the code''s intent, and sometimes why, not summarize the code. Have you people ever worked for a company who has a huge application they want you to make an addition to, which you''ve never even looked at? If you think comments aren''t extremely helpful at that point then you''re crazy. I mean, you can look at a line of code and understand it, but you don''t know what the application as a whole is doing. Anyone can look at a line and say, "Yep, they are shifting the bits in this integer 3 to the left, but that doesn''t tell them what that section of code is supposed to do. I mean, what if this section of code has a bug in it? How are you supposed to know what the code was SUPPOSED to do without comments are an intimate knowledge of the program?




First of all, the comments themselves could be saying goals that you don''t really want in this line of code, so you can''t always base whether a line is good or not because of the intentions expressed in the comments.
2nd of all, the general role of a large module is better explained in documentation.
3rd of all, if you understand the previous lines, you''ll understand the result of a certain operation. From the code in the future you can find that the operation is not doing something properly.

quote:
That is one thing I agree with Daveb about. Commenting is a good practice. That I can get by without it doesn''t mean it shouldn''t be done. That you can get by without program documentation doesn''t mean you shouldn''t be doing it. If you have done it plenty of times before and it would only be for your own benefit then certainly there isn''t much point to it if you are not going to use it. If you have never done it then there is a benefit just as there is for a beginning programmer to comment. Not that beginning programmers are the only ones that benefit from comments, but rather they are pretty much the only ones that benefit from the process of commenting. It helps them reason out what they are doing to explain it in english. Program documentation does the same thing at a higher level. Working at a systems level means thinking of the program in the abstract. If you want to do something like STL, MFC, OWL or VCL then it is essential that you not bog down in the details. If you want to write something like Windows or DirectX it is also essential.



You haven''t explained why you should comment if you can get by without it.
Comments are only important if you want to maintain the code.
If you''re never going to program again, comments aren''t needed.

...
Comments are not supposed to describe whats going on, their suppose to tell why it''s going on. And the why is not conveyed by the best naming conventions.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:
Original post by Anonymous Poster

I must say you're quite arrogant. George W. won the election, he has(or will have) experience, does that mean his policies are right?



Hey pal, before you start getting punchy - I was _asked_ what my experience was. That's the only reason I posted my credentials. And considering this is "gamedev.net" I think its relevant, especially while explaining my side of the argument. You're the one posting anonymously. Perhaps you'd like to give us your relevant experience?

But you win. You're super-I-don't-need-to-comment-because-I'm-so-damn-good programmer man. I wish I could say I have that much skill. I don't. Probably 99% of the programmers (skilled or otherwise) in the world don't have that ability. ::shrug::

Edited by - daveb on November 8, 2000 11:05:39 PM
Volition, Inc.
LilBuddyWizer - I didn''t say exactly what I meant; I basically agree with your last post.

quote:
Original post by Anonymous Poster


You''re saying typos are less common than large logical algorithmical errors?


''algorithmical errors'' take up more time than typos; debating that would be ludicrous. Commonality is debatable and irrelevant.

quote:

The ratio of commented to non-commented lines is already being discussed in the previous point. But do you agree that in a single commented line the comments take up more characters than the code?


Sometimes, yes, but it is irrelevant. You actually argued that the number of charecters was equal; I say find any professional code that has that property, and I would be very surprised.

quote:

If you modularize correctly, you can debug each separate function at a time. Making the debugging state not that long. The reason debugging states are long is because of general design errors. These can''t be fixed by comments.


Theoretically, mabye, but in practice it is hard to modulize so well and keep them so small as to nearly eliminate the debugging process. As in, no team that I know of has ever been able to do so; they either have a long debugging period or they ship a buggy product. And I rarely make typos in my code (I do, just rarely), I generally don''t bother to fix them while writting online. I also don''t use variable names containing words I don''t know how to spell, as I sometimes use words I don''t know the exact spelling for; but It''s not worthwhile to look it up.

quote:
It''s pretty obvious you have no real world experiance. When you get some, come back and we can discuss this further.

I consider your skeptancy on my years of experience in this market an insult. I haven''t personally insulted you, so please, have a professional attitude toward this thread.


I questioned your professional experiance becuase you actually suggested: Don''t comment if your coworkers/boss ask you to, ''Manipulate'' your boss, and other things that sound liek you have no idea what you are talking about. I''m sorry if you find it insulting, but I continue to believe you have no professional (being paid for coding) experiance.

quote:
Um, an *objective* view is not what you presented here. An objective view is when you argue for both sides. Your view is strictly subjective.

Objective (from dictionary):"Uninfluenced by emotions or personal prejudices". Not even close.


quote:
- does it return the combat value or is that an error/success code? Is it 0 on fail, or < 0? Or nonzero?

You can figure that out from the code.


Are you telling me it would be quicker to read the whole code than to read one line describing the return value?

quote:
If your coworkers want comments then that alone makes it important if nothing else does.
Why?


Get a job, then mabye you can figure it out.

quote:

The documentation should be sufficiently divided that you can find what a function does.


But if it''s not? Comments are another layer of protection from the real world, where documentation may be inavailable, incomplete, nonexistant, wrong, etc. Stop being so damn theoretical and be realistic; you speak in "shoulds" and "ifs", welcome to the imperfect real world buddy. Also, it can be easier to just refer solely to code, and not both code and documentation.


Mike
"Unintentional death of one civilian by the US is a tragedy; intentional slaughter of a million by Saddam - a statistic." - Unknown

This topic is closed to new replies.

Advertisement