|
Hmmm. I tend to use K&R style braces:
if (...) {
}
for (..) {
}
but I do tend to include a fair number of blank lines in my code. I've found it's easier for me to read, with blank lines breaking things up every so often. One thing I've always disliked, however, is the extra spaces people put before and after the parentheses in a function call:
SomeFunction ( argument1, argument2 );
Software Zen: delete this;
|
|
|
|
|
|
Gary R. Wheeler wrote:
if (...) { //... } for (..) { //... }
Agreed.
Gary R. Wheeler wrote:
SomeFunction ( argument1, argument2 );
Definitely agreed!
The kindest thing you can do for a stupid person, and for the gene pool, is to let him expire of his own dumb choices.
[Roger Wright on stupid people]
|
|
|
|
|
If you make easily understood source code then the programmer and the viewer will understand it better and should just about speak for itself.
But then again if you comment ALOT then you probably won't find alot of things out and you are spending a huge amount of commenting which when compiling the program will be useless and if you spent more time making and improving better code, then your program, (I think), would be alot better.;)
Don't get me wrong, you should comment it but as little as possible so you or someone else looking at it should understand what it's supposed to do.;P
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
See my post below - I partly disagree. Well written code can tell you what. But you need comments, or knowledge of what your program does, to decipher why.
Comments are invaluable when dealing with an API from a large, well-known software corporation that occasoinally has bugs or undocumented "features" that have non-obvious workarounds.
"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
|
|
|
|
|
If you recall I didn't say that comments were totally bad if you had read all of it.
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
.. but you get none !
:evil:
i'm only pointer to myself
|
|
|
|
|
More often than not, though, you're right... :puke:
"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
|
|
|
|
|
That's the problem with surveys like this. "Which would you rather lose.. your right hand or your left?"
Good code is written to be understandable, and is well commented.
|
|
|
|
|
"If you can say it in code, do so. Otherwise, say it in a comment."
He made this statement in a C++ class I took from him. This comment made a profound change in how I documented my code. I used to comment everything, whether it really needed it or not. Now, my commenting is very context dependent. Header files I tend to comment fairly well, providing descriptions for methods and their arguments when they are private. Sources I comment whenever an algorithm is non-trivial, and to partition major pieces.
The end result is that my code is more concise, easier to read, and I'm more productive.
Software Zen: delete this;
|
|
|
|
|
I just finished a 2500 line C project. 20 Comment lines total. Why comment when code is readible?
Cheers
PS: one method comment is:
//if you wanna figure out whats going on here, set up a truth table
leppie::AllocCPArticle("Zee blog");
|
|
|
|
|
2500 lines? That's all? Small-timer.
"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
|
|
|
|
|
Gary Wheeler wrote:
Sources I comment whenever an algorithm is non-trivial, and to partition major pieces.
OR whenever you use a library function/API tha thas a bug, and you have to do something contrary to the documentation (or the documentation has a bug) to get around it.
"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
|
|
|
|
|
That's a case where the code can't 'say it' clearly; a comment is called for.
Software Zen: delete this;
|
|
|
|
|
When its good, its out of this world...
When its bad, its better than nothing...
Steven J. Ackerman, Consultant
ACS, Sarasota, FL
http://www.acscontrol.com
steve@acscontrol.com
sja@gte.net
|
|
|
|
|
And not having any makes you cranky?
Software Zen: delete this;
|
|
|
|
|
... and who will be maintaining it. If the purpose of the code is clear (e.g., you know it's a GUI app that does blah), then well-written code is better than comments.
However if it does something that someone maintaing the code might not easily understand (e.g., drivers, system code, or mathmatecal solvers), then comments are better, because if the reasons behind doing something aren't understood, then the best written code in the world won't help.
So I guess in summary: well-written code can say what is being done, but only comments can say why it is being done.
However more often than not, it's probably the "what" that's important.
"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
|
|
|
|
|
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.
|
|
|
|