[16697] in Kerberos_V5_Development
Re: Coding practices proposals
daemon@ATHENA.MIT.EDU (Ken Raeburn)
Thu Mar 17 23:44:59 2011
Mime-Version: 1.0 (Apple Message framework v1082)
From: Ken Raeburn <raeburn@mit.edu>
In-Reply-To: <tsltyf1xt1o.fsf@mit.edu>
Date: Thu, 17 Mar 2011 23:44:57 -0400
Message-Id: <A2433AE3-E0A2-486D-B93A-E900068E06C0@mit.edu>
To: "krbdev@MIT.EDU List" <krbdev@mit.edu>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: krbdev-bounces@mit.edu
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.
Ken
_______________________________________________
krbdev mailing list krbdev@mit.edu
https://mailman.mit.edu/mailman/listinfo/krbdev