c99/c++ localised variable definition

John Baldwin jhb at FreeBSD.org
Wed Feb 2 14:18:20 PST 2005


On Tuesday 01 February 2005 06:46 pm, Paul Richards wrote:
> On Tue, Feb 01, 2005 at 03:04:37PM -0800, John-Mark Gurney wrote:
> > Paul Richards wrote this message on Tue, Feb 01, 2005 at 19:04 +0000:
> > > On Tue, Feb 01, 2005 at 10:06:24AM -0800, John-Mark Gurney wrote:
> > > > Paul Richards wrote this message on Mon, Jan 31, 2005 at 10:26 +0000:
> > > >
> > > > [...]
> > > >
> > > > > I think the loop usage though is one clear example where it is
> > > > > clearer. I think there are others as well; where the usage of the
> > > > > variable is clearly localised it is much easier to see a local
> > > > > definition than to have to jump back and forth to find out what
> > > > > variables are.
> > > >
> > > > I personally think it isn't.  One thing that I do in python all to
> > > > regularly (because it lacks variable declarations), is attempt to do:
> > > > 	for i in foo:
> > > > 		for j in bar:
> > > > 			for i in baz:
> > >
> > > That would work fine with c99.
> >
> > Depends upon your definition of working fine.. :)  it doesn't work fine
> > if you do:
> > 	for i in foo:
> > 		for j in bar:
> > 			for i in baz:
> > 				pass
> > 		print i
> >
> > When the print i is suppose to return the element from foo, not baz,
> > because you later added baz because of fixing another bug..
>
> That's true. What's starting to strike me as odd about this thread is
> that all the counter examples are about doing really dumb things. If
> you're a second rate coder who has a tendency to do dumb things then
> there's really no helping you no matter what the style is.
>
> Surely the issue should be, if you're a good coder and you adhere
> to the adopted style, which style is more likely to result in
> maintainable code.

Having a different person (!author) come back to fix a problem or add a new 
feature to old code is not a "dumb" thing, and it would be fairly easy to 
overlook some details when doing that sort of thing.  I think the current 
style is fine as it is with its current 100+ maintainers vs. elegance bias.

-- 
John Baldwin <jhb at FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org


More information about the freebsd-arch mailing list