 |
|
 |
Definitely above. The point is that a coder can come along later and read the comment first (understand what to expect) and then read the code.
Besides, now it's the convention. To use something else would likely lead to confusion.
Chris.
|
|
|
|
 |
|
 |
Above...unless you really don't like the person who will be maintaining the code.
|
|
|
|
 |
|
 |
I have a habit of putting comments to the right of the code.
Init();
Probably a habit leftover from my assembler days. Which would be just yesterday, in fact.
|
|
|
|
 |
|
 |
As someone who has only taken a few programming classes, and learned everything else on my own my opinion may be a bit skewed.
I prefer the comments above the code for two reasons. First I have learned a lot from studying other peoples code and having the comments above the code helps me follow along and figure out what they are doing and then how they are doing it.
Second in my own code it helps me to go back later and kind of follow the logic of what I am trying to do so I can go back later to see if I missed something. Kinda of a "Do this, like this, then do that, like this . . ."
This probably isn't as important for most of you but as someone who doesn't code for a living, but has to code to make their living it can be such a big help.
T
|
|
|
|
 |
|
 |
Having both taught computer programming and done it for a living, I find that comments serve two distinct purposes. In the classroom, a comment explains "here is what this code does"; because, when teaching, you introduce an idea and then you explain it. It is appropriate to put such comments immediately following the line of code, but only for didactic purposes. In the production world, a comment explains "here is what this code is for"; and should go above the code (or, if very brief, next to it).
|
|
|
|
 |
|
 |
i like the VS XML generating comments - which go above.
|
|
|
|
 |
|
 |
I always defer to my favorite software book Code Complete for these kinds of questions. McConnell spends a whole chapter talking about best practices in writing comments. (This may seem silly to some, but if you read the book, it makes a TON of sense.) Chapter 32 states plainly "Use comments to prepare the reader for what is to follow", and explains the well-established convention of putting comments above the code it's documenting.
Further (and this is the fun part you can show your professor), he claims "This idea isn't always taught in programming classes, but it's a well-established convention in commercial practice."
Well-established conventions, until there is a clear technical reason to do otherwise, should be followed!
Also, there has been some discussion hinting that well-crafted code should not need comments. My thought is all about how fast you can look at code to quickly understand what it's supposed to do. Your brain doesn't waste time translating variable names (even if they're well named), doing math, finding control loop conditions, etc.
Stuart
|
|
|
|
 |
|
 |
A couple of lines for general explanation above the code block, and short 2 or 3 word comments at the end of appropriate lines to explain what a particular variable or called function is for. Always worked for me.
|
|
|
|
 |
|
 |
Personally, my comments generally come before the code, but it's because of the way I code. I don't set out to write comments; rather, as I enter a new conceptual block, I find that it helps clear my mind to write a quick explanation of what I'm going to do. Then I find it easier to focus on what needs to be done within the conceptual block. Thus, the comments I write actually direct the code, rather than the other way around.
I don't need to go back over the code and add comments this way. Basically, if there's a comment in the code, it's because it was needed to write the code; if there's not, it's because the conceptual block was straight-forward enough that this guide wasn't necessary for my initial thoughts.
I suppose you could say my coding style is self-commenting. Or is my commenting style self-coding?
|
|
|
|
 |
|
 |
Above the code that implements it is best. That allows the reader to go from generalitites to specifics by reading top to bottom, just like an outline, or a story, or any other type of explanatory writing.
I think you should your the entire class to turn in an assignment with the comments below the code they comment. They can't mark down for it since the professor provides examples comemnted that way. If they actually read your source code, they'll probably try to mark it down though.
patbob
|
|
|
|
 |
|
 |
Now, if only I could sing, this[^] would be the gig to go for.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
 |
|
 |
Just walk this way...
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
 |
|
 |
You've always been a bit of a big mouth Vilmos.
"People who don't like their beliefs being laughed at shouldn't have such funny beliefs." ~ Anon
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
Currently reading: 'The Greatest Show on Earth', by Richard Dawkins.
|
|
|
|
 |
|
 |
Who knows, maybe he is Tyler made for the job.
//L
|
|
|
|
 |
|
|
 |
|
 |
It's good to see you're Back in the Saddle.
//L
|
|
|
|
 |
|
 |
I can't. I found love in an elevator.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
 |
|
 |
Pete O'Hanlon wrote: I found love in an elevator.
I did that once, but it didn't last. Too many ups and downs.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
 |
|
 |
Last time I would walk this way, was because I found love in an elevator.
Silver member by constant and unflinching longevity.
|
|
|
|
 |
|
 |
"but they hope to continue with a new frontman"
[sarcasm] One imagines that would be a huge success. [\sarcasm]
|
|
|
|
 |
|
 |
As I'm sure most people have noticed, today is the 11th November, Armistice Day. It has just been 11:00 in the UK, and I stopped to observe the two minutes silence. It occured to me that, at least in my office, I was the only who did.
Does anyone else here stop for two minutes at 11:00, whenever it reaches that time for you? I know we used to do it every year at school, not enforced, but a case of 'if you don't want to observe it, respect those who do', but I've noticed a lot of people don't bother once they've left.
|
|
|
|
 |
|
 |
As an Ex-Squaddie I always observe it.
------------------------------------
In science, 'fact' can only mean 'confirmed to such a degree that it would be perverse to withhold provisional assent.' I suppose that apples might start to rise tomorrow, but the possibility does not merit equal time in physics classrooms. Stephen J Gould
|
|
|
|
 |
|
 |
The whole office here stopped for two minutes, whether they would have all done it if there hadn't been an announcement remains unknown.
I always stop for two minutes, like you I used to in school and haven't stopped.
- Rob
|
|
|
|
 |
|
 |
I admit there wasn't an announcement made here...
|
|
|
|
 |
|
 |
Incidentally, first armistice day without a WWI Veteran.
They have all gone now, it is history.
------------------------------------
In science, 'fact' can only mean 'confirmed to such a degree that it would be perverse to withhold provisional assent.' I suppose that apples might start to rise tomorrow, but the possibility does not merit equal time in physics classrooms. Stephen J Gould
|
|
|
|
 |