An objective analysis of comments: Are they necessary?

Started by
83 comments, last by The1Blade 23 years, 5 months ago
quote:Original post by The1Blade
If they made a small algorithmical change, then they should tell you where they did it, and then you go and easily figure that one line out yourself.


What if its not an algorithmic change? What if its something about the particular software you are using. I''ll give you an example. Note this is an Oracle PL/SQL statement and not C or C++, but the point is the same.
SELECT ''X''   INTO employee_begin_after_jan_31_1999   from employees   where employees.start_date > TO_DATE(''JAN-31-1999'',''MON-DD-YYYY'' 


Now anyone with any PL/SQL (or SQL) experience and probably a lot without, would be able to see that this is trying to find out if there are any employees that have started after the date of Jan 31/1999. But, wouldn''t it be nice if I added a line of comment to it so that you didn''t need to read the sql statement? Something like:
-- check to see if any employees have started after jan 31/1999SELECT ''X''   INTO employee_begin_after_jan_31_1999   from employees   where employees.start_date > TO_DATE(''JAN-31-1999'',''MON-DD-YYYY'' 


Arguably that hardly adds anything to the code as it would be pretty obvious what my code is doing, but I bet I saved you a few seconds, and when time is money....

Now here is where we get to what my point really was about. What if I change the statement to look like this:
-- check to see if any employees have started after jan 31/1999SELECT ''X''   INTO employee_begin_after_jan_31_1999   from employees   where employees.start_date > TO_DATE(''JAN-31-1999'',''MON-DD-YYYY''     and rownum = 1 


This is an optimization trick. In this case you don''t care how many employees started after jan 31/2000, only that fact that someone has. The ''and rownum = 1'' tells the database server to stop after its found the first one, rather than scan the whole table, which is what it would do without it. If you were inexperienced in sql optimizations or had never seen that before, you might not know what it is there for. A little comment would take care of that.

quote:
Thanks for proving a point of mine, if the good programmers write the code, then it is properly modulized, etc. and the maintenance people could easily figure it out. The only thing that would take thinking are the more complex algorithms, which would take you the same amount of time to figure out with or without comments.


I hardly think I proved a point of yours. I never said ''good programmers'', I said ''more experienced programmers'', they are not necessarily the same thing. And good or not, more experience generally means they have learned more sneaky optimization tricks or a faster (but possibly more convoluted) way of doing things. And I disagree that it would take as much time to figure out the more complicated code with or without comments. But then we are allowed to disagree. We should probably drop this as doubt you will ever convince me that comments are not necessary, and its looking like I will will never convince you or they are.

Bret.
Advertisement
1blade, I don't suppose you could show us a sample of your code documentation? I'm sure we'd all be interested to see what "perfect" code documentation is.

I'm surprised that you can get away with manipulating your bosses. If I tried anything like that, I'm sure that I would be fired.

quote:
Business is never friendship, it is business, I do what I need to for my own well-being.


quote:
If they said that they would prefer it but you wouldn't gain from it, would you? Im not being self-centered.


Hmmm. Very interesting comments.

Also, on modualarizing - I've had plenty of times when it's difficult to tell if an error is due to the code in the function or due to bad code in the module. Also, when so many things depends on so many other things, it can get very hard to track. How do you get around this?

"Science is a tool. If the tool works, we use it. If it's true, that's great, but if it isn't, it doesn't matter" -- ("Desert Fox" from GameDev.net)'s physics teacher

Edited by - CobraA1 on November 20, 2000 11:05:51 AM
"If a man does not keep pace with his companions, perhaps it is because he hears a different drummer. Let him step to the music he hears, however measured or far away"--Henry David Thoreau
I'm sorry, but I will not waste my time discussing this with someone that attempts to argue with a dictionary. Sorry, but putting up one point opposite your view and then claiming it invalid is not even close to objective. Your entire first post reeks of personal prejudice. When you stretch your arguement that thin, you will get many that disagree with the BS you are spewing. I have seen no code written and documented so well that the abolition of comments is appropriate, but I would like to seet his VCL code. Where can I see it, LilBuddyWizer?

Here's my summary, you can have the last word. Correct comments have their place. They can let you know the intent of the code, are useful in describing return values, etc. If you would like to see good evidence for comments, I suggest you read Code Complete, or the likes.

If you seriously have the professional life you describe, you are one sick individual. For one with 23 years experiance, you have a lot of growing up to do. 'Boss manipulation' and ignoring coworkers for an insignificant gain are signs that you need some professional help. I suggest you search out therapy immediatly. Out of curiousity, where exactly were these jobs that you implemented these professional strategies? Can you name a specific job? I'm curious.

That's all I have to say, I hate being repetitive, so I will stop. You may take the last word.

And yes, I will do whatever my job requires, whether I enjoy it,think it's best or whatever. If I don't like the requirements, I will talk them over rationally with my boss or find a new job. I will not attempt to 'manipulate' him so he 'likes me better' than my coworkers.

Mike

Edited by - Vetinari on November 20, 2000 11:14:01 AM
"Unintentional death of one civilian by the US is a tragedy; intentional slaughter of a million by Saddam - a statistic." - Unknown
heh.

I am a newbie, and so I am just reading and learning. But I find it interesting that I have never seen such well-commented replies as the ones in this thread. You guys have gone to great trouble to quote each other and intersperse your replies with the other guy''s quotes.

Could it be that context is important? I, for one, need my documentation/comments in close proximity to the code. Whether that means liberal commenting in the code itself, or code snippets in the documentation, it helps me not to have to go back and forth.

IMHO,
- gollumgollum
I believe anyone that has either C++ Builder or Delphi has the source to the VCL, though I might be wrong and it may not be included with the Standard version. It certainly is with both the Professional and Enterprise versions though.

Seperately it depends on your definition of manipulation. Using the Merriam-Webster Online the definition is: 1) to treat or operate with the hands or by mechanical means especially in a skillful manner; 2) a - to manage or utilize skillfully; b - to control or play upon by artful, unfair, or insidious means especially to one''s own advantage; 3 - to change by artful or unfair means so as to serve one''s purpose. I would have to argue that 2.a is an essential requirement for success. Even with 2.b and 3 there is no requirement that it be to the detrement of the one being manipulated. I personally don''t feel you should use unfair and insidious means, but I see nothing wrong with convincing a bank to give me loan I am perfectly capable of and intending to repay. It is to my benefit in that I am able to leverage my equity, but it is also to their benefit in the form of the income they earn off the interest. Personally the only reason I can see for convincing someone to do something that is not in your own interest is love. I don''t love my company. Perhaps I should, but I don''t. Rather I only want to see them successful because it makes my job secure and increases my chance of promotion.
Keys to success: Ability, ambition and opportunity.
Well now, here''s from my dictionary (GuruNet):
1) To operate or control by skilled use of the hands; handle: She manipulated the lights to get just the effect she wanted.
2) To influence or manage shrewdly or deviously: He manipulated public opinion in his favor.
3) To tamper with or falsify for personal gain: tried to manipulate stock prices.
4) Medicine. To handle and move in an examination or for therapeutic purposes: manipulate a joint; manipulate the position of a fetus during delivery

