On 12.11.2016 at 14:59, Nikita Popov wrote:

> There are two ways in which you can have code mixed with declarations. The
> first one is within a single "basic block", like this:
> 
>     int a = ...;
>     b = ...;
>     int c = ...;
>     a = ...;
>     float d = ...;
>     // ...
> 
> I can totally see how some many people might find this kind of code to be
> objectionable.
> 
> However, the use-case that I have in mind is different -- it's the case
> where declarations **are** at the top of a block -- but its the top of a
> basic block in terms of control flow, not a block in terms of C syntax. To
> clarify what I mean by that: For a compiler (and arguably, a programmer),
> the control flow of
> 
>     if (...) {
>         return;
>     }
> 
>     // Basic block starts here, but not C block
>     type var = ...;
> 
> and of
> 
>     if (...) {
>         return;
>     } else {
>         // Basic block starts here, and C block
>         type var = ...;
>     }
> 
> is the same. The declaration in both cases is at the top of a control-flow
> block. It just doesn't happen to coincide with a syntactic C block.
> 
> This is the case I'm interested in.
> 
> Anyway, I'll just leave this gem from our codebase here:
> https://github.com/php/php-src/blob/master/ext/standard/http_fopen_wrapper.c#L114
> (Some of those variables have 500 lines of code between declaration and
> first use)

In my humble opinion, inline declarations wouldn't make this code
understandable – there are simply way too many variables and the
function is way too large generally, and as such should be broken up.

-- 
Christoph M. Becker


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to