回复: [PHP-DEV] Thoughts on C version supported for PHP-Next
| From: | Wei Dai | Date: | Tue, 29 Jul 2014 02:23:37 +0000 |
| Subject: | 回复: [PHP-DEV] Thoughts on C version supported for PHP-Next | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-76244@lists.php.net to get a copy of this message | ||
>
> 发自我的 iPad
>
> > 在 2014年7月28日,22:20,Andrea Faulds <ajf@ajf.me (mailto:ajf@ajf.me)>
> > 写道:
> >
> >
> > On 28 Jul 2014, at 15:00, Derick Rethans <derick@php.net (mailto:derick@php.net)>
> > wrote:
> >
> > > > Well, we don’t need to allow all of C99. We can simply allow using
> > > > 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’ve found that declaring everything in advance makes for hard-to-read code. To
> > take an example from code I’ve written (admittedly not C code - GML if anyone’s 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’t 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’t spot that
> > it’s 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’t exist in C, but it is
> > an example of why having to declare all your variables at the start of a function isn’t really a
> > good thing.
> >
> > If nothing else, I think we should use C99’s 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.
> I really hate this.
> Thanks
+1, can’t agree more.
Thanks,
Wei Dai
> >
> > --
> > Andrea Faulds
> > http://ajf.me/
> >
> >
> >
> >
> >
> > --
> > PHP Internals - PHP Runtime Development Mailing List
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php