Inappropriately-Appropriate Code Comments
-
Comments are intended to clear up unclear code. Code should not be unclear because it is badly written, but because the problem it solves is difficult and requires some specific knowledge. That's where commenting should be used. As such each line of comment should be treated like regular code that needs to be maintained. For example, if you change a bit of code that is commented you should check if the comment still matches the code. The less you need to maintain the better, so you best use comments only when they are really necessary (or rather, when you think they are necessary, it's a personal matter). If you comment to much or to obvious comments are distracting and are a waste of digital ink and paperspace and only increase scrolling time. I've written a little tip on writing good comments (or at least what I think are good comments). You might want to check it out: Write comments that matter[^]
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}Was reading you comments in your code in your article. I was wondering why you even bother with Alpha:
// Alpha is simply the answer to life, the universe and everything.
After all every learned person knows the what Alpha has to be, why not just call a spade a spade?
-
What are the general thoughts and/or examples of 'working blue' in code comments? My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree (e.g. "not professional", etc., like devs tend to be "professional" anyway). For example, if I write a particularly kludgy piece of code (which is most of it :~), then I'm fond of comparing it to horse excrement, etc. Not only does it alert me and anyone else as to what's up, it also highlights that I'm aware it sucks and that it's okay to have a bit of sense of humor about it, etc.
Assuming you are being paid to work for a company, then part of the long-term value in the product/source-code base may well be the extent the code is maintainable, readable, and annotated with appropriate comments that explain unusual methods/solutions/work-arounds, as well as the other functions comments usually perform. Source-code with inappropriate personal comments might well reduce the chances of a possible future acquisition of the company, as a possibly acquiring company does a "due-diligence" technical review. I have worked at one company which was "consciously designed" from the get-go to become the "apple-of-the-eye" of a certain very large company, to become an inevitable acquisition target for the big company. And, it was acquired, without ever becoming a "big commercial success" in its own right (to the immen$e benefit of myself, and other holders of the start-up's "fantasy stock"). What if the technical review of the source-code base of the company wishing desperately to be acquired, by the world-class programmers from the acquiring company, had come across a bunch of bizarrely off-topic comments that implied they didn't know why what they were doing, in specific cases, and contained personal ventilation of frustration : ... uhhh ... a deal-breaker ? At that little start-up (which would certainly have failed within six-months if it had not been acquired), there was a high degree of scrutiny of all source-code by the founder, who was one of those rare geniuses who was both a world=class programmer himself, and an astute business-man able to sell venture capitalists a "field of dreams," all the while deliberately shaping the company to be an irresistible acquisition candidate by one specific very-large well-endowed company. best, Bill
~ Confused by Windows 8 ? This may help: [^] !
-
What are the general thoughts and/or examples of 'working blue' in code comments? My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree (e.g. "not professional", etc., like devs tend to be "professional" anyway). For example, if I write a particularly kludgy piece of code (which is most of it :~), then I'm fond of comparing it to horse excrement, etc. Not only does it alert me and anyone else as to what's up, it also highlights that I'm aware it sucks and that it's okay to have a bit of sense of humor about it, etc.
I very rarely include expletives in comments, it is rare that I think MY code is that bad. However I will happily call the owner of some particularly bad kludge any number of expletives. It is rather embarrassing when they explain the reason and I can't come up with a better solution :-O I also make sure I include the URL of any solution I have snaffled off the interweb. This is so I don't have to explain it, the author generally does that in the supporting doco. Added bonus is they get the credit for the solution.
Never underestimate the power of human stupidity RAH
-
Assuming you are being paid to work for a company, then part of the long-term value in the product/source-code base may well be the extent the code is maintainable, readable, and annotated with appropriate comments that explain unusual methods/solutions/work-arounds, as well as the other functions comments usually perform. Source-code with inappropriate personal comments might well reduce the chances of a possible future acquisition of the company, as a possibly acquiring company does a "due-diligence" technical review. I have worked at one company which was "consciously designed" from the get-go to become the "apple-of-the-eye" of a certain very large company, to become an inevitable acquisition target for the big company. And, it was acquired, without ever becoming a "big commercial success" in its own right (to the immen$e benefit of myself, and other holders of the start-up's "fantasy stock"). What if the technical review of the source-code base of the company wishing desperately to be acquired, by the world-class programmers from the acquiring company, had come across a bunch of bizarrely off-topic comments that implied they didn't know why what they were doing, in specific cases, and contained personal ventilation of frustration : ... uhhh ... a deal-breaker ? At that little start-up (which would certainly have failed within six-months if it had not been acquired), there was a high degree of scrutiny of all source-code by the founder, who was one of those rare geniuses who was both a world=class programmer himself, and an astute business-man able to sell venture capitalists a "field of dreams," all the while deliberately shaping the company to be an irresistible acquisition candidate by one specific very-large well-endowed company. best, Bill
~ Confused by Windows 8 ? This may help: [^] !
When I was selling my business I went through the code prior to the source code check and changed all the "WTF" comments to nebulous but pertinent sounding ones. My main system uses bitmapped inverted indexes so there is a lot of bit twiddling and in some cases the code can explain what is happening far better than any comment in English - I used the "WTF" comments as place holders for when I did come to sell my business and needed to at least insert some comments in English in those places.
-
I very rarely include expletives in comments, it is rare that I think MY code is that bad. However I will happily call the owner of some particularly bad kludge any number of expletives. It is rather embarrassing when they explain the reason and I can't come up with a better solution :-O I also make sure I include the URL of any solution I have snaffled off the interweb. This is so I don't have to explain it, the author generally does that in the supporting doco. Added bonus is they get the credit for the solution.
Never underestimate the power of human stupidity RAH
Mycroft Holmes wrote:
also make sure I include the URL of any solution I have snaffled off the interweb
Indeed. I have a wikipedia link in one spot for an algorithm I used.
Software Zen:
delete this;
-
In some of the more bizarre bit twiddling depths of my code I have comments which just say: WTF???!!!!???? It usually means I have tried to give an explanatory comment but gave up as the code isn't really anything which can be expressed in English
Example or it isn't true! I've been able to explain every bithack I ever used, and many that I've never used as well. Sometimes it takes quite a lot of text to explain it in detail, such as in the case of propagating bounds through bitwise AND and OR without a loop (the version with a loop isn't trivial to explain either), but it's still expressible and removing some detail makes it "long but not too long".
-
Example or it isn't true! I've been able to explain every bithack I ever used, and many that I've never used as well. Sometimes it takes quite a lot of text to explain it in detail, such as in the case of propagating bounds through bitwise AND and OR without a loop (the version with a loop isn't trivial to explain either), but it's still expressible and removing some detail makes it "long but not too long".
...and if you can't explain it, you don't understand it, and no one can maintain it. :thumbsup:
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
-
What are the general thoughts and/or examples of 'working blue' in code comments? My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree (e.g. "not professional", etc., like devs tend to be "professional" anyway). For example, if I write a particularly kludgy piece of code (which is most of it :~), then I'm fond of comparing it to horse excrement, etc. Not only does it alert me and anyone else as to what's up, it also highlights that I'm aware it sucks and that it's okay to have a bit of sense of humor about it, etc.
I worked for a while at an "international" company based near Munich. We had people from 43 different countries all working in English (more or less). It was very interesting, especially when you read the comments on some code maintained by a multilingual Frenchman, a multilingual German, a multilingual Englishman, a bilingual Italian, a bilingual Pole, a bilingual Spaniard and a poor American who only spoke the US version of English. The comments were (theoretically) in English - although the grammar was all over the place - but the "meaningful" variable and function names, etc. were multi-lingual! You needed the comments to explain the meaningful names! Yes, I was the Englishman.
- Life in the fast lane is only fun if you live in a country with no speed limits. - Of all the things I have lost, it is my mind that I miss the most. - I vaguely remember having a good memory...
-
What are the general thoughts and/or examples of 'working blue' in code comments? My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree (e.g. "not professional", etc., like devs tend to be "professional" anyway). For example, if I write a particularly kludgy piece of code (which is most of it :~), then I'm fond of comparing it to horse excrement, etc. Not only does it alert me and anyone else as to what's up, it also highlights that I'm aware it sucks and that it's okay to have a bit of sense of humor about it, etc.
IndifferentDisdain wrote:
My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree
The problem of course is that is an assumption. Some possible serious problems... As a specific example some customers require as part of sales agreement the ability to inspect source code and even receive a copy of it. So the Acme company gets your code where you have a comment that says "This only exists because the idiots at Acme don't know what they are doing". A developer from a client company is tasked with helping developing an adaptor in house and in doing so has access to the code base. The developer is John Doe. The comment in the code is "Moron developer at Acme, John something, seems to think that this should return zero instead of null". The new developer, a woman, starts and takes over maintenance of a project that you are more than happy to hand off. The code is sprinkled with comments like "This code is just as temperamental as a woman on PMS". She complains. And you have a EOC complaint in your record. Even worse she sues and you are called to testify so there is a public record of a EOC complaint initiated by you. Of course up until the sh*t hits the fan it all seems like just a bit of fun.
-
When I was selling my business I went through the code prior to the source code check and changed all the "WTF" comments to nebulous but pertinent sounding ones. My main system uses bitmapped inverted indexes so there is a lot of bit twiddling and in some cases the code can explain what is happening far better than any comment in English - I used the "WTF" comments as place holders for when I did come to sell my business and needed to at least insert some comments in English in those places.
RugbyLeague wrote:
I went through the code prior to the source code check and changed all the "WTF" comments to nebulous
And there is absolutely no possibility that you missed one?
RugbyLeague wrote:
I used the "WTF" comments as place holders
Same purpose is served by using a 'TODO'
-
RugbyLeague wrote:
I went through the code prior to the source code check and changed all the "WTF" comments to nebulous
And there is absolutely no possibility that you missed one?
RugbyLeague wrote:
I used the "WTF" comments as place holders
Same purpose is served by using a 'TODO'
I am more keen to check the WTF's than the TODOs - I use TODOs for future enhancements and optimisations
-
IndifferentDisdain wrote:
My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree
The problem of course is that is an assumption. Some possible serious problems... As a specific example some customers require as part of sales agreement the ability to inspect source code and even receive a copy of it. So the Acme company gets your code where you have a comment that says "This only exists because the idiots at Acme don't know what they are doing". A developer from a client company is tasked with helping developing an adaptor in house and in doing so has access to the code base. The developer is John Doe. The comment in the code is "Moron developer at Acme, John something, seems to think that this should return zero instead of null". The new developer, a woman, starts and takes over maintenance of a project that you are more than happy to hand off. The code is sprinkled with comments like "This code is just as temperamental as a woman on PMS". She complains. And you have a EOC complaint in your record. Even worse she sues and you are called to testify so there is a public record of a EOC complaint initiated by you. Of course up until the sh*t hits the fan it all seems like just a bit of fun.
jschell wrote:
some customers require as part of sales agreement the ability to inspect source code
I've had that happen to me. Twice. By the same sales twit. In both cases she sold the rights to our source code in a sales contract. In the first case, the customer just needed some documentation that wasn't part of the standard kit. In the second, a few e-mails between the customer and yours truly helped resolve the issue. This is what happens when you're a software engineer working at a hardware company. The sales twits would never dream of giving away hardware design information like schematics or CAD drawings. Software has no intrinsic value, so just give it away :mad:.
Software Zen:
delete this;
-
What are the general thoughts and/or examples of 'working blue' in code comments? My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree (e.g. "not professional", etc., like devs tend to be "professional" anyway). For example, if I write a particularly kludgy piece of code (which is most of it :~), then I'm fond of comparing it to horse excrement, etc. Not only does it alert me and anyone else as to what's up, it also highlights that I'm aware it sucks and that it's okay to have a bit of sense of humor about it, etc.
The rule is: If other people are to see or work with your code then keep it proffessional, informative and descreet. ( You don't know their religion, ethics, if they are PC (Politically Correct) or if they are easily offended.) If you are the only one that manages the code the WTE, do what ever you like. But then again.... How do you name your variables and your functions? Do you follow the same ethical procedures that you use for comments...? Catch an exception and .tostring it to a messagebox and have your expletives revealed to all. Best to write all your code as it was to your Mother or Chris Maunder's Kid sister. That way you won't elephant up. Personally though I like a bit of character in comments and in var names, function names, class names, module names and indeed form names. I do know this though... Never ever write temporary violent, abuse or expletive stuff in your messagebox or any notification code, because one day you will not delete it or or comment it out, and it will Pop up on a customers machine. Comments are for other programmers or yourself. Keep pro or if just for thy then go for it... but always beware...
-
What are the general thoughts and/or examples of 'working blue' in code comments? My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree (e.g. "not professional", etc., like devs tend to be "professional" anyway). For example, if I write a particularly kludgy piece of code (which is most of it :~), then I'm fond of comparing it to horse excrement, etc. Not only does it alert me and anyone else as to what's up, it also highlights that I'm aware it sucks and that it's okay to have a bit of sense of humor about it, etc.
-
What are the general thoughts and/or examples of 'working blue' in code comments? My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree (e.g. "not professional", etc., like devs tend to be "professional" anyway). For example, if I write a particularly kludgy piece of code (which is most of it :~), then I'm fond of comparing it to horse excrement, etc. Not only does it alert me and anyone else as to what's up, it also highlights that I'm aware it sucks and that it's okay to have a bit of sense of humor about it, etc.
Years ago, a bright young programmer placed a comment in what he thought was code that would never execute. It did. In the field during a trial with a potential sale of hundreds of units. If not for the sense of humor with the client's field engineer at the time, I think we'd all have been fired. The comment was something to the effect of requiring the sacrifice of a black goat on the keyboard during a full moon. Placed by a person who had since left the company ... and we did not even know about it. Shame on us. Very tense scenario in the room when that message popped up. We were called in for a chewing out at the next available meeting. The sale did go thru, btw. A commment like that can cause a lot of heartache, even jobs, you name it. With the current jobs atmosphere these days, it's best to keep our frustrations to ourselves. I know of some employers who monitor comments on blogs even when you are not at work. It'd be a pain to work for such folks but they do exist.
-
What are the general thoughts and/or examples of 'working blue' in code comments? My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree (e.g. "not professional", etc., like devs tend to be "professional" anyway). For example, if I write a particularly kludgy piece of code (which is most of it :~), then I'm fond of comparing it to horse excrement, etc. Not only does it alert me and anyone else as to what's up, it also highlights that I'm aware it sucks and that it's okay to have a bit of sense of humor about it, etc.
Time was, I'd have chuckled at such comments and passed on with a grin. But fairly recently, I came across an example of the practice that jerked me out of my complacency.
Two of my engineers -- call them John and Steve -- had gotten into a severe disagreement about how to handle a particular aspect of the communications interface between their programs. As group leader, I had to mediate, and it was in the nature of the dispute that one or the other of them had to "lose." As John had already written a solution to the problem for his side that embodied his preference, I wheedled Steve into accepting the fait accompli and implementing a conforming solution in his program. He accepted my decision, but to say the least, he wasn't happy about it.
(What is it with software and ego? After forty years in this trade, I still don't get it.)
Well, shortly thereafter, Steve left my group. In the sweet rushing fulless of time it became necessary to make changes to his program. As all my people were up to their eyelashes with work, I took the responsibility onto my own shoulders, and resolved to learn Steve's rather complex program as thoroughly as possible.
When I came to the two segments of Steve's code where he'd implemented John's preferred solution to their mutual problem, I was stunned by the comments in the code. Mind you, Steve isn't a happy commenter; indeed, his stuff tends not to be commented at all. But my oh my, did he ever comment those two segments.
The thrust of those comments was highly uncomplimentary to John. Offensive in several dimensions. And they went on and on and ON...
And so, I've become an enforcer of "structured English" commentary. Among its other virtues, it's entirely free of:
- adjectives,
- adverbs,
- similes,
- metaphors,
- idioms,
- imagery,
- Anglo-Saxon monosyllables for body parts, excrement, and the procreative act,
- and references to the marital state of other engineers' parents.
My engineers think I'm an obsessive. So be it.
(This message is programming you in ways you cannot detect. Be afraid.)
-
Comments are intended to clear up unclear code. Code should not be unclear because it is badly written, but because the problem it solves is difficult and requires some specific knowledge. That's where commenting should be used. As such each line of comment should be treated like regular code that needs to be maintained. For example, if you change a bit of code that is commented you should check if the comment still matches the code. The less you need to maintain the better, so you best use comments only when they are really necessary (or rather, when you think they are necessary, it's a personal matter). If you comment to much or to obvious comments are distracting and are a waste of digital ink and paperspace and only increase scrolling time. I've written a little tip on writing good comments (or at least what I think are good comments). You might want to check it out: Write comments that matter[^]
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}Code should not be unclear. Not even for complicated problems. If it's unclear, it needs refactoring until it becomes clear. There are extremely rare cases when a line or a small number of lines look awkward - most often workarounds for library bugs or the like. A comment in such case is OK, to explain the implementation awkwardness, but IMO that's about it. There's another issue about commens. Some people try to add enough comments to make the design/architecture clear from comments. That's IMO a bad idea. Usually the architecture is an issue at a level higher than the compilation unit, having comments at that level won't help.
-
What are the general thoughts and/or examples of 'working blue' in code comments? My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree (e.g. "not professional", etc., like devs tend to be "professional" anyway). For example, if I write a particularly kludgy piece of code (which is most of it :~), then I'm fond of comparing it to horse excrement, etc. Not only does it alert me and anyone else as to what's up, it also highlights that I'm aware it sucks and that it's okay to have a bit of sense of humor about it, etc.
Completely agree: even program itself is written NOT FOR CPU, but for us, humans! And as in verbal conversation, you express yourself according to your emotions. Why comment is an exception? If I hate MS for idiotic "if (myWindow.ShowDialog() == true)" why I cannot say it? (if you didn't catch the point, ShowDialog() now returns.... absolutely stupid "bool?" type!!) With emotions, jokes, etc we say our followers "hey, it's not only 0/1, it's our thoughts, dude!". :)
-
Time was, I'd have chuckled at such comments and passed on with a grin. But fairly recently, I came across an example of the practice that jerked me out of my complacency.
Two of my engineers -- call them John and Steve -- had gotten into a severe disagreement about how to handle a particular aspect of the communications interface between their programs. As group leader, I had to mediate, and it was in the nature of the dispute that one or the other of them had to "lose." As John had already written a solution to the problem for his side that embodied his preference, I wheedled Steve into accepting the fait accompli and implementing a conforming solution in his program. He accepted my decision, but to say the least, he wasn't happy about it.
(What is it with software and ego? After forty years in this trade, I still don't get it.)
Well, shortly thereafter, Steve left my group. In the sweet rushing fulless of time it became necessary to make changes to his program. As all my people were up to their eyelashes with work, I took the responsibility onto my own shoulders, and resolved to learn Steve's rather complex program as thoroughly as possible.
When I came to the two segments of Steve's code where he'd implemented John's preferred solution to their mutual problem, I was stunned by the comments in the code. Mind you, Steve isn't a happy commenter; indeed, his stuff tends not to be commented at all. But my oh my, did he ever comment those two segments.
The thrust of those comments was highly uncomplimentary to John. Offensive in several dimensions. And they went on and on and ON...
And so, I've become an enforcer of "structured English" commentary. Among its other virtues, it's entirely free of:
- adjectives,
- adverbs,
- similes,
- metaphors,
- idioms,
- imagery,
- Anglo-Saxon monosyllables for body parts, excrement, and the procreative act,
- and references to the marital state of other engineers' parents.
My engineers think I'm an obsessive. So be it.
(This message is programming you in ways you cannot detect. Be afraid.)
Sounds familiar and I'm happy that Steve left this slough. First of all, in project there is no "looser" side and cannot be at all. Only strictly technical decisions. Judging on that: "As John had already written a solution to the problem..." I say: YOU is a problem since you based your decision not on a tech facts, but just "it's already done by John". Stupid as an arse. But you HAD a chance to clean your f** up: when you saw Steve is not happy, what you did? Did you ask him why? Did you get tech. reasons? Did you compare his vision with John's? Sure not - you just said "accept this sh** and make same fetid copy". TWICE you're stupid as a manager and a technician. People "is not happy" not because NIH, but because they have technical knowledge what is good/bad. You ignored this knowledge and... viola - you LOST technicaly wisdom person. Because if he was just stupid newbie, he'll never left the team. Congrats.
-
What are the general thoughts and/or examples of 'working blue' in code comments? My thought is that, as the end user of our product never sees the comments, then it's whatever, but some do not agree (e.g. "not professional", etc., like devs tend to be "professional" anyway). For example, if I write a particularly kludgy piece of code (which is most of it :~), then I'm fond of comparing it to horse excrement, etc. Not only does it alert me and anyone else as to what's up, it also highlights that I'm aware it sucks and that it's okay to have a bit of sense of humor about it, etc.
I find that in .NET Windows Forms controls there are a lot of things that you need to do in a particular order to make events trigger the way you want, and some are not so clear as to why. There have been a number of times when the solution I found online is "this is how I did it but I don't know why". For a handful of these solutions, the consensus is that it's either a bug in the .NET Framework, Visual Studio, or at least a poor inconsistency in Microsoft's design or implementation. These are the ones I comment with things like: "This is the ghetto way to get around Microsoft's broken development environment." This way I know that if I try to play with it in the future, it may not be something I'm doing wrong and it just makes no sense but "you do it this way."