Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76241 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58081 invoked from network); 29 Jul 2014 00:56:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jul 2014 00:56:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.53 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.215.53 mail-la0-f53.google.com Received: from [209.85.215.53] ([209.85.215.53:43289] helo=mail-la0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CE/82-41808-421F6D35 for ; Mon, 28 Jul 2014 20:56:05 -0400 Received: by mail-la0-f53.google.com with SMTP id gl10so5917386lab.40 for ; Mon, 28 Jul 2014 17:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:from:mime-version:in-reply-to:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=/4fcub4hrkvCQNGLQSrjDXoqTXmdIOqkeUc4kZfCdB8=; b=SXsW+fX0ByeHFVCj3klM5OVWQ977LEcRo1EQY7SPz8hkMSN1LqM+RP46iWytcXXyPI 92NsSif4h0bhj3SMZctB2Qka/zwidFnGG82tE1XXu1y8hGrKQ3cI9K6Y1aCla0Ih1PXo 6g7m4ybsra8gYcsIt5HiUHbbUzXGFnQXSvubzaISsxb7dkQYOQITEl5JJY7YqCiHfckb 9mKioL51S0+I3AH+W2xHnUWrZx4oDjIrYBsQRzNIp/9lV5wHn0bUOZ7FsJvEmTVNqysB opOODWw9lCYHCdwnU/B226tZPtLZmLCjw2uW/1okr1CHb2cXwNW8aVVtETLnymmxTPTi +aUA== X-Received: by 10.152.245.171 with SMTP id xp11mr38831791lac.61.1406595374687; Mon, 28 Jul 2014 17:56:14 -0700 (PDT) References: <71A78449-A62C-400D-A01F-5668930A7BED@ajf.me> Mime-Version: 1.0 (1.0) In-Reply-To: <71A78449-A62C-400D-A01F-5668930A7BED@ajf.me> Date: Mon, 28 Jul 2014 23:49:57 +0800 Message-ID: <-611365610874328433@unknownmsgid> To: Andrea Faulds Cc: Derick Rethans , Nikita Popov , Julien Pauli , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Thoughts on C version supported for PHP-Next From: laruence@gmail.com (Xinchen Hui) =E5=8F=91=E8=87=AA=E6=88=91=E7=9A=84 iPad > =E5=9C=A8 2014=E5=B9=B47=E6=9C=8828=E6=97=A5=EF=BC=8C22:20=EF=BC=8CAndrea= Faulds =E5=86=99=E9=81=93=EF=BC=9A > > > On 28 Jul 2014, at 15:00, Derick Rethans wrote: > >>> Well, we don=E2=80=99t need to allow all of C99. We can simply allow us= ing >>> features that are widely supported and actually useful. For example, >>> declarations between statements, >> >> I think that makes code a lot less readable, so I would not be in favour >> allowing this in our coding guidelines. > > Really? I=E2=80=99ve found that declaring everything in advance makes for= hard-to-read code. To take an example from code I=E2=80=99ve written (admi= ttedly not C code - GML if anyone=E2=80=99s curious - but it might as well = be), the first line of a function looked like this: > > var list, hashList, text, i, pluginname, pluginhash, realhash, url, ha= ndle, filesize, progress, tempfile, tempdir, failed, lastContact, isCached,= env; > > Even broken onto multiple lines, declaring everything at once isn=E2=80= =99t nice. For large functions (and some functions have to be large necessa= rily), declaring everything at the start just means a long list of variable= s and I would argue impairs code readability. > > You should declare variables when and where you need them. If everything = is done at the top, you have to scroll up to check the type of a variable. = It also means that now-unused variables are less obvious as the declaration= s are far away from the usage, so you probably won=E2=80=99t spot that it= =E2=80=99s useless unless you look at your compiler warnings. > > Actually, a similar issue popped up in the code where that example was fr= om. The language it was written in had some unfortunate properties, one of = which was that variables not explicitly declared would instead be treated a= s properties of the current object. Because all the variables were declared= at the start of the function, it was easy to miss the fact that some varia= bles being used had not actually been declared. Of course this specific iss= ue doesn=E2=80=99t exist in C, but it is an example of why having to declar= e all your variables at the start of a function isn=E2=80=99t really a good= thing. > > If nothing else, I think we should use C99=E2=80=99s ability to declare v= ariables between statements. It makes it more likely mistakes will be spott= ed, eases reading code, and as far as I am aware, is widely supported. I really hate this. Thanks > > -- > Andrea Faulds > http://ajf.me/ > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >