 |
|
 |
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).
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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? 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
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"
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
Last time I would walk this way, was because I found love in an elevator.
Silver member by constant and unflinching longevity.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
"but they hope to continue with a new frontman"
[sarcasm] One imagines that would be a huge success. [\sarcasm]
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
We observed 2 minutes silence at 11:00 in my office, although I could still hear mouse clicks and typing sounds. To be honest, I wouldn't have remembered if my boss hadn't made an announcement.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
tufkap wrote: although I could still hear mouse clicks and typing sounds
That's where a lump hammer is needed, one swift blow to the fingers should prevent it happening again.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I was appalled at the number of people who carried on typing during the silence. We had a signal that it was starting so there was no excuse whatsoever just a complete lack of respect.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Company wide silence here. It wasn't announced in our office (the loudspeaker system's bust here), but we knew it was 11am.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |