← Back to team overview

kicad-developers team mailing list archive

Position for variable declaration (trivial style issue)

 

During today merge I noticed that some 'new style' variable
declarations:

function blah()
{
int a = 0;

// code 

int b = stuff_from_a(a);

// code
}

were converted to the traditional:

function blah()
{
int a = 0;
int b;

// code

b = stuff_from_a(a);

// code
}

My preference is to try to restrict the scope of a variable (i.e.
declare it at the initialization point); the 'old' style could have the
advantage of seeing from the start all the stuff used. Of course, no
RAII or collaterals from cons/des, the semantic should be the same (I'd
say the compiler would optimize both of these in the same way).

Is the traditional style preferred for some reason? Just to tune my
writing style

-- 
Lorenzo Marcantonio
Logos Srl


Follow ups