Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76244 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65095 invoked from network); 29 Jul 2014 02:23:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jul 2014 02:23:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=zxcvdavid@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=zxcvdavid@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.46 as permitted sender) X-PHP-List-Original-Sender: zxcvdavid@gmail.com X-Host-Fingerprint: 209.85.220.46 mail-pa0-f46.google.com Received: from [209.85.220.46] ([209.85.220.46:35526] helo=mail-pa0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/B3-41808-2A507D35 for ; Mon, 28 Jul 2014 22:23:31 -0400 Received: by mail-pa0-f46.google.com with SMTP id lj1so11528978pab.19 for ; Mon, 28 Jul 2014 19:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:message-id:in-reply-to:references:subject :mime-version:content-type; bh=2Vr+tqPYgtlTywnoXsaYzWKNSARurkB2mP9mZC2Z8KU=; b=DMoxxm0832IfqE5nVrs7HWSPQTmvX9c+dCHVNvfQ4zz6rfoDAsJsETfriQ3XeYo4vE HUF9v05ylOoEkqN0Z3uHK9Q1NSN/5gwRQmU0OdlkNunSYOkEInxhm1bxbPFx8JM1tTqF vNjB09AB//m1p+K+uRM4837m08rG7dx/G43FIAxWiPlmz41M6xNmbTLgMAUYHTH382WL 4iPQCBHymFarGwkCrL8kDgYZBYcII9WVlshELYiwOAkOiTHnZ8zlLa5+q8hVCOugTcAl b7KpsrP+mDZB0kcI6T3tXjLRS5/e4dYulwFOxCF2JM7EAtekAXDd43S9yJS0QBLWFFzh 7Psw== X-Received: by 10.68.57.232 with SMTP id l8mr42597402pbq.79.1406600621822; Mon, 28 Jul 2014 19:23:41 -0700 (PDT) Received: from [10.0.10.141] (li664-244.members.linode.com. [106.186.119.244]) by mx.google.com with ESMTPSA id ce13sm26538780pdb.76.2014.07.28.19.23.39 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 28 Jul 2014 19:23:41 -0700 (PDT) Date: Tue, 29 Jul 2014 10:23:37 +0800 To: Xinchen Hui Cc: Andrea Faulds , Derick Rethans , Nikita Popov , Julien Pauli , PHP Internals Message-ID: In-Reply-To: <-611365610874328433@unknownmsgid> References: <71A78449-A62C-400D-A01F-5668930A7BED@ajf.me> <-611365610874328433@unknownmsgid> X-Mailer: sparrow 1.6.4 (build 1178) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="53d705a9_684a481a_142" Subject: =?utf-8?Q?=E5=9B=9E=E5=A4=8D=EF=BC=9A_?=[PHP-DEV] Thoughts on C version supported for PHP-Next From: zxcvdavid@gmail.com (Wei Dai) --53d705a9_684a481a_142 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline > =20 > =E5=8F=91=E8=87=AA=E6=88=91=E7=9A=84 iPad > =20 > > =E5=9C=A8 2014=E5=B9=B47=E6=9C=8828=E6=97=A5=EF=BC=8C22:20=EF=BC=8CAn= drea =46aulds =E5=86=99=E9=81=93=EF=BC= =9A > > =20 > > =20 > > On 28 Jul 2014, at 15:00, Derick Rethans wrote: > > =20 > > > > Well, we don=E2=80=99t need to allow all of C99. We can simply al= low using > > > > features that are widely supported and actually useful. =46or exa= mple, > > > > declarations between statements, > > > > =20 > > > =20 > > > =20 > > > I think that makes code a lot less readable, so I would not be in f= avour > > > allowing this in our coding guidelines. > > > =20 > > =20 > > =20 > > Really=3F I=E2=80=99ve found that declaring everything in advance mak= es for hard-to-read code. To take an example from code I=E2=80=99ve writt= en (admittedly not C code - GML if anyone=E2=80=99s curious - but it migh= t as well be), the first line of a function looked like this: > > =20 > > var list, hashList, text, i, pluginname, pluginhash, realhash, url, h= andle, filesize, progress, tempfile, tempdir, failed, lastContact, isCach= ed, env; > > =20 > > Even broken onto multiple lines, declaring everything at once isn=E2=80= =99t nice. =46or large functions (and some functions have to be large nec= essarily), declaring everything at the start just means a long list of va= riables and I would argue impairs code readability. > > =20 > > You should declare variables when and where you need them. If everyth= ing is done at the top, you have to scroll up to check the type of a vari= able. It also means that now-unused variables are less obvious as the dec= larations 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. > > =20 > > Actually, a similar issue popped up in the code where that example wa= s from. The language it was written in had some unfortunate properties, o= ne of which was that variables not explicitly declared would instead be t= reated as properties of the current object. Because all the variables wer= e declared at the start of the function, it was easy to miss the fact tha= t some variables being used had not actually been declared. Of course thi= s specific issue doesn=E2=80=99t exist in C, but it is an example of why = having to declare all your variables at the start of a function isn=E2=80= =99t really a good thing. > > =20 > > If nothing else, I think we should use C99=E2=80=99s ability to decla= re variables between statements. It makes it more likely mistakes will be= spotted, eases reading code, and as far as I am aware, is widely support= ed. > I really hate this. > Thanks +1, can=E2=80=99t agree more. Thanks, Wei Dai > > =20 > > -- > > Andrea =46aulds > > http://ajf.me/ > > =20 > > =20 > > =20 > > =20 > > =20 > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > =20 > =20 > =20 > -- =20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php --53d705a9_684a481a_142--