|
I'm a big fan of comments and was going to vote for them, but I spoke to another developer here and changed my vote to prefer understandable code.
His point? The best commenting in the world is no use if it's not in a language you understand.
(In his previous job with a games company, as an English speaker, he had to work with code commented in Japanese.)
Gavin Greig
"Haw, you're no deid," girned Charon. "Get aff ma boat or ah'll report ye."
Matthew Fitt - The Hoose O Haivers: The Twelve Trauchles O Heracles.
|
|
|
|
|
Gavin Greig wrote:
His point? The best commenting in the world is no use if it's not in a language you understand.
You can say the same for code, though, too. I've seen code with variable names in Russian (and I'm not fluent in Russian, about all I know is "nyet". )
"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
|
|
|
|
|
Navin wrote:
You can say the same for code, though, too. I've seen code with variable names in Russian
LOL
I once new a young programmer fluent in Russian that added all his comments etc in Russian as a joke.
When he died in a motor-bike accident the company employing him was really shagged.
Regardz
Colin J Davies
* WARNING * This could be addictive The minion's version of "Catch "
It's a real shame that people as stupid as you can work out how to use a computer. said by Christian Graus in the Soapbox
|
|
|
|
|
Code may have unhelpful variable names (and I guess names in a language you don't understand would fall into this category) but at least you have other clues as to what's going on - you may know whether the code works or doesn't, you can watch what it's doing, and you will be familiar with most of the syntax even if you can't read the variable names. With "easily understandable code" - primarily well laid out, if the human language isn't a common factor - this will be easier.
With foreign language comments, you don't have the same clues to help you out, so if you can only have one of easily understandable code or good comments, the easily understandable code wins.
I've worked with extremely horrible variable names in MUMPS (Massachussets General Hospital Utility Multi-Programming System, a programming language of horror) and while I would never want to go back, it is possible to make something of the gibberish so long as you have the syntax to help out.
Gavin Greig
"Haw, you're no deid," girned Charon. "Get aff ma boat or ah'll report ye."
Matthew Fitt - The Hoose O Haivers: The Twelve Trauchles O Heracles.
|
|
|
|
|
|
Not sure what the int is supposed to be
Matt Newman Sonork: 100:11179
"Whoa, that ruled! What function key do I gotta press to get that to happen again?" - Strong Bad
|
|
|
|
|
Nishant S wrote:
//remember to add code to check g_tot later //sorry - going out for coffee now/ so cannot do it
Oh man, I'm dying to put a comment like that in *my* code somewhere now, too.
<br />
"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
|
|
|
|
|
How about this one:
<br />
"Sucks less" isn't progress - Kent Beck [^]
Awasu 1.1.1 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
OK, where's the :projectile-regurgitation: emoticon?
Oh well, I guess will have to do.
Software Zen: delete this;
|
|
|
|
|
..but at least if you have understandable code, people can put their own comments in.
Really, though, people put appallingly few comments in their code these days.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Its like a silent rebellion from the incoming generation
Matt Newman Sonork: 100:11179
"Whoa, that ruled! What function key do I gotta press to get that to happen again?" - Strong Bad
|
|
|
|
|
I submit...
... code that is not commented cannot be easily understood.
|
|
|
|
|
I beg to differ.
Code can be written in such a way that comments aren't necessary for it to be easily understandable. Not always - but enough times that comments can be minimised.
Whether or not there is ever actually a case for minimising comments based on how neat the code is is debatable. Clearly having both comments and understandable code is ideal but I've been reading a lot of code lately that is either one or the other (unfortunately some of it is mine).
cheers,
Chris Maunder
|
|
|
|
|
While it is certainly true that good coding style and well-chosen names (to name just two techniques) help a lot in making code readable, it is also true that only mickey-mouse projects can be understood without comments, diagrams, and documentation.
Projects that take several man-years to develop and contain dozens of classes simply cannot be understood by good coding practise alone.
Documentation, model diagrams, and comments are paramount. The measure is not whether the author finds the code self-explainatory, it is whether a fellow developer can navigate and take over control eventually.
After all, when the more tedious maintenance work starts, you will want to move on to a new project, won't you
Bernd
|
|
|
|
|
Out-of-Date documentation can be worse than no-documentation at all. The problem I have found on previous projects is that the more detailed the code design documentation (ie. physical design), the more often a paper-based document will become obsolete.
I am finding XML Commenting and NDoc to be really useful for teaching developers to improve the commenting of their code, as well as being able to generate up-to-date documentation that stays current with the code.
|
|
|
|
|
Chris Beckett wrote:
Out-of-Date documentation can be worse than no-documentation at all.
Nothing worse than wrong directions.
leppie::AllocCPArticle("Zee blog");
|
|
|
|
|
Chris Beckett wrote:
Out-of-Date documentation can be worse than no-documentation at all.
I agree 100%. I see this a lot with open source projects.
John
|
|
|
|
|
You hit the nail on the head when a “fellow developer can navigate and take over control”.
For those of us who have worked on projects with several developers, the true test of ‘understandability’ is when another programmer can easily take up where you left off.
I personally prefer good coding with just enough concise commenting to alleviate the question: What was he thinking?!?
Wade
|
|
|
|
|
I agree. The only place I've seen lately where comments are mandatory regardless of the 'readability' of the underlying code is in assembly language. I'm maintaining an OS/2 device driver (don't ask; it isn't pretty) that is ~18,000 lines of assembly language. The source is probably 65% comments. It's just not possible to maintain this thing without verbose, inline documentation.
Software Zen: delete this;
|
|
|
|
|
Our assembly system is setup with a 6100 line limit.
The first thing to go is comments. A typical line might get some inititals and a date to let me know who made a change and when, with a 1 line(71 char.) comment at the top stating what their change was about. The rest is mostly walking through by hand.
It sucks!
"Manifest plainness, embrace simplicity, reduce selfishness, have few desires." -- Lao Tzu BW
|
|
|
|
|
Have you considered writing a preprocessor for your assembly system that would strip comments out?
Software Zen: delete this;
|
|
|
|
|
I've thought about it, but I'm not handling the code for our editor anymore. I seem to remember hearing complaints that line numbers wouldn't match, or some other lame thing.
"Manifest plainness, embrace simplicity, reduce selfishness, have few desires." -- Lao Tzu BW
|
|
|
|
|
Jim A. Johnson wrote:
code that is not commented cannot be easily understood.
Well if you embed all comments within variable names it is
Matt Newman Sonork: 100:11179
"Whoa, that ruled! What function key do I gotta press to get that to happen again?" - Strong Bad
|
|
|
|
|
'nuff said
God, I pity me! - Phoncible P. Bone
If I end up Windows ME someone is going to be hurting. - One of the answers to a question for What OS are you
|
|
|
|
|
...to get awfully unfunny if all 400k CPians want their shot at the CListCtrl joke
Paul Watson Bluegrass Cape Town, South Africa
Crikey! ain't life grand?
|
|
|
|