[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: permit declaration after statement



On Mon, 28 Nov 2011, Ian Jackson wrote:
> Stefano Stabellini writes ("Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: 
> permit declaration after statement"):
> > I think it would make sense to add to the CODING_STYLE that variable
> > declarations shouldn't be mixed with code, unless part of a macro or an
> > alloca-like construct.
> 
> I think this is a silly rule.  In my proposed commit message I
> advanced three reasons for allowing declaration after statement:
> 
> > >  * It allows variables to be more often initialised as they are
> > >    declared, thus reducing the occurrence of uninitialised variable
> > >    errors.
> > > 
> > >  * Certain alloca-like constructs (arrays allocated at runtime on the
> > >    stack) can more often be written without a spurious { } block.
> > >    Such blocks are confusing to read.
> > >
> > >  * It makes it easier to write and use macros which declare and
> > >    initialise formulaic variables and do other function setup code,
> > >    because there is no need to worry that such macros might be
> > >    incompatible with each other or have strict ordering constraints.
> 
> Of these the first two improvements would be banned by your proposed
> coding style rule.

Only the first would be banned, I am OK with making an exception for
alloca constructs and macros.


> I don't understand what the harm is in allowing declarations, with
> initialisation, freely mixed with code.


It makes the code harder to read;
it makes it more difficult to rearrange local variables in the future;
it makes it more difficult to see how much stack your function is using;
it makes it more difficult to realize if you can reduce the amount of
local variables you are using.

And it violates the current coding style.

I think that declaring variables at the beginning of the function is a
good programming practice in any language.

The three most important C codebases in the Xen project are: Linux,
Qemu and Xen. None of these allow mixing declarations and code, for a
good reason. I don't think libxl should have a different code style in
this regard, it would just be confusing.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.