|
His commenting may be providing him with "thinking space" ... the same way some people doodle. I expect he'll outgrow it.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Long back, had inherited a code like this:
bool funcName( five arguments of different types )
{
return true;
}
No comments in the code, rather the entire code was commented out.
Unfortunately, could not get my hand on the coder who created this, he had resigned.
|
|
|
|
|
one of my products is 23 years old now since i launched it (started writing it in the late 90's), written in vb6. I sold over 1000 copies back in the day (and even sold a new one a year ago). I still have quite a few users who pay support (and a few who don't) and dont see the need to change or upgrade to my newer version coz it does everything they want and they are comfortable with it. my newer version was launched 2010 and is a net framework product, so i suppose 13yo for that is getting quite aged these days, but again i have loads of customers on it. I am a compulsive 'commenter' (always have been) since the 70's, even though the code is never likely to be seen by anyone else, and now i'm in my 60's (and still coding), the grey matter aint as sharp as it once was there's a definate advantage when i need to make mods, and imho code that aint documented aint complete. GL
|
|
|
|
|
Yes ... commenting can be seen as an investment in terms of when it comes time to "sell the company". One man's noise is another man's salvation.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
charlieg wrote: Do comments even matter any more, or am I flattering myself?
Comments matter A LOT. Although, going through the previous replies I can see a contrarian trend ("I don't write comments", "code should be self-documenting", etc.). Sorry, but I find it ludicrous, at least in my line of work. Just two days ago I was working on this code:
const double pre_2008[2][14] = {
{ 0.0019, 0.0017, 0.0105, -0.00134, 0.00, 0.00, 0.00,
-0.0001, -0.0001, 0.0018, 0.00008, 0.00, 0.00, 0.00}, { 0.0020, 0.0009, 0.0047, -0.00094, 0.00, 0.00, 0.00, -0.0003, 0.0, 0.0, 0.00, 0.00, 0.00, 0.00}
};
Pray tell me, how would you write this in a self-documenting way? If I wouldn't have put that comment block there, would anyone (myself included) had been able to figure out what's going on?
So, for your own sanity and for the sanity of those around you, please, keep commenting!
Mircea
|
|
|
|
|
My oldest code that I maintain is no more than ~10 years old (have moved companies, products have been EOL'ed, etc.), but I've always been a compulsive commenter. The comments mostly help me, six months down the line.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
I find it depends on what language I'm writing in and, to a certain degree, what the code is doing. In general, I'll have more comments when I'm writing C code than I do for C# and Java. I've got some C code that does some quite involved data manipulation. That code has both in-line comments and a notice at the top that says "read and UNDERSTAND the XXX page on the project wiki before you do anything with this code." What it's doing is so complex both high-level and low-level block comments are needed for anyone besides me to modify it. I've also got some C code that does the equivalent of serialization; that code has no comments beyond "save the data via serialization"
As with all things coding --- it depends.
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
I used to write comments all over the place that know one reads, even me.
Nowadays I write comments so GitHub Copilot can generate code off of it auto-magically. 😁
|
|
|
|
|
Absolutely do matter, anyone tells you otherwise does not have 40 years experience.
The concept of "self-documenting" code is nice, sometimes do-able. But the time
it takes to write a comment (or a few comments) for code that is non-trivial is
saved many times over as that code is revisited in coming *decades* (think the
build up to Y2K when we needed to figure out code written between 1965 and 1990).
Not commenting is short-sighted and, I think, selfish and arrogant of the developer
who assumes:
1) later developers are as good as he thinks he is
2) his time is too valuable to be wasted doing non-coding tasks.
Sorry, personal pet peeve of mine picking up process control C code written in the
mid-1990s with zero comments that does not work.
|
|
|
|
|
WPerkins wrote: The concept of "self-documenting" code is nice, sometimes do-able. "Self-documenting APL code", is than an oxymoron or not?
|
|
|
|
|
Since this seems to be two questions, I'll answer in two parts:
Code comments: I use comments very sparingly, really only when the code is complicated. Yesterday I wrote more comments than I typically write in a month, describing for myself the layout/elements of several multi-dimensional arrays. I do find that I comment more these days that I used to.
How old is my code? My company's flagship product was released to the public at a trade show in the summer of 2K. Since development started around 1.5 years before that, there is code that dates back to '98 when I got hired...so around 25 years ago!
"Go forth into the source" - Neal Morse
"Hope is contagious"
|
|
|
|
|
FWIW I read comments others have written.
Even if I'm the only one who will ever read my comments, that makes them worthwhile.
I try very hard to make my comments clear and concise to improve the chances that they will be read.
|
|
|
|
|
Definitely for myself, though most of the comments nowadays seem to be // TODO: fix this bug
|
|
|
|
|
I started programming in the late 70's so the only real option was assembly code for the devices I was programming for. It pretty much cemented the idea that I should be commenting my code. It's a practice that I kept throughout my career. Commenting was for my own benefit and for anyone who might be modifying my code. I always made the assumption that the person inheriting one of my projects wouldn't necessarily be a very knowledgeable programmer so good commenting was needed.
|
|
|
|
|
There has been a fairly recent crusade against comments. Some claim code should be self-documenting and that comments are somehow evil.
You know what's documenting? Documentation... like comments.
Self-documenting? WTF? There's nearly zero code ever written that explains WHY it does what it does or WHY it was changed to do otherwise. I guess you can enforce tying commits to cards and chase down the commit that changed the code and then the card that brought that commit.
Alternatively, maybe a comment isn't such a bad thing.
Has nobody written a VS plugin to just turn all comments on/off?
Is it really just that developers hate documentation so much they'd rather claim their code does all the documentation for them? Because that's just how great their code is?
Do people not use XML comments so people get intellisense on what they are calling? Do they think making that block descriptive is some massive chore?
|
|
|
|
|
That crusade against comments has been going on for many years, where I have been.
The major exception is huge copyright/left comment blocks topping every source file and extensive comment blocks heading every function, repeating the function name, the the types and names of all parameters of the function declaration, only doing it in 10-20 lines instead of one, cluttered with typographic markup.
I have been heavily criticized for my habit of adding a lot of explanatory ("why") end-of-line comments - end-of-line because I like to see the entire function/method in a single screenful rather than three. I also have a habit of aligning the comments from col 80, so that they do not visually disturb the code itself - you look at the comments (only) if you wonder "why". A number of my critics also love to open three source file windows side by side, so narrow that they usually won't see my comments, which are outside of their windows 
|
|
|
|
|
|
Comment for yourself. Some devs will read them... some... if they are coherent and make sense to a different person. And then some devs refuse to take any initiative... so good luck with that.
Jeremy Falcon
|
|
|
|
|
I guess I should have provided context on what I mean as a comment. For as long as I've been writing code, I outgrew quickly code comments that say "increment the pointer" and other trivial stuff. I also like *limited* Hungarian notation: certain prefixes that over time just help me scan the code. Years ago, I picked up the habit that every pointer begins with a lower case p. Key was readability.
As for oxygen and other tools like that, they sometimes help understand the overall system (especially call trees) but development tools have made such advancements that most of the doc has been replaced by tool features (hovering over a variable for example). The best tool I've ever used is Understand from SciTools. Unfortunately, they moved from a perm. license model to monthly fees, pricing it out of my market.
Rather than what, I try to explain why the code does what it does. Example of the table of data - that's what and you can infer why. In my case, I have a piece of common code that runs on 4 different platforms. Thelatest platform has some issues to be worked around, and I found myself trying to explain why. It then occurred to me that I knew the product was reaching end of life, no one will likely read this, just comment in the SVN commit.
After reading all of the replies to my question, it might be wordier, but breaking up the code into 4 different methods (each supporting a specific device) is probably the cleaner approach.
Thanks for the insights.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Sometime in the 1970s one of our users reported a problem entering a date for a future event. The code was not written by us, but we had the source, so I pulled up the code to see how it worked. I found this comment (PDP-10 assembler)
"Thirty days hath September, all the rest I can't remember, except February which never works anyway" There was no code to handle leap year! At least the comment helped us know we were in the right place. That isn't the worst comment I found in code from that source, but the worst would violate nsfw rules.
|
|
|
|
|
I like it!
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Most PC mainboards have various 'headers' (why are they called that?) for attaching I/O sockets on the back, LEDs on the front, internal fans etc. Micros such as Arduino have lots of them - super simple, naked pins, no shielding, no locking holding the plug in position. Sometimes the board has the male pins, sometimes it has the female receptacle. They are far less robust that the power connectors.
I believe that the distance between pins are 1/10", commonly in a single row, but two rows is not uncommon. The number of pins vary from 2 (or even 1) up to at least 36. The cross section is usually square, but is is always? Always the same size (pin thickness)? Always 1/10" apart?
I have tried to find out what these connectors are called, to learn about their specification. There must be some standard defining them. What is the name or number of that standard? Maybe there are several standards - I suspect that some of them have a pin distance smaller than 1/10". Sometimes, there is a lock and release on the plug (typically on fan connectors), but maybe that is a different standard? (Or several different ones - 'The good thing about standards' etc.
Can anyone provide the name of the connectors, so I can google for more complete information? Or possibly give me a link to more information about them: Physical dimensions/distances, pin shape/length, male/female usage, lock/release usage, acceptable voltages and current/power and so on.
|
|
|
|
|
Just to clarify. Are you talking about, for example, the GPIO pins on a Raspberry PI, which seem to be the same as the pins on old IDE Hard drives for Master/Slave/CS?
Keep Calm and Carry On
|
|
|
|
|
I never worked with Raspberry Pi, but looking at the top photo of Wikipedia: Raspberry Pi[^] looks like the male version of what I am thinking of.
Wikipedia: Arduino[^] shows a photo with 8 and 10 pin female connectors along the edges, and two groups of 2 by 3 male connectors. (I believe that even they seem to be made of 3 independent 2 pin connectors, the plastic at the bottom keep them at a standard distance so that a single 2 by 3 female connector would fit.)
The IDE, aka PATA, connectors I remember are quite robust, with a frame around the pins having a slot to ensure that the plug is not turned around and that it is pushed straight down. The plug is sturdy, usually attached to a flat cable making it even sturdier. The male pins are significantly shorter. The plug (female) sometimes has one hole covered, and wouldn't fit on the Raspberry Pi GPIO. I guess the PATA standard would define this connector.
I was thinking of the less robust ones such as those for making connections from the PC front panel LED/buttons to the mainboard, such as those shown on YouTube: Explaining PC Front Panel Connectors [^] (you don't have to play the video to see the photo of the plugs).
Is there a name/standard for these kinds of connectors?
If you look at Wikipedia: Computer Fan[^], next to the section 'Multiple purposes' ("A small blower fan ..."), you will see a fan connector that will fit onto a single-row header, but in a proper fan socket you can only insert it one way. Is this a different standard from the headers, and if so, what is it called?
|
|
|
|
|
Sorry to be negative, but whilst there are design standards for such connectors (indeed often called 'headers' when on devices) there are so many 'standards' for so many different kinds of connectors used in so many situations (eg soldered on a PCB, in-line in a cable, surface mount) not to mention for different purposes (eg RS232 - lots of different ways of wiring these even with a standard to follow), SCSI, USB (four 'standards for this in current use and rising), power (uncounted numbers of DC power plug connectors), video monitors (at least 8 that I know of) that all you can do is try to establish which ones you are connecting to and match that type.
Even then, some connectors are made for a particular manufacturer for a specialised purpose and will only connect to their 'headers' etc (eg early Apple iPhone)
Physical interconnections are still, after all these years, very much not standardised except for a small range of consumer products, and even these (eg USB - C) can vary depending on what uses they are intended for...
Sorry again!
|
|
|
|
|