Click here to Skip to main content
15,909,953 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Coding Standards Pin
Matt U.14-Feb-14 10:10
Matt U.14-Feb-14 10:10 
GeneralRe: Coding Standards Pin
_Maxxx_13-Feb-14 16:47
professional_Maxxx_13-Feb-14 16:47 
GeneralRe: Coding Standards Pin
Stefan_Lang14-Feb-14 0:03
Stefan_Lang14-Feb-14 0:03 
GeneralRe: Coding Standards Pin
Stefan_Lang13-Feb-14 23:58
Stefan_Lang13-Feb-14 23:58 
GeneralRe: Coding Standards Pin
User 754579914-Feb-14 3:54
User 754579914-Feb-14 3:54 
GeneralRe: Coding Standards Pin
agolddog14-Feb-14 4:11
agolddog14-Feb-14 4:11 
GeneralRe: Coding Standards Pin
Member 999720314-Feb-14 5:48
Member 999720314-Feb-14 5:48 
GeneralRe: Coding Standards Pin
Ralph Little14-Feb-14 6:10
Ralph Little14-Feb-14 6:10 
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 Big Grin | :-D
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.
GeneralRe: Coding Standards Pin
Kirk 1038982114-Feb-14 8:12
Kirk 1038982114-Feb-14 8:12 
GeneralRe: Coding Standards Pin
Daniel R. Przybylski14-Feb-14 8:21
Daniel R. Przybylski14-Feb-14 8:21 
GeneralRe: Coding Standards Pin
Matt U.14-Feb-14 10:08
Matt U.14-Feb-14 10:08 
GeneralRe: Coding Standards Pin
James Lonero17-Feb-14 5:19
James Lonero17-Feb-14 5:19 
GeneralIs anyone else... Pin
Fredrik Bornander13-Feb-14 2:53
professionalFredrik Bornander13-Feb-14 2:53 
GeneralRe: Is anyone else... PinPopular
Duncan Edwards Jones13-Feb-14 3:03
professionalDuncan Edwards Jones13-Feb-14 3:03 
GeneralRe: Is anyone else... Pin
Nicholas Marty13-Feb-14 3:39
professionalNicholas Marty13-Feb-14 3:39 
GeneralRe: Is anyone else... Pin
Duncan Edwards Jones13-Feb-14 4:13
professionalDuncan Edwards Jones13-Feb-14 4:13 
GeneralRe: Is anyone else... Pin
Nicholas Marty13-Feb-14 4:22
professionalNicholas Marty13-Feb-14 4:22 
GeneralRe: Is anyone else... Pin
Richard Deeming13-Feb-14 3:09
mveRichard Deeming13-Feb-14 3:09 
GeneralRe: Is anyone else... Pin
Dinesh.V.Kumar13-Feb-14 3:12
Dinesh.V.Kumar13-Feb-14 3:12 
GeneralRe: Is anyone else... Pin
HobbyProggy13-Feb-14 3:49
professionalHobbyProggy13-Feb-14 3:49 
GeneralRe: Is anyone else... Pin
Nagy Vilmos13-Feb-14 3:10
professionalNagy Vilmos13-Feb-14 3:10 
GeneralRe: Is anyone else... Pin
Kornfeld Eliyahu Peter13-Feb-14 3:31
professionalKornfeld Eliyahu Peter13-Feb-14 3:31 
GeneralRe: Is anyone else... Pin
Richard MacCutchan13-Feb-14 4:37
mveRichard MacCutchan13-Feb-14 4:37 
JokeGETTING OLDER PinPopular
Vivi Chellappa13-Feb-14 2:27
professionalVivi Chellappa13-Feb-14 2:27 
GeneralRe: GETTING OLDER Pin
BillW3313-Feb-14 7:33
professionalBillW3313-Feb-14 7:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.