|
When I was at college I was told that every line of code MUST be commented, however they did stress that the comment should state why you are doing something not what you are doing (after all, you can figure out what the code is doing just by reading it, and if you can't understand the code then it needs to be refactored), sticking to standard patterns also helps with ease of understanding.
Despite what they impressed on me at college, I'm not in favour of commenting every single line of code as it's unnecessary, but I (mostly) always write headline comments on Methods/Properties/Classes/whatever as an overview of functionality; and I also (mostly) write comments for a group of statements in methods more or less like a overview/guide, without commenting every line.
But, most importantly, I comment for the future me, who in 2 weeks time will be looking at a section of code I wrote at 11:30pm one evening thinking - why did I do it like that again?!
"Benjamin is nobody's friend. If Benjamin were an ice cream flavor, he'd be pralines and dick." ~ Garth Algar
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
|
|
|
|
|
1.21 Gigawatts wrote: I comment for the future me, The "future you" is the "future maintainer", who in 20 years time, will probably be "somebody else". So, you should comment for the "future maintainer".
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
Hopefully most of my code is not in use anymore in 20 years.
|
|
|
|
|
The 'future maintainer' is me in this context
I do C# for fun, day job is slightly different, but related nonetheless!
"Benjamin is nobody's friend. If Benjamin were an ice cream flavor, he'd be pralines and dick." ~ Garth Algar
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
|
|
|
|
|
I don't always comment, but when I do, it's for my future self. As a solo dev for most of the past 16 years, I've never had a problem understanding my own code.
"Go forth into the source" - Neal Morse
|
|
|
|
|
You must not get out much.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
Whaddaya mean? I'm here most days!
"Go forth into the source" - Neal Morse
|
|
|
|
|
Dan Saks, one-time secretary of the ANSI/ICO C++ standardization committee, said the following:
"If you can say it in code, do so. Otherwise, say it in a comment."
In other words, your code should be self-documenting as far as possible. Your comments should supplement that documentation as necessary.
Software Zen: delete this;
|
|
|
|
|
|
Real words of wisdom there.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Seasoned programmers know well that code is the ultimate comment. When code reads like a story, there's hardly any comment needed. Comments come handy only when you have to break the flow of the story due to limitations of the language or adopt a complex hack to improve performance, etc.
|
|
|
|
|
I've seen some linq examples here that does NOT read like a story and definitely needs commenting
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I agree with you and I have seen simple structures like for loops that require comments. Any programming feature or paradigm can be abused if its purpose is not fully understood by the developer.
|
|
|
|
|
Comments are for business logic. There are often things we are told to do that seem crazy, but they are just the crazy things we're asked to do. So often times, the comments explain why I'm doing something I don't think makes sense to do.
Hogan
|
|
|
|
|
// I'm sorry
|
|
|
|
|
so I use long and explaining coding conventions and names and a clean control flow to make it easy readable.
Only when it gets wired I use comments.
This is working fine for me for some years. I understand my 10 year old code. (I hope so)
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
To the poor souls who have to review my code
|
|
|
|
|
I do not fear of failure. I fear of giving up out of frustration.
|
|
|
|
|
Developers who have spent any time on large projects understand the importance of code comments. When you’re building many features into the same application, things tend to get complicated. There are so many data bits including functions, variable references, return values, parameters… how are you expected to keep up?
It should come as no surprise that commenting your code is essential, both solo and team projects.
Regards,
Palash
|
|
|
|
|
That's not what comments are for... That's actual documentation.
Comments are for those times you can't express yourself very well in the code itself: it says why you did something a certain way, for example.
|
|
|
|
|
Agreed. Documenting every bit of the code is more useful than cryptic, embedded comments. We're not obliged to read the manual but if it has been well written it should explain everything.
How often I fall victim to the copy/paste merchant who forgets to modify his comment for the new scenario.
We're philosophical about power outages here. A.C. come, A.C. go.
|
|
|
|
|
Palash Mondal_ wrote: how are you expected to keep up?
Design and implementation documents? Yes a radical idea which has not gained sufficient traction in all quarters.
Peter Wasser
"The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts." - Bertrand Russell
|
|
|
|
|
I had to. I just had to.
Jeremy Falcon
|
|
|
|
|
That isn't complete without bacon, liquid nitrogen and Paris Hilton.
You have just been Sharapova'd.
|
|
|
|
|
Jeremy Falcon
|
|
|
|