And my thesoraus for the same meaning: exploit, maneuver, play.

I would consider applying for a bank loan transacting or dealing, not manipulating.

I don''t see any of the above meanings necessary for success. In fact, they carry the same connotations that I have in my mind when I think of manipulation of people. That is, self-centered purposes, generally less than honest means, usually at the detriment to others, though not necissaraly the one being manipulated.

From the context, I believe that was the type of meaning he was using; in fact, manipulating the boss to the detriment of his coworkers and boss himself. Of course on teh internet, miscommunication runs rampant.


Mike
"Unintentional death of one civilian by the US is a tragedy; intentional slaughter of a million by Saddam - a statistic." - Unknown
Question: An objective analysis of comments: are they necessary?

Technically no. A program will compile and run fine with or without comments. So they aren''t.

But they can be useful.

--------------------------
I guess this is where most people put a famous quote...
"Everything is funnier with monkey''''s" - Unknown
--------------------------I guess this is where most people put a famous quote..."Everything is funnier with monkey''s" - Unknown
First, my background, for the sake of you understanding my perspective. I''ve been programming as a hobby for roughly 10 years, with no professional experience. I''m in the last year of a computer science curriculum. I expect I''ll be graduating top of my class. I''ve worked on everything from tiny solo projects to large-scale open-source projects.
I''m not going to even attempt to debate this from the perspective of writing the original code. I neither have enough experience to be definitive nor do I think it''s relevant.
What is relevant is how that code is going to be used. I am not the best programmer on the planet. I cannot easily understand every single piece of code I read. Sometimes I have to spend hours pouring over it, trying to glean the reasoning of some section, even if I know the intent of the function from the general documentation. A few comments inside the code would almost always make that job much easier.
I''m not implying every programmer needs to write down to my level as some of you will only work exclusively with programming geniuses. However, the vast majority of you will have to work with less experienced programmers such as me. These are the people that will be greatly helped by comments.
When I''m out looking for a job for after graduation, I know I''ll be looking for a place like Volition - a place where I feel I won''t be ignored for not being a programming god, but rather one where thoughtful comments will bring me up to speed much quicker. I''ll be quickly dismissing companies with programmers who are too arrogant to realize other, less-skilled people need to work with their code as well.
Ah well, I see, it is only ok for you to argue with a dictionary. I stand corrected.
Keys to success: Ability, ambition and opportunity.
quote:Original post by Belandrew

First, my background, for the sake of you understanding my perspective. I''ve been programming as a hobby for roughly 10 years, with no professional experience. I''m in the last year of a computer science curriculum. I expect I''ll be graduating top of my class. I''ve worked on everything from tiny solo projects to large-scale open-source projects.
I''m not going to even attempt to debate this from the perspective of writing the original code. I neither have enough experience to be definitive nor do I think it''s relevant.
What is relevant is how that code is going to be used. I am not the best programmer on the planet. I cannot easily understand every single piece of code I read. Sometimes I have to spend hours pouring over it, trying to glean the reasoning of some section, even if I know the intent of the function from the general documentation. A few comments inside the code would almost always make that job much easier.
I''m not implying every programmer needs to write down to my level as some of you will only work exclusively with programming geniuses. However, the vast majority of you will have to work with less experienced programmers such as me. These are the people that will be greatly helped by comments.
When I''m out looking for a job for after graduation, I know I''ll be looking for a place like Volition - a place where I feel I won''t be ignored for not being a programming god, but rather one where thoughtful comments will bring me up to speed much quicker. I''ll be quickly dismissing companies with programmers who are too arrogant to realize other, less-skilled people need to work with their code as well.



I have been programming professionally for 10 years and I have yet to meet a person that could look at a chunk of code and instantly know every detail about it. You are the norm, despite what a few people have seemed to imply here.

Bret.

This topic is closed to new replies.

Advertisement