|
There are always multiple views on this kind of thing.
Here's my 2 cents worth.
Excessive commenting is a plague in my view. They interrupt the natural flow of what might otherwise be beautiful code.
As a rule, I will take a functional block of code and block comment it in as much detail as I think is useful. The comment will usually be less about what it is doing than why and what for and any notes about anything strange/non intuitive that it is doing. But I'm really against small obvious comments with each and every line of code.
As for the variable thing, in previous C standards, top of the block declarations were the only option. In newer ANSI, I believe this has been relaxed although here we don't tend to use it.
At least in C++ you have the option of late declaration. For me, as an Eclipse user, pressing F3 to get to the declaration is second nature now and most decent development environments have such a facility. If you can't remember what the type is, a mouse hover will soon reveal that. Not so convenient for vi/emacs uses of course
I would note that putting the declaration of a variable at the point at which it is initialised/first used reduces the possibility of accidental use when uninitialised. It also guards against the abomination of using a single general-purpose variable (e.g. i) for everything in the function. It might be slightly more efficient (although most optimisers would be converting these general purpose items into registers anyway) it is always tempting the accidental use of whatever was left in there from the previous use. I prefer not to do this.
For a loop variable, declare it in loop scope, don't reuse the same variable all the time:
for (uint32_t loop = 0; loop < max; loop++) {} etc
In a block, declare it in block scope.
As I said, a lot of these general purpose items will be registers anyway.
|
|
|
|
|
Wow, some of the comments here against coding standards surprised me.
I am a huge fan of coding standards, and code reviews. Especially when everyone works on the software. But I started with professional Basic Plus (on a PDP/11), which required no indentation, so people did not do it. LOL. A 16 way If then statement without ANY indentation. Worse, one of the programmers actually removed MY indentation. He said if you can't read the code, you are not a real programmer.
We immediately adopted coding standards, and reviews. But pragmatically. Comments are OPTIONAL and NEVER increase the accuracy of code. But, in a review, ANY reviewer can request a comment clarifying a complex block of code. Or forcing a comment on a variable declaration whose usage must be understood.
Over the next few months, we noticed the rates of defects in the code were dropping. We also found we were all getting better at predicting problems just by reading the code.
So, I am all for coding standards and code reviews. But let me add, that ONLY to the degree that the rules make sense. One of the reasons to use a standard is that it is EASIER to teach a person to read structured code of ONE STYLE than to have to constantly switch styles. Most editors do the heavy lifting of formatting these days.
My only issue with the coding style you have described is that it requires USELESS comments.
Declaring variables at the top is required in other languages (Pascal/Delphi, COBOL). In C, I always liked blocked local variables.
So, while i understand your frustration, have you read "Code Complete" or "Writing Solid Code". One way to attack the problem, is to get your boss to read some of the modern books (you should read them first). On my teams, ALL developers are REQUIRED to read a batch of 6 books on their own time. This helps us all speak the same language and communicate better. Just a thought.
|
|
|
|
|
And I bet they completely ignore XML commenting and don't require it. (This does look like C#)
Declaring the variables at the top does sound reminiscent of C/C++.
One thing that drives me nuts is using #regions in C# to create a section for all of your fields, then another for delegates, then properties, then functions.... Sounds good until you have a data-object where each bit of data might have a field, an exposing property, and maybe an event or two to let people know when it's added/deleted/changed... and then someone wants to change or delete a property of the object and you have to go thru each region to find the methods and fields regarding that property.
|
|
|
|
|
They actually do require the #region separation. It's like this:
#region Variables
...
#endregion Variables
#region Fields
...
#endregion Fields
#region Properties
...
#endregion Properties
#region Constructors
...
#endregion Constructors
#region Methods
#region Private
...
#endregion Private
#region Protected
...
#endregion Protected
#region Public
...
#endregion Public
#endregion Methods
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Probably, your manager's main metric is lines of code (with the comments). The more lines, the more productive he (and you all) look. If this is the case, then your manager needs a serious education in modern software design(including coding practices).
If you really want to inspire your manager, write a full length paragraph for each line of code. (Pretend that you are writing software for the department of defense. They just love documentation, even if they don't understand what it does.)
|
|
|
|
|
...tempted to phone one of the phone numbers currently being spammed in the Q&A section just to see what it's all about?
One might be missing out on some valuable advice concerning black magic.
/Fredrik
|
|
|
|
|
hmmm - tempted to get my fax machine to dial it. Constantly.
|
|
|
|
|
Could get pretty expensive if it's premium number
|
|
|
|
|
..only if its not coded to disconnect the second the line is picked up.
|
|
|
|
|
already establishing the connection can charge you an initial fee. A longer call just gets increasingly more expensive.
It's like paying for a cab. You pay a base amount for the service and the more time that passes (or the greater the distance) the more expensive it gets.
|
|
|
|
|
Tempted to sign the number up to every cold-call scammer and double-glazing salesman I can find.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
ha thats a nice thing to do!! and a nice way to take revenge ..lets see if the magician can cast a spell on the salesmen...
|
|
|
|
|
You need to roll your willpower and your castability as a d6
i do that for you , willpower 4 and castability of 3 makes a 7d6
/roll 7d6
... rolling {1, 3, 5, 5 , 4, 1, 4} >= 5 = 2 successes
I'm sorry he defended your skill with 3 successes.
Please withstand the mana drain now
if(this.signature != "")
{
MessageBox.Show("This is my signature: " + Environment.NewLine + signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|
|
You do it first!
speramus in juniperus
|
|
|
|
|
Yes - to do some Black Magic...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
I tried it, and the Swami's voice chanted "great power will be yours o enlightened child of the forums". And lo, it came to pass[^].
Veni, vidi, abiit domum
|
|
|
|
|
A distraught senior citizen phoned her doctor's office.
"Is it true," she wanted to know, "that the medication you prescribed has to be taken for the rest of my life?"
"Yes, I'm afraid so," the doctor told her.
There was a moment of silence before the senior lady replied, "I'm wondering, then, just how serious is my condition, because this prescription is marked 'NO REFILLS'.."
***********************
An older gentleman was on the operating table awaiting surgery and he insisted that his son, a renowned surgeon, perform the operation.
As he was about to get the anesthesia, he asked to speak to his son.
"Yes, Dad , what is it?"
"Don't be nervous, son; do your best, and just remember, if it doesn't go well, if something happens to me, your mother is going to come and live with you and your wife....."
~~~~~~~~~~~~~~~~~
Aging:
Eventually you will reach a point when you stop lying about your age and start bragging about it. This is so true. I love to hear them say "you don't look that old."
---------------------------------
The older we get, the fewer things seem worth waiting in line for. (Mostly because we forgot why we were waiting in line in the first place!!)
---------------------------------
Some people try to turn back their odometers.
Not me!
I want people to know why I look this way.
I've traveled a long way and some of the roads weren't paved.
********************
When you are dissatisfied and would like to go back to youth, think of Algebra.
-------------------------------
One of the many things no one tells you about aging is that it is such a nice change from being young.
~~~~~~~~~~~
Ah, being young is beautiful, but being old is comfortable.
*********
First you forget names, then you forget faces.
Then you forget to pull up your zipper...
It's worse when you forget to pull it down.
````````````````
Two guys, one old, one young, are pushing their carts around Wal-Mart when they collide.
The old guy says to the young guy, "Sorry about that. I'm looking for my wife, and I guess I wasn't paying attention to where I was going."
The young guy says, "That's OK, it's a coincidence. I'm looking for my wife, too... I can't find her and I'm getting a little desperate."
The old guy says, "Well, maybe I can help you find her... what does she look like?"
The young guy says, "Well, she is 27 yrs. old, tall, with red hair, blue eyes, is buxom...wearing no bra, long legs, and is wearing short shorts. What does your wife look like?'
To which the old guy says, “Doesn’t matter, --- let's look for yours."
*********************
(And this final one especially for me,)
"Lord, keep Your arm around my shoulder and Your hand over my mouth!"
**************************
Now, if you feel this doesn't apply to you . . . stick around awhile . . . it will!
|
|
|
|
|
One elderly lady was chatting with another. “My memory is poor Mildred, so I changed my password to “incorrect.” That way when I log in with the wrong password, the computer will tell me… “Your password is incorrect.”
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
|
I lurve #14!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Thought from the title it was going to be about poetry/Valentines Day.
Probably shouldn't have found this one[^] funny, but I did.
|
|
|
|
|
I wonder what the sign said?
|
|
|
|
|
Well it was Cardiff, so I'm going for this[^].
|
|
|
|
|
In Wales it wouldn't have the line through it and would be a triangle.
speramus in juniperus
|
|
|
|
|
"Warning: Strong storms may blow down shields!"
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|