Coding practices proposals

Ken Raeburn raeburn at MIT.EDU
Thu Mar 17 23:44:57 EDT 2011

On Mar 17, 2011, at 18:48, Sam Hartman wrote:
> * If a pointer is going out of scope it seems reasonable to free. I
>  don't think we want to force things into top most scope just to clean
>  them up in a particular place

This I agree with.  If it doesn't make things confusing or inconvenient, I often prefer variable declarations in inner scopes not just to make the shorter lifetime more obvious to the reader, but also to avoid accidental re-use of an earlier value inside a loop if a path is accidentally created through which reinitialization inside the loop is bypassed.

But gathering cleanup code in one place is one of those ways in which it can make things inconvenient.

> * If the value has fairly short life, for example it is an intermediate
>  used by one call.

I sort of agree with this... but then again, I might put the temporary and call into an inner block, for the more obvious scoping rather than as a control-flow construct, thus reducing it to a previously argued case. :)

Unless we switch to C99, the declarations have to live at the top of the block, so for some functions it may not be immediately obvious when the variable's lifetime is just one call, when the scope is much larger.


More information about the krbdev mailing list