From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 10:26:52 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8C8E516A4CE for ; Mon, 31 Jan 2005 10:26:52 +0000 (GMT) Received: from mx1.originative.co.uk (freebsd.gotadsl.co.uk [81.6.249.198]) by mx1.FreeBSD.org (Postfix) with ESMTP id EBA5443D4C for ; Mon, 31 Jan 2005 10:26:49 +0000 (GMT) (envelope-from paul@mx1.originative.co.uk) Received: from localhost (unknown [127.0.0.1]) by mx1.originative.co.uk (Postfix) with ESMTP id 81FA815583 for ; Mon, 31 Jan 2005 10:26:46 +0000 (GMT) Received: from mx1.originative.co.uk ([127.0.0.1])port 10024) with ESMTP id 07199-03 for ; Mon, 31 Jan 2005 10:26:30 +0000 (GMT) Received: by mx1.originative.co.uk (Postfix, from userid 1000) id 9AFE515579; Mon, 31 Jan 2005 10:26:30 +0000 (GMT) Date: Mon, 31 Jan 2005 10:26:30 +0000 From: Paul Richards To: arch@freebsd.org Message-ID: <20050131102630.GJ61409@myrddin.originative.co.uk> References: <20050128173327.GI61409@myrddin.originative.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050128173327.GI61409@myrddin.originative.co.uk> User-Agent: Mutt/1.5.6i Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 10:26:52 -0000 On Fri, Jan 28, 2005 at 05:33:27PM +0000, Paul Richards wrote: > People used to programming in C++ or Perl (and many others) are used > to defining variables as near to use as possible. This have never been > possible before in C, but now with c99 it is. Ok, to sum up the discussion then: 1) In the kernel the issue of stack usage is a relevant consideration against adopting the new style. 2) Sprinkling definitation all over the place may not be a postitive step forward, but in practice this is already occuring with local scope creationg. 3) Usage in for loops may be more useful than other uses. 4) The new style has benefits for const usage and initialisation. There was one strong dissenting comment from DES with regard to sloppy programming technique but I think sloppy programming is an issue anyway and the best way to counter it is to enforce adherence to style(9).The issue under consideration is whether we can improve some aspects of style given the new syntax available. I agree with the issue that sprinkling definitions arbitrarily all over the code does not aid readibility or reliability of the code. 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'd suggest that we allow the use of c99 variable definitions in a limited area of userland on a trial basis in order to gain some experience of whether we do or do not gain anything from their usage. The conservatives might feel that FreeBSD is not the place for such research but I disagree, I think that's exactly the sort of thing FreeBSD should be doing. > I noticed when trying to use this feature that we're not running > the compiler with c99 fully supported yet so I guess that's perhaps > the first step to discuss. This wasn't really discussed, I think at the very least we should enable c99 as the base system compiler so that 1) we can be sure our code works with c99 and 2) it's available as the default compiler for third party use. At the risk of really throwing the cat amongst the pigeons, I compiled cat with c++ over the weekend just to see if the better(different) checking turned anything up and I found a couple of loose casting situations. It got me wondering whether a c++ compilation option wouldn't be a beneficial way of linting the code. -- Paul Richards From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 12:26:11 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3CCD716A4CE for ; Mon, 31 Jan 2005 12:26:11 +0000 (GMT) Received: from gizmo03ps.bigpond.com (gizmo03ps.bigpond.com [144.140.71.13]) by mx1.FreeBSD.org (Postfix) with SMTP id B55A443D31 for ; Mon, 31 Jan 2005 12:26:09 +0000 (GMT) (envelope-from andrew@areilly.bpc-users.org) Received: (qmail 4708 invoked from network); 31 Jan 2005 12:26:07 -0000 Received: from unknown (HELO PSMAM03.bigpond.com) (144.135.25.75) by gizmo03ps.bigpond.com with SMTP; 31 Jan 2005 12:26:07 -0000 Received: from cpe-138-130-184-160.nsw.bigpond.net.au ([138.130.184.160]) by PSMAM03.bigpond.com(MAM REL_3_4_2a 89/57423700) with SMTP id 57423700; Mon, 31 Jan 2005 22:26:07 +1000 Received: (qmail 83730 invoked by uid 1000); 31 Jan 2005 12:26:09 -0000 Date: Mon, 31 Jan 2005 23:26:09 +1100 From: Andrew Reilly To: Paul Richards Message-ID: <20050131122609.GA83556@gurney.reilly.home> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050131102630.GJ61409@myrddin.originative.co.uk> User-Agent: Mutt/1.4.2.1i cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 12:26:11 -0000 On Mon, Jan 31, 2005 at 10:26:30AM +0000, Paul Richards wrote: > 3) Usage in for loops may be more useful than other uses. [snip] > 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'd just like to raise a dissenting voice to this particular point. I find the for-loop initialization syntax a pernicious source of errors, mainly because of the non-intuitive scope of the definition. I.e., it looks like it's equivalent to "int i; for (i = 0;;)" but it isn't. If you carelessly c++-ify a loop like: for (int i = 0; i < N; i++) { if (some_condition(i)) break; } do_something_with(i); /* use finishing index */ you can miss the fact that the value of i is used outside of the loop. The newly created scope for "i" shadows the presumably pre-existing definition of i at the top of the function, which is what do_something_with() gets to see. Const friendliness and some minor economy of thought are perhaps valid benefits of this style, but I don't think sufficient to change the style. Cheers, -- Andrew From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 12:36:18 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D5D0616A4CE for ; Mon, 31 Jan 2005 12:36:18 +0000 (GMT) Received: from critter.freebsd.dk (f170.freebsd.dk [212.242.86.170]) by mx1.FreeBSD.org (Postfix) with ESMTP id 404A143D48 for ; Mon, 31 Jan 2005 12:36:18 +0000 (GMT) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.13.1/8.13.1) with ESMTP id j0VCa9DH090393; Mon, 31 Jan 2005 13:36:09 +0100 (CET) (envelope-from phk@critter.freebsd.dk) To: Andrew Reilly From: "Poul-Henning Kamp" In-Reply-To: Your message of "Mon, 31 Jan 2005 23:26:09 +1100." <20050131122609.GA83556@gurney.reilly.home> Date: Mon, 31 Jan 2005 13:36:09 +0100 Message-ID: <90392.1107174969@critter.freebsd.dk> Sender: phk@critter.freebsd.dk cc: arch@freebsd.org cc: Paul Richards Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 12:36:19 -0000 In message <20050131122609.GA83556@gurney.reilly.home>, Andrew Reilly writes: >If you carelessly c++-ify a loop like: > > for (int i = 0; i < N; i++) > { > if (some_condition(i)) break; > } > do_something_with(i); /* use finishing index */ > >you can miss the fact that the value of i is used outside of the >loop. The newly created scope for "i" shadows the presumably >pre-existing definition of i at the top of the function, which >is what do_something_with() gets to see. I would _really_ hope we have the compiler warning about this already ? -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 12:58:03 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 81AE416A4CE for ; Mon, 31 Jan 2005 12:58:03 +0000 (GMT) Received: from mx1.originative.co.uk (freebsd.gotadsl.co.uk [81.6.249.198]) by mx1.FreeBSD.org (Postfix) with ESMTP id CBA7A43D3F for ; Mon, 31 Jan 2005 12:58:00 +0000 (GMT) (envelope-from paul@mx1.originative.co.uk) Received: from localhost (unknown [127.0.0.1]) by mx1.originative.co.uk (Postfix) with ESMTP id B575115575; Mon, 31 Jan 2005 12:57:59 +0000 (GMT) Received: from mx1.originative.co.uk ([127.0.0.1])port 10024) with ESMTP id 50905-06; Mon, 31 Jan 2005 12:57:43 +0000 (GMT) Received: by mx1.originative.co.uk (Postfix, from userid 1000) id A879615579; Mon, 31 Jan 2005 12:57:43 +0000 (GMT) Date: Mon, 31 Jan 2005 12:57:43 +0000 From: Paul Richards To: Andrew Reilly Message-ID: <20050131125743.GO61409@myrddin.originative.co.uk> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050131122609.GA83556@gurney.reilly.home> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050131122609.GA83556@gurney.reilly.home> User-Agent: Mutt/1.5.6i cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 12:58:03 -0000 On Mon, Jan 31, 2005 at 11:26:09PM +1100, Andrew Reilly wrote: > On Mon, Jan 31, 2005 at 10:26:30AM +0000, Paul Richards wrote: > > 3) Usage in for loops may be more useful than other uses. > [snip] > > 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'd just like to raise a dissenting voice to this particular > point. I find the for-loop initialization syntax a pernicious > source of errors, mainly because of the non-intuitive scope of > the definition. I.e., it looks like it's equivalent to "int i; > for (i = 0;;)" but it isn't. > > If you carelessly c++-ify a loop like: > > for (int i = 0; i < N; i++) > { > if (some_condition(i)) break; > } > do_something_with(i); /* use finishing index */ > > you can miss the fact that the value of i is used outside of the > loop. The newly created scope for "i" shadows the presumably > pre-existing definition of i at the top of the function, which > is what do_something_with() gets to see. Depends whether you find it non-intuitive or not. I find this usage makes it clearer that the loop variable only exists within the scope of the loop. If I needed to code the above example then I know that my for construct is doing more than just looping, it's also returning a value and therefore it needs to affect a variable outside of its scope. I think use of this syntax makes it clearer what you intend in each case. The converse is true as well though, where a global is inadvertently used as a loop variable. -- Paul Richards From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 14:36:37 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D575F16A4CE for ; Mon, 31 Jan 2005 14:36:37 +0000 (GMT) Received: from node15.coopprint.com (node15.cooperativeprinting.com [208.4.77.15]) by mx1.FreeBSD.org (Postfix) with SMTP id A3B0B43D48 for ; Mon, 31 Jan 2005 14:36:34 +0000 (GMT) (envelope-from ryans@gamersimpact.com) Received: (qmail 85289 invoked by uid 0); 31 Jan 2005 14:34:11 -0000 Received: from unknown (HELO ?192.168.0.5?) (63.231.157.250) by node15.coopprint.com with SMTP; 31 Jan 2005 14:34:11 -0000 Message-ID: <41FE426E.1050807@gamersimpact.com> Date: Mon, 31 Jan 2005 08:36:30 -0600 From: Ryan Sommers User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Paul Richards References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> In-Reply-To: <20050131102630.GJ61409@myrddin.originative.co.uk> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 14:36:37 -0000 Paul Richards wrote: > I'd suggest that we allow the use of c99 variable definitions in a > limited area of userland on a trial basis in order to gain some > experience of whether we do or do not gain anything from their > usage. The conservatives might feel that FreeBSD is not the place > for such research but I disagree, I think that's exactly the sort > of thing FreeBSD should be doing. IMO this is a bad idea, unless you are volunteering to clean all the dissenting code up if we decide to nix it in the future. A trial basis or not we end up with the emerging and the old standard intermixed in the code base. Granted there might be occasions when something new is worth the effort. However, as I believe it was PHK that said, if the current solution solves 90% of the problems regardless of if a new solution solves 100% people won't want to change (was stated in regards to a new version control system in hackers@). One of the strengths of FreeBSD is such a rigorous coding style requirement. It's one of the reasons I switched to FreeBSD from Linux a long time ago. > This wasn't really discussed, I think at the very least we should > enable c99 as the base system compiler so that 1) we can be sure our > code works with c99 and 2) it's available as the default compiler for > third party use. Available on the compiler sure, default, not until we are 100% certain it doesn't introduce any oddities. What do we really gain from making C99 the default if we don't allow any of the new features of the C99 syntax? Personally I don't like even the ability to declare variables mid-block. As others pointed out, I believe this lends itself more easily to sloppy programming. Sure, you can be sloppy no matter what. But it's easier to just throw a variable in if you don't have to take the extra time to move up to the top and declare it. That little bit of extra time can be all it takes to force yourself to think "do I really need this?" Or you might look at your other declarations and realize, "hey I could use this instead." -- Ryan Sommers ryans@gamersimpact.com From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 16:31:27 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AA35916A4CE for ; Mon, 31 Jan 2005 16:31:27 +0000 (GMT) Received: from wrzx28.rz.uni-wuerzburg.de (wrzx28.rz.uni-wuerzburg.de [132.187.3.28]) by mx1.FreeBSD.org (Postfix) with ESMTP id 36ABC43D39 for ; Mon, 31 Jan 2005 16:31:25 +0000 (GMT) (envelope-from q@uni.de) Received: from wrzx34.rz.uni-wuerzburg.de (wrzx34.rz.uni-wuerzburg.de [132.187.3.34]) by wrzx28.rz.uni-wuerzburg.de (Postfix) with ESMTP id D6393D849A; Mon, 31 Jan 2005 17:31:24 +0100 (CET) Received: from virusscan (localhost [127.0.0.1]) by wrzx34.rz.uni-wuerzburg.de (Postfix) with ESMTP id B6A15B178B; Mon, 31 Jan 2005 17:31:24 +0100 (CET) Received: from wrzx28.rz.uni-wuerzburg.de (wrzx28.rz.uni-wuerzburg.de [132.187.3.28]) by wrzx34.rz.uni-wuerzburg.de (Postfix) with ESMTP id 9AFE8B1726; Mon, 31 Jan 2005 17:31:24 +0100 (CET) Received: from coyote.q.local (wwsx14.win-screen.uni-wuerzburg.de [132.187.253.14]) by wrzx28.rz.uni-wuerzburg.de (Postfix) with ESMTP id F32C1D849A; Mon, 31 Jan 2005 17:31:23 +0100 (CET) Received: from roadrunner.q.local (roadrunner.q.local [192.168.0.148]) by coyote.q.local (8.13.1/8.13.1) with ESMTP id j0VGVNE9070149; Mon, 31 Jan 2005 17:31:23 +0100 (CET) (envelope-from q@uni.de) Received: from roadrunner.q.local (localhost [127.0.0.1]) by roadrunner.q.local (8.13.1/8.13.1) with ESMTP id j0VGVNlf005775; Mon, 31 Jan 2005 17:31:23 +0100 (CET) (envelope-from q@uni.de) Received: (from q@localhost) by roadrunner.q.local (8.13.1/8.13.1/Submit) id j0VGVH9W005774; Mon, 31 Jan 2005 17:31:17 +0100 (CET) (envelope-from q@uni.de) Date: Mon, 31 Jan 2005 17:31:17 +0100 From: Ulrich Spoerlein To: Poul-Henning Kamp Message-ID: <20050131163117.GE828@galgenberg.net> References: <20050131122609.GA83556@gurney.reilly.home> <90392.1107174969@critter.freebsd.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <90392.1107174969@critter.freebsd.dk> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new (Rechenzentrum Universitaet Wuerzburg) cc: Paul Richards cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 16:31:27 -0000 On Mon, 31.01.2005 at 13:36:09 +0100, Poul-Henning Kamp wrote: > >If you carelessly c++-ify a loop like: > > > > for (int i = 0; i < N; i++) > > { > > if (some_condition(i)) break; > > } > > do_something_with(i); /* use finishing index */ > > > >you can miss the fact that the value of i is used outside of the > >loop. The newly created scope for "i" shadows the presumably > >pre-existing definition of i at the top of the function, which > >is what do_something_with() gets to see. > > I would _really_ hope we have the compiler warning about this > already ? Doesn't look so: #include #include int main(int argc, char **argv) { int N = 42; int i; for (int i = 0; i < N; i++) if (i == 23) break; printf("%d\n", i); /* use finishing index */ return (0); } % cc -Wall -std=c99 test.c && ./a.out 1 % icc -Wall -std=c99 test.c && ./a.out test.c(12): remark #592: variable "i" is used before its value is set printf("%d\n", i); /* use finishing index */ ^ 0 But the ICC warning is bogus too, if you happen to set i before, the warning disappears. Ulrich Spoerlein -- PGP Key ID: F0DB9F44 Encrypted mail welcome! Fingerprint: F1CE D062 0CA9 ADE3 349B 2FE8 980A C6B5 F0DB 9F44 Ok, which part of "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn." didn't you understand? From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 16:41:44 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2689B16A4CE for ; Mon, 31 Jan 2005 16:41:44 +0000 (GMT) Received: from VARK.MIT.EDU (VARK.MIT.EDU [18.95.3.179]) by mx1.FreeBSD.org (Postfix) with ESMTP id CCA1743D39 for ; Mon, 31 Jan 2005 16:41:43 +0000 (GMT) (envelope-from das@FreeBSD.ORG) Received: from VARK.MIT.EDU (localhost [127.0.0.1]) by VARK.MIT.EDU (8.13.1/8.13.1) with ESMTP id j0VGfxTC011641; Mon, 31 Jan 2005 11:41:59 -0500 (EST) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.MIT.EDU (8.13.1/8.13.1/Submit) id j0VGfvO5011640; Mon, 31 Jan 2005 11:41:57 -0500 (EST) (envelope-from das@FreeBSD.ORG) Date: Mon, 31 Jan 2005 11:41:57 -0500 From: David Schultz To: Paul Richards Message-ID: <20050131164157.GA11469@VARK.MIT.EDU> Mail-Followup-To: Paul Richards , arch@FreeBSD.ORG References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050131102630.GJ61409@myrddin.originative.co.uk> cc: arch@FreeBSD.ORG Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 16:41:44 -0000 On Mon, Jan 31, 2005, Paul Richards wrote: > Ok, to sum up the discussion then: > > 1) In the kernel the issue of stack usage is a relevant consideration > against adopting the new style. Is it? In my experience, gcc 3.X does a proper liveness analysis at -O1 and higher, and reuses stack space pretty well. This is an elementary optimization. (Some people don't seem to trust the compiler to do this, so they do evil things such as reuse an identifier to mean two different things in the same function.) From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 16:54:49 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4C68E16A4CE for ; Mon, 31 Jan 2005 16:54:49 +0000 (GMT) Received: from mx1.originative.co.uk (freebsd.gotadsl.co.uk [81.6.249.198]) by mx1.FreeBSD.org (Postfix) with ESMTP id BEF4843D1F for ; Mon, 31 Jan 2005 16:54:46 +0000 (GMT) (envelope-from paul@mx1.originative.co.uk) Received: from localhost (unknown [127.0.0.1]) by mx1.originative.co.uk (Postfix) with ESMTP id BBE7015575 for ; Mon, 31 Jan 2005 16:54:45 +0000 (GMT) Received: from mx1.originative.co.uk ([127.0.0.1])port 10024) with ESMTP id 50504-10 for ; Mon, 31 Jan 2005 16:54:30 +0000 (GMT) Received: by mx1.originative.co.uk (Postfix, from userid 1000) id DD47715579; Mon, 31 Jan 2005 16:54:29 +0000 (GMT) Date: Mon, 31 Jan 2005 16:54:29 +0000 From: Paul Richards To: arch@FreeBSD.ORG Message-ID: <20050131165429.GU61409@myrddin.originative.co.uk> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050131164157.GA11469@VARK.MIT.EDU> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050131164157.GA11469@VARK.MIT.EDU> User-Agent: Mutt/1.5.6i Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 16:54:49 -0000 On Mon, Jan 31, 2005 at 11:41:57AM -0500, David Schultz wrote: > On Mon, Jan 31, 2005, Paul Richards wrote: > > Ok, to sum up the discussion then: > > > > 1) In the kernel the issue of stack usage is a relevant consideration > > against adopting the new style. > > Is it? In my experience, gcc 3.X does a proper liveness analysis > at -O1 and higher, and reuses stack space pretty well. This is an > elementary optimization. (Some people don't seem to trust the > compiler to do this, so they do evil things such as reuse an > identifier to mean two different things in the same function.) It's more a question of the programmer being able to do a quick visual check i.e. it's easy to spot bad practice say creating a large array on the stack, if it's all there in one place. If it's spread throughout the file then you might not spot that erroneous line. I think tools would be better used here than code style but I can see the point of the argument. -- Paul Richards From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 16:55:16 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9E09A16A4CE for ; Mon, 31 Jan 2005 16:55:16 +0000 (GMT) Received: from fafoe.narf.at (chello084113209090.6.14.vie.surfer.at [84.113.209.90]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1CCB743D46 for ; Mon, 31 Jan 2005 16:55:14 +0000 (GMT) (envelope-from stefan@fafoe.narf.at) Received: from wombat.fafoe.narf.at (wombat.fafoe.narf.at [192.168.1.42]) by fafoe.narf.at (Postfix) with ESMTP id 6A7883FC5; Mon, 31 Jan 2005 17:55:07 +0100 (CET) Received: by wombat.fafoe.narf.at (Postfix, from userid 1001) id D8CD04C8; Mon, 31 Jan 2005 17:55:06 +0100 (CET) Date: Mon, 31 Jan 2005 17:55:06 +0100 From: Stefan Farfeleder To: Ulrich Spoerlein Message-ID: <20050131165504.GD78235@wombat.fafoe.narf.at> References: <20050131122609.GA83556@gurney.reilly.home> <90392.1107174969@critter.freebsd.dk> <20050131163117.GE828@galgenberg.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050131163117.GE828@galgenberg.net> User-Agent: Mutt/1.5.6i cc: arch@freebsd.org cc: Poul-Henning Kamp cc: Paul Richards Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 16:55:16 -0000 On Mon, Jan 31, 2005 at 05:31:17PM +0100, Ulrich Spoerlein wrote: > Doesn't look so: > #include > #include > > int > main(int argc, char **argv) { > int N = 42; > int i; > for (int i = 0; i < N; i++) > if (i == 23) > break; > printf("%d\n", i); /* use finishing index */ > return (0); > } > > % cc -Wall -std=c99 test.c && ./a.out > 1 > % icc -Wall -std=c99 test.c && ./a.out > test.c(12): remark #592: variable "i" is used before its value is set > printf("%d\n", i); /* use finishing index */ > ^ -Wshadow Stefan From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 16:58:33 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DAB9A16A4CF for ; Mon, 31 Jan 2005 16:58:33 +0000 (GMT) Received: from mx1.originative.co.uk (freebsd.gotadsl.co.uk [81.6.249.198]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5598B43D1D for ; Mon, 31 Jan 2005 16:58:33 +0000 (GMT) (envelope-from paul@mx1.originative.co.uk) Received: from localhost (unknown [127.0.0.1]) by mx1.originative.co.uk (Postfix) with ESMTP id 44D0915575; Mon, 31 Jan 2005 16:58:32 +0000 (GMT) Received: from mx1.originative.co.uk ([127.0.0.1])port 10024) with ESMTP id 76384-03; Mon, 31 Jan 2005 16:58:17 +0000 (GMT) Received: by mx1.originative.co.uk (Postfix, from userid 1000) id 63D5D15579; Mon, 31 Jan 2005 16:58:17 +0000 (GMT) Date: Mon, 31 Jan 2005 16:58:17 +0000 From: Paul Richards To: Ulrich Spoerlein Message-ID: <20050131165817.GV61409@myrddin.originative.co.uk> References: <20050131122609.GA83556@gurney.reilly.home> <90392.1107174969@critter.freebsd.dk> <20050131163117.GE828@galgenberg.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050131163117.GE828@galgenberg.net> User-Agent: Mutt/1.5.6i cc: Poul-Henning Kamp cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 16:58:34 -0000 On Mon, Jan 31, 2005 at 05:31:17PM +0100, Ulrich Spoerlein wrote: > On Mon, 31.01.2005 at 13:36:09 +0100, Poul-Henning Kamp wrote: > > >If you carelessly c++-ify a loop like: > > > > > > for (int i = 0; i < N; i++) > > > { > > > if (some_condition(i)) break; > > > } > > > do_something_with(i); /* use finishing index */ > > > > > >you can miss the fact that the value of i is used outside of the > > >loop. The newly created scope for "i" shadows the presumably > > >pre-existing definition of i at the top of the function, which > > >is what do_something_with() gets to see. > > > > I would _really_ hope we have the compiler warning about this > > already ? > > Doesn't look so: > #include > #include > > int > main(int argc, char **argv) { > int N = 42; > int i; > for (int i = 0; i < N; i++) > if (i == 23) > break; > printf("%d\n", i); /* use finishing index */ > return (0); > } > > % cc -Wall -std=c99 test.c && ./a.out > 1 gcc should be throwing an uninitialised warning here. > % icc -Wall -std=c99 test.c && ./a.out > test.c(12): remark #592: variable "i" is used before its value is set > printf("%d\n", i); /* use finishing index */ > ^ > 0 > > But the ICC warning is bogus too, if you happen to set i before, the > warning disappears. icc looks correct to me since the i being printed out is the one in the outer scope which is unitialised. -- Paul Richards From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 17:04:34 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A42F416A4CE for ; Mon, 31 Jan 2005 17:04:34 +0000 (GMT) Received: from mx1.originative.co.uk (freebsd.gotadsl.co.uk [81.6.249.198]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2180343D58 for ; Mon, 31 Jan 2005 17:04:34 +0000 (GMT) (envelope-from paul@mx1.originative.co.uk) Received: from localhost (unknown [127.0.0.1]) by mx1.originative.co.uk (Postfix) with ESMTP id 2294515575; Mon, 31 Jan 2005 17:04:33 +0000 (GMT) Received: from mx1.originative.co.uk ([127.0.0.1])port 10024) with ESMTP id 38650-08; Mon, 31 Jan 2005 17:04:18 +0000 (GMT) Received: by mx1.originative.co.uk (Postfix, from userid 1000) id 0B0F815579; Mon, 31 Jan 2005 17:04:18 +0000 (GMT) Date: Mon, 31 Jan 2005 17:04:17 +0000 From: Paul Richards To: Ulrich Spoerlein Message-ID: <20050131170417.GW61409@myrddin.originative.co.uk> References: <20050131122609.GA83556@gurney.reilly.home> <90392.1107174969@critter.freebsd.dk> <20050131163117.GE828@galgenberg.net> <20050131165817.GV61409@myrddin.originative.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050131165817.GV61409@myrddin.originative.co.uk> User-Agent: Mutt/1.5.6i cc: arch@freebsd.org cc: Poul-Henning Kamp Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 17:04:34 -0000 On Mon, Jan 31, 2005 at 04:58:17PM +0000, Paul Richards wrote: > On Mon, Jan 31, 2005 at 05:31:17PM +0100, Ulrich Spoerlein wrote: > > On Mon, 31.01.2005 at 13:36:09 +0100, Poul-Henning Kamp wrote: > > > >If you carelessly c++-ify a loop like: > > > > > > > > for (int i = 0; i < N; i++) > > > > { > > > > if (some_condition(i)) break; > > > > } > > > > do_something_with(i); /* use finishing index */ > > > > > > > >you can miss the fact that the value of i is used outside of the > > > >loop. The newly created scope for "i" shadows the presumably > > > >pre-existing definition of i at the top of the function, which > > > >is what do_something_with() gets to see. > > > > > > I would _really_ hope we have the compiler warning about this > > > already ? > > > > Doesn't look so: > > #include > > #include > > > > int > > main(int argc, char **argv) { > > int N = 42; > > int i; > > for (int i = 0; i < N; i++) > > if (i == 23) > > break; > > printf("%d\n", i); /* use finishing index */ > > return (0); > > } > > > > % cc -Wall -std=c99 test.c && ./a.out > > 1 > > gcc should be throwing an uninitialised warning here. With the right warns it does :-) cc -Wall -std=c99 -O -Wuninitialized test.c test.c test.c: In function `main': test.c:7: warning: 'i' might be used uninitialized in this function -- Paul Richards From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 18:42:27 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4BA2516A4CE for ; Mon, 31 Jan 2005 18:42:27 +0000 (GMT) Received: from wrzx35.rz.uni-wuerzburg.de (wrzx35.rz.uni-wuerzburg.de [132.187.3.35]) by mx1.FreeBSD.org (Postfix) with ESMTP id 88BB443D4C for ; Mon, 31 Jan 2005 18:42:26 +0000 (GMT) (envelope-from q@uni.de) Received: from wrzx30.rz.uni-wuerzburg.de (wrzx30.rz.uni-wuerzburg.de [132.187.1.30]) by wrzx35.rz.uni-wuerzburg.de (Postfix) with ESMTP id A905DE1012; Mon, 31 Jan 2005 19:42:25 +0100 (CET) Received: from virusscan (localhost [127.0.0.1]) by wrzx30.rz.uni-wuerzburg.de (Postfix) with ESMTP id 8D56F93216; Mon, 31 Jan 2005 19:42:25 +0100 (CET) Received: from wrzx28.rz.uni-wuerzburg.de (wrzx28.rz.uni-wuerzburg.de [132.187.3.28]) by wrzx30.rz.uni-wuerzburg.de (Postfix) with ESMTP id 7A9F9931AC; Mon, 31 Jan 2005 19:42:25 +0100 (CET) Received: from coyote.q.local (wwsx14.win-screen.uni-wuerzburg.de [132.187.253.14]) by wrzx28.rz.uni-wuerzburg.de (Postfix) with ESMTP id F2A80D84A6; Mon, 31 Jan 2005 19:42:24 +0100 (CET) Received: from roadrunner.q.local (roadrunner.q.local [192.168.0.148]) by coyote.q.local (8.13.1/8.13.1) with ESMTP id j0VIgOSw070820; Mon, 31 Jan 2005 19:42:24 +0100 (CET) (envelope-from q@uni.de) Received: from roadrunner.q.local (localhost [127.0.0.1]) by roadrunner.q.local (8.13.1/8.13.1) with ESMTP id j0VIgONe006811; Mon, 31 Jan 2005 19:42:24 +0100 (CET) (envelope-from q@uni.de) Received: (from q@localhost) by roadrunner.q.local (8.13.1/8.13.1/Submit) id j0VIgN6J006810; Mon, 31 Jan 2005 19:42:23 +0100 (CET) (envelope-from q@uni.de) Date: Mon, 31 Jan 2005 19:42:23 +0100 From: Ulrich Spoerlein To: Paul Richards Message-ID: <20050131184223.GG828@galgenberg.net> References: <20050131122609.GA83556@gurney.reilly.home> <90392.1107174969@critter.freebsd.dk> <20050131163117.GE828@galgenberg.net> <20050131165817.GV61409@myrddin.originative.co.uk> <20050131170417.GW61409@myrddin.originative.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050131170417.GW61409@myrddin.originative.co.uk> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new (Rechenzentrum Universitaet Wuerzburg) cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 18:42:27 -0000 On Mon, 31.01.2005 at 17:04:17 +0000, Paul Richards wrote: > > > % cc -Wall -std=c99 test.c && ./a.out > > > 1 > > gcc should be throwing an uninitialised warning here. > > With the right warns it does :-) > > cc -Wall -std=c99 -O -Wuninitialized test.c > test.c > test.c: In function `main': > test.c:7: warning: 'i' might be used uninitialized in this function Grrr, I knew I should've read the man page. I guess you can't expect to get _all_ warnings when specifying -Wall *sigh* % cc -std=c99 -O -pedantic -Wall -Wshadow -Wuninitialized test.c test.c: In function `main': test.c:8: warning: declaration of 'i' shadows a previous local test.c:7: warning: shadowed declaration is here test.c:7: warning: 'i' might be used uninitialized in this function Ulrich Spoerlein -- PGP Key ID: F0DB9F44 Encrypted mail welcome! Fingerprint: F1CE D062 0CA9 ADE3 349B 2FE8 980A C6B5 F0DB 9F44 Ok, which part of "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn." didn't you understand? From owner-freebsd-arch@FreeBSD.ORG Tue Feb 1 07:04:46 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 330C916A4CE for ; Tue, 1 Feb 2005 07:04:46 +0000 (GMT) Received: from mail25.syd.optusnet.com.au (mail25.syd.optusnet.com.au [211.29.133.166]) by mx1.FreeBSD.org (Postfix) with ESMTP id 68E3D43D2D for ; Tue, 1 Feb 2005 07:04:45 +0000 (GMT) (envelope-from PeterJeremy@optushome.com.au) Received: from cirb503493.alcatel.com.au (c211-30-75-229.belrs2.nsw.optusnet.com.au [211.30.75.229]) j1174biK023764 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Tue, 1 Feb 2005 18:04:44 +1100 Received: from cirb503493.alcatel.com.au (localhost.alcatel.com.au [127.0.0.1])j1173c7l045660; Tue, 1 Feb 2005 18:03:38 +1100 (EST) (envelope-from pjeremy@cirb503493.alcatel.com.au) Received: (from pjeremy@localhost)j1173cXd045659; Tue, 1 Feb 2005 18:03:38 +1100 (EST) (envelope-from pjeremy) Date: Tue, 1 Feb 2005 18:03:38 +1100 From: Peter Jeremy To: Ryan Sommers Message-ID: <20050201070338.GA45608@cirb503493.alcatel.com.au> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <41FE426E.1050807@gamersimpact.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41FE426E.1050807@gamersimpact.com> User-Agent: Mutt/1.4.2i cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 07:04:46 -0000 On Mon, 2005-Jan-31 08:36:30 -0600, Ryan Sommers wrote: >all it takes to force yourself to think "do I really need this?" Or you >might look at your other declarations and realize, "hey I could use this >instead." Finding a stray int (or whatever) that doesn't appear to be live at a particular point and re-using it for something unrelated isn't necessarily good coding practice either. This can confuse someone who is quickly scanning the code - especially if the variable name was mnemonic and the re-use doesn't match it's name. It's unfortunate that C doesn't have any way to define the end of a variable's scope (or lifetime) apart from blocks. -- Peter Jeremy From owner-freebsd-arch@FreeBSD.ORG Tue Feb 1 18:06:32 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E080216A4CF for ; Tue, 1 Feb 2005 18:06:32 +0000 (GMT) Received: from mail24.sea5.speakeasy.net (mail24.sea5.speakeasy.net [69.17.117.26]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8FD4443D49 for ; Tue, 1 Feb 2005 18:06:32 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: (qmail 19902 invoked from network); 1 Feb 2005 18:06:32 -0000 Received: from gate.funkthat.com (HELO hydrogen.funkthat.com) ([69.17.45.168]) (envelope-sender ) by mail24.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 1 Feb 2005 18:06:32 -0000 Received: from hydrogen.funkthat.com (ipknwl@localhost.funkthat.com [127.0.0.1])j11I6QGH049744; Tue, 1 Feb 2005 10:06:26 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.12.10/8.12.10/Submit) id j11I6OZ3049743; Tue, 1 Feb 2005 10:06:24 -0800 (PST) Date: Tue, 1 Feb 2005 10:06:24 -0800 From: John-Mark Gurney To: Paul Richards Message-ID: <20050201180624.GB19624@funkthat.com> Mail-Followup-To: Paul Richards , arch@freebsd.org References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050131102630.GJ61409@myrddin.originative.co.uk> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.2-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: John-Mark Gurney List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 18:06:33 -0000 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: And wonder why i gets such a strange value... It appears that unless you have WARNS=4 set, warnings about: t.c:10: warning: declaration of 'i' shadows a previous local don't show up. So, I would say we HAVE to get the tree building with WARNS=4 and -Werror before we let this into style(9)... Requiring variables at the top require people to think about variable names, and as others have stated, if you need local scoped variables, you're probably better off creating a new function. /me notes it's anoying that gcc accepts -std=c99 and not -std=C99. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not." From owner-freebsd-arch@FreeBSD.ORG Tue Feb 1 19:04:34 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AE44A16A4CE for ; Tue, 1 Feb 2005 19:04:34 +0000 (GMT) Received: from mx1.originative.co.uk (freebsd.gotadsl.co.uk [81.6.249.198]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1A66643D46 for ; Tue, 1 Feb 2005 19:04:34 +0000 (GMT) (envelope-from paul@mx1.originative.co.uk) Received: from localhost (unknown [127.0.0.1]) by mx1.originative.co.uk (Postfix) with ESMTP id E9DA515575 for ; Tue, 1 Feb 2005 19:04:32 +0000 (GMT) Received: from mx1.originative.co.uk ([127.0.0.1])port 10024) with ESMTP id 97617-06 for ; Tue, 1 Feb 2005 19:04:17 +0000 (GMT) Received: by mx1.originative.co.uk (Postfix, from userid 1000) id 3971E15583; Tue, 1 Feb 2005 19:04:17 +0000 (GMT) Date: Tue, 1 Feb 2005 19:04:17 +0000 From: Paul Richards To: arch@freebsd.org Message-ID: <20050201190416.GG61409@myrddin.originative.co.uk> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050201180624.GB19624@funkthat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050201180624.GB19624@funkthat.com> User-Agent: Mutt/1.5.6i Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 19:04:34 -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. > > And wonder why i gets such a strange value... It appears that unless > you have WARNS=4 set, warnings about: > t.c:10: warning: declaration of 'i' shadows a previous local > > don't show up. So, I would say we HAVE to get the tree building with > WARNS=4 and -Werror before we let this into style(9)... The issue with shadowing outer scope variables is only an issue if you need to access them. If your only using the syntax for loop variables to do the looping then there's no issue. -- Paul Richards From owner-freebsd-arch@FreeBSD.ORG Tue Feb 1 20:30:44 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1900716A4CE for ; Tue, 1 Feb 2005 20:30:44 +0000 (GMT) Received: from ns1.xcllnt.net (209-128-86-226.BAYAREA.NET [209.128.86.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id D239443D1F for ; Tue, 1 Feb 2005 20:30:43 +0000 (GMT) (envelope-from marcel@xcllnt.net) Received: from [192.168.4.250] (dhcp50.pn.xcllnt.net [192.168.4.250]) by ns1.xcllnt.net (8.13.1/8.13.1) with ESMTP id j11KUdea012213; Tue, 1 Feb 2005 12:30:41 -0800 (PST) (envelope-from marcel@xcllnt.net) In-Reply-To: <20050201190416.GG61409@myrddin.originative.co.uk> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050201180624.GB19624@funkthat.com> <20050201190416.GG61409@myrddin.originative.co.uk> Mime-Version: 1.0 (Apple Message framework v619.2) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Marcel Moolenaar Date: Tue, 1 Feb 2005 12:30:37 -0800 To: Paul Richards X-Mailer: Apple Mail (2.619.2) cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 20:30:44 -0000 On Feb 1, 2005, at 11:04 AM, Paul Richards wrote: >> And wonder why i gets such a strange value... It appears that unless >> you have WARNS=4 set, warnings about: >> t.c:10: warning: declaration of 'i' shadows a previous local >> >> don't show up. So, I would say we HAVE to get the tree building with >> WARNS=4 and -Werror before we let this into style(9)... > > The issue with shadowing outer scope variables is only an issue if > you need to access them. If your only using the syntax for loop > variables to do the looping then there's no issue. Never forget that you want to be able to debug you application. While technically you're right, it's bad practice to do so. In general, localized variable definitions increases the chance that a bug is being made, because it increases the complexity of the language -- there are more things/cases to be aware off and that need checking before you can be sure the code is correct. Hence, there's more you can forget about when you code. Therefore, it's not a feature you want to promote. Put differently: it doesn't fundamentally change the expression power of the language, but rather introduce new ways of doing things that can already be done. It doesn't buy you anything. It's just window- dressing. It would have been very adequate if it were kept as a C++ (or more correctly object oriented) feature only... -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net From owner-freebsd-arch@FreeBSD.ORG Tue Feb 1 20:43:51 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AA0BB16A4CE for ; Tue, 1 Feb 2005 20:43:51 +0000 (GMT) Received: from mx1.originative.co.uk (freebsd.gotadsl.co.uk [81.6.249.198]) by mx1.FreeBSD.org (Postfix) with ESMTP id DD91943D41 for ; Tue, 1 Feb 2005 20:43:48 +0000 (GMT) (envelope-from paul@mx1.originative.co.uk) Received: from localhost (unknown [127.0.0.1]) by mx1.originative.co.uk (Postfix) with ESMTP id A10B615575; Tue, 1 Feb 2005 20:43:47 +0000 (GMT) Received: from mx1.originative.co.uk ([127.0.0.1])port 10024) with ESMTP id 98052-04; Tue, 1 Feb 2005 20:43:31 +0000 (GMT) Received: by mx1.originative.co.uk (Postfix, from userid 1000) id 9D60115579; Tue, 1 Feb 2005 20:43:31 +0000 (GMT) Date: Tue, 1 Feb 2005 20:43:31 +0000 From: Paul Richards To: Marcel Moolenaar Message-ID: <20050201204331.GH61409@myrddin.originative.co.uk> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050201180624.GB19624@funkthat.com> <20050201190416.GG61409@myrddin.originative.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6i cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 20:43:51 -0000 On Tue, Feb 01, 2005 at 12:30:37PM -0800, Marcel Moolenaar wrote: > On Feb 1, 2005, at 11:04 AM, Paul Richards wrote: > > >>And wonder why i gets such a strange value... It appears that unless > >>you have WARNS=4 set, warnings about: > >>t.c:10: warning: declaration of 'i' shadows a previous local > >> > >>don't show up. So, I would say we HAVE to get the tree building with > >>WARNS=4 and -Werror before we let this into style(9)... > > > >The issue with shadowing outer scope variables is only an issue if > >you need to access them. If your only using the syntax for loop > >variables to do the looping then there's no issue. > > Never forget that you want to be able to debug you application. > While technically you're right, it's bad practice to do so. I disagree with this point. I think it's more error prone to rely on a side effect of a loop variable to exist outside the scope of the loop. I know that C programmers are used to this, but from the perspective of good programming practice I don't think it's a good one. Of these two situations: Case 1: int i; for (i = 0; i < MAX; i++) if (i == 5) break; printf("Found %dth element\n"); Case 2: int fifth_element = 0; for (int i = 0; i < MAX; i++) if (i == 5) { fifth_element = i; break; } } if (fifth_element) printf("Found %dth element", fifth_elemtn); The latter seems the better written code to me. It's more verbose, but it's clearer what's being done. It seems pointless when you consider it in isolation but since probably more than 99% of for loops only declare outer scope variables in order to terminate the loop the above is the exception and not the rule and for the other 99% of the time using localised looping variables is better since it doesn't pollute the outer scope. -- Paul Richards From owner-freebsd-arch@FreeBSD.ORG Tue Feb 1 21:23:07 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 112E016A4CE for ; Tue, 1 Feb 2005 21:23:07 +0000 (GMT) Received: from ns1.xcllnt.net (209-128-86-226.BAYAREA.NET [209.128.86.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6BF8643D5A for ; Tue, 1 Feb 2005 21:23:06 +0000 (GMT) (envelope-from marcel@xcllnt.net) Received: from [192.168.4.250] (dhcp50.pn.xcllnt.net [192.168.4.250]) by ns1.xcllnt.net (8.13.1/8.13.1) with ESMTP id j11LN5HI012570; Tue, 1 Feb 2005 13:23:05 -0800 (PST) (envelope-from marcel@xcllnt.net) In-Reply-To: <20050201204331.GH61409@myrddin.originative.co.uk> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050201180624.GB19624@funkthat.com> <20050201190416.GG61409@myrddin.originative.co.uk> <20050201204331.GH61409@myrddin.originative.co.uk> Mime-Version: 1.0 (Apple Message framework v619.2) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <7133afbc3492c934b5686c5e6f0911b1@xcllnt.net> Content-Transfer-Encoding: 7bit From: Marcel Moolenaar Date: Tue, 1 Feb 2005 13:23:04 -0800 To: Paul Richards X-Mailer: Apple Mail (2.619.2) cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 21:23:07 -0000 On Feb 1, 2005, at 12:43 PM, Paul Richards wrote: > On Tue, Feb 01, 2005 at 12:30:37PM -0800, Marcel Moolenaar wrote: >> On Feb 1, 2005, at 11:04 AM, Paul Richards wrote: >> >>>> And wonder why i gets such a strange value... It appears that >>>> unless >>>> you have WARNS=4 set, warnings about: >>>> t.c:10: warning: declaration of 'i' shadows a previous local >>>> >>>> don't show up. So, I would say we HAVE to get the tree building >>>> with >>>> WARNS=4 and -Werror before we let this into style(9)... >>> >>> The issue with shadowing outer scope variables is only an issue if >>> you need to access them. If your only using the syntax for loop >>> variables to do the looping then there's no issue. >> >> Never forget that you want to be able to debug you application. >> While technically you're right, it's bad practice to do so. > > I disagree with this point. I think it's more error prone to rely on a > side effect of a loop variable to exist outside the scope of the loop. There's no side-effect. You define it outside the loop. You know that the scope will be larger than the scope of the loop itself. The only down side is that the life-range spans the whole function and not the one loop it is used in. *cases snipped* It's all subjective and very much dependent on the context. There are indeed times when localised variable definitions are in fact more elegant. But it doesn't go beyond just being more elegant. It doesn't add to the power of the language. It just addresses one of many down sides in this particular language (and every language has plenty of down sides) that you could just as well have solved with #pragma statements or lint(1) annotations. It does however introduce more ways to make mistakes and I simply don't value elegancy that much. I value consistency more. -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net From owner-freebsd-arch@FreeBSD.ORG Tue Feb 1 23:04:43 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BFDA416A4E0 for ; Tue, 1 Feb 2005 23:04:43 +0000 (GMT) Received: from mail25.sea5.speakeasy.net (mail25.sea5.speakeasy.net [69.17.117.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4F79B43D60 for ; Tue, 1 Feb 2005 23:04:43 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: (qmail 30519 invoked from network); 1 Feb 2005 23:04:43 -0000 Received: from gate.funkthat.com (HELO hydrogen.funkthat.com) ([69.17.45.168]) (envelope-sender ) by mail25.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 1 Feb 2005 23:04:43 -0000 Received: from hydrogen.funkthat.com (ahsrqx@localhost.funkthat.com [127.0.0.1])j11N4gGH057585; Tue, 1 Feb 2005 15:04:42 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.12.10/8.12.10/Submit) id j11N4bin057584; Tue, 1 Feb 2005 15:04:37 -0800 (PST) Date: Tue, 1 Feb 2005 15:04:37 -0800 From: John-Mark Gurney To: Paul Richards Message-ID: <20050201230437.GD19624@funkthat.com> Mail-Followup-To: Paul Richards , arch@freebsd.org References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050201180624.GB19624@funkthat.com> <20050201190416.GG61409@myrddin.originative.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050201190416.GG61409@myrddin.originative.co.uk> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.2-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: John-Mark Gurney List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 23:04:43 -0000 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.. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not." From owner-freebsd-arch@FreeBSD.ORG Tue Feb 1 23:47:06 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8890416A4CE for ; Tue, 1 Feb 2005 23:47:06 +0000 (GMT) Received: from mx1.originative.co.uk (freebsd.gotadsl.co.uk [81.6.249.198]) by mx1.FreeBSD.org (Postfix) with ESMTP id E110243D46 for ; Tue, 1 Feb 2005 23:47:03 +0000 (GMT) (envelope-from paul@mx1.originative.co.uk) Received: from localhost (unknown [127.0.0.1]) by mx1.originative.co.uk (Postfix) with ESMTP id EA80315575 for ; Tue, 1 Feb 2005 23:47:02 +0000 (GMT) Received: from mx1.originative.co.uk ([127.0.0.1])port 10024) with ESMTP id 98450-10 for ; Tue, 1 Feb 2005 23:46:47 +0000 (GMT) Received: by mx1.originative.co.uk (Postfix, from userid 1000) id 2781A15579; Tue, 1 Feb 2005 23:46:47 +0000 (GMT) Date: Tue, 1 Feb 2005 23:46:47 +0000 From: Paul Richards To: arch@freebsd.org Message-ID: <20050201234646.GK61409@myrddin.originative.co.uk> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050201180624.GB19624@funkthat.com> <20050201190416.GG61409@myrddin.originative.co.uk> <20050201230437.GD19624@funkthat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050201230437.GD19624@funkthat.com> User-Agent: Mutt/1.5.6i Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 23:47:06 -0000 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. -- Paul Richards From owner-freebsd-arch@FreeBSD.ORG Wed Feb 2 06:25:05 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 23DA816A4D6 for ; Wed, 2 Feb 2005 06:25:05 +0000 (GMT) Received: from smtp3.server.rpi.edu (smtp3.server.rpi.edu [128.113.2.3]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9E05E43D3F for ; Wed, 2 Feb 2005 06:25:04 +0000 (GMT) (envelope-from drosih@rpi.edu) Received: from [128.113.24.47] (gilead.netel.rpi.edu [128.113.24.47]) by smtp3.server.rpi.edu (8.13.0/8.13.0) with ESMTP id j126P0N3023436; Wed, 2 Feb 2005 01:25:00 -0500 Mime-Version: 1.0 Message-Id: In-Reply-To: <20050201234646.GK61409@myrddin.originative.co.uk> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050201180624.GB19624@funkthat.com> <20050201190416.GG61409@myrddin.originative.co.uk> <20050201230437.GD19624@funkthat.com> <20050201234646.GK61409@myrddin.originative.co.uk> Date: Wed, 2 Feb 2005 01:24:59 -0500 To: Paul Richards , arch@freebsd.org From: Garance A Drosihn Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-CanItPRO-Stream: default X-RPI-SA-Score: undef - spam-scanning disabled X-Scanned-By: CanIt (www . canit . ca) Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2005 06:25:05 -0000 At 11:46 PM +0000 2/1/05, Paul Richards wrote: > >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. I suspect that if you're a good coder, or if you have a bunch of good coders looking over your shoulder (like we do here...), then the current style is just as likely to result in good, maintainable code as the localized-variable style that you are proposing. Thus, there does not seem to be any compelling reason to change the style. Just MO, of course. -- Garance Alistair Drosehn = gad@gilead.netel.rpi.edu Senior Systems Programmer or gad@freebsd.org Rensselaer Polytechnic Institute or drosih@rpi.edu From owner-freebsd-arch@FreeBSD.ORG Wed Feb 2 19:53:57 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3AE2F16A4CE for ; Wed, 2 Feb 2005 19:53:57 +0000 (GMT) Received: from mail26.sea5.speakeasy.net (mail26.sea5.speakeasy.net [69.17.117.28]) by mx1.FreeBSD.org (Postfix) with ESMTP id B517543D49 for ; Wed, 2 Feb 2005 19:53:56 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: (qmail 29152 invoked from network); 2 Feb 2005 19:53:56 -0000 Received: from gate.funkthat.com (HELO hydrogen.funkthat.com) ([69.17.45.168]) (envelope-sender ) by mail26.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 2 Feb 2005 19:53:56 -0000 Received: from hydrogen.funkthat.com (qdovsj@localhost.funkthat.com [127.0.0.1])j12JroGH087081; Wed, 2 Feb 2005 11:53:51 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.12.10/8.12.10/Submit) id j12JrorR087080; Wed, 2 Feb 2005 11:53:50 -0800 (PST) Date: Wed, 2 Feb 2005 11:53:50 -0800 From: John-Mark Gurney To: Paul Richards Message-ID: <20050202195349.GH19624@funkthat.com> Mail-Followup-To: Paul Richards , arch@freebsd.org References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050201180624.GB19624@funkthat.com> <20050201190416.GG61409@myrddin.originative.co.uk> <20050201230437.GD19624@funkthat.com> <20050201234646.GK61409@myrddin.originative.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050201234646.GK61409@myrddin.originative.co.uk> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.2-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: John-Mark Gurney List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2005 19:53:57 -0000 Paul Richards wrote this message on Tue, Feb 01, 2005 at 23:46 +0000: > 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. The issue should be how to make sure all contributions to the FreeBSD project are maintainable and of good quality not to be buggy... That is part of why we have the style(9) guide in the first place.. Considering not everyone is a first rate coder, having loose style guide lines is an accident waiting to happen... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not." From owner-freebsd-arch@FreeBSD.ORG Wed Feb 2 22:18:20 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0CE9516A4CE for ; Wed, 2 Feb 2005 22:18:20 +0000 (GMT) Received: from mail21.sea5.speakeasy.net (mail21.sea5.speakeasy.net [69.17.117.23]) by mx1.FreeBSD.org (Postfix) with ESMTP id C0BB643D31 for ; Wed, 2 Feb 2005 22:18:19 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: (qmail 21589 invoked from network); 2 Feb 2005 22:18:19 -0000 Received: from server.baldwin.cx ([216.27.160.63]) (envelope-sender )AES256-SHA encrypted SMTP for ; 2 Feb 2005 22:18:19 -0000 Received: from [10.50.40.202] (gw1.twc.weather.com [216.133.140.1]) (authenticated bits=0) by server.baldwin.cx (8.13.1/8.13.1) with ESMTP id j12MI5ES049221; Wed, 2 Feb 2005 17:18:16 -0500 (EST) (envelope-from jhb@FreeBSD.org) From: John Baldwin To: freebsd-arch@FreeBSD.org Date: Wed, 2 Feb 2005 11:33:09 -0500 User-Agent: KMail/1.6.2 References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050201230437.GD19624@funkthat.com> <20050201234646.GK61409@myrddin.originative.co.uk> In-Reply-To: <20050201234646.GK61409@myrddin.originative.co.uk> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200502021133.09691.jhb@FreeBSD.org> X-Spam-Status: No, score=-102.8 required=4.2 tests=ALL_TRUSTED, USER_IN_WHITELIST autolearn=failed version=3.0.2 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on server.baldwin.cx cc: Paul Richards Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2005 22:18:20 -0000 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 <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org