Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76234 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91529 invoked from network); 28 Jul 2014 14:19:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2014 14:19:22 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.199 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.199 imap11-2.ox.privateemail.com Received: from [192.64.116.199] ([192.64.116.199:56365] helo=imap11-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/4D-26001-9EB56D35 for ; Mon, 28 Jul 2014 10:19:22 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id BA1898800D5; Mon, 28 Jul 2014 10:19:30 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id GxJGH1v62iCE; Mon, 28 Jul 2014 10:19:30 -0400 (EDT) Received: from [192.168.0.15] (unknown [90.210.122.167]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id BE4D08800E5; Mon, 28 Jul 2014 10:19:28 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: Date: Mon, 28 Jul 2014 15:19:25 +0100 Cc: Nikita Popov , Julien Pauli , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <71A78449-A62C-400D-A01F-5668930A7BED@ajf.me> References: To: Derick Rethans X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] Thoughts on C version supported for PHP-Next From: ajf@ajf.me (Andrea Faulds) On 28 Jul 2014, at 15:00, Derick Rethans wrote: >> Well, we don=92t need to allow all of C99. We can simply allow using=20= >> features that are widely supported and actually useful. For example,=20= >> declarations between statements, >=20 > I think that makes code a lot less readable, so I would not be in = favour=20 > allowing this in our coding guidelines. Really? I=92ve found that declaring everything in advance makes for = hard-to-read code. To take an example from code I=92ve written = (admittedly not C code - GML if anyone=92s 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, = handle, filesize, progress, tempfile, tempdir, failed, lastContact, = isCached, env; Even broken onto multiple lines, declaring everything at once isn=92t = nice. For large functions (and some functions have to be large = necessarily), declaring everything at the start just means a long list = of variables 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 declarations are far away from the usage, so you probably won=92t = spot that it=92s useless unless you look at your compiler warnings. Actually, a similar issue popped up in the code where that example was = from. The language it was written in had some unfortunate properties, = one of which was that variables not explicitly declared would instead be = treated as 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 variables being used had not actually been declared. Of course = this specific issue doesn=92t exist in C, but it is an example of why = having to declare all your variables at the start of a function isn=92t = really a good thing. If nothing else, I think we should use C99=92s ability to declare = variables between statements. It makes it more likely mistakes will be = spotted, eases reading code, and as far as I am aware, is widely = supported. -- Andrea Faulds http://ajf.me/