Click here to Skip to main content
15,915,160 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
jschell13-Feb-14 9:07
jschell13-Feb-14 9:07 
GeneralRe: Coding Standards Pin
Matt U.13-Feb-14 10:37
Matt U.13-Feb-14 10:37 
GeneralRe: Coding Standards Pin
Dennis E White13-Feb-14 12:52
professionalDennis E White13-Feb-14 12:52 
GeneralRe: Coding Standards Pin
jschell14-Feb-14 10:06
jschell14-Feb-14 10:06 
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 
I see very little - if any - benefit in declaring all local variables at the start of a method. To the contrary, it's bound to cause problems:

1. Variables that are being used much later may not have to be allocated at all, depending on the flow of control. You may end up spending resources and processing time for the initialization (and release) of data you never need! This is specifically true if you make a sanity check on the method arguments (which you alwys should) and go for a premature return.

2. When you maintain the code, it's often useful to see how a local variable has been initialized. This gets harder when the variables are grouped a long way up, and you can't see at a glance whether it's being changed between the declaration and the spot you're about to edit.

3. You shouldn't keep a hold on resources that you no longer need: the only way to reliably and maintainably (is that a word?) free up the resources required by a variable is declaring it within a code block. I even sometimes use a code block as a means to denote a specific variable's lifetime! You (or your manager) might consider this just as a'nice to have' feature, but it quickly becomes a necessity when you program concurrent threads using locks. There's no way in hell you're going to keep your locks over an entire method!

P.S.:
4. How do you do exceptions? I suspect your manager has never implemented a catch block, did he? D'Oh! | :doh:

5. Why do you think C++11 has been changed to end the lifetime of for loop counters at the end of the loop?
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)


modified 14-Feb-14 6:11am.

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 
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 

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.