Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96851 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94997 invoked from network); 12 Nov 2016 13:59:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Nov 2016 13:59:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.43 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 74.125.82.43 mail-wm0-f43.google.com Received: from [74.125.82.43] ([74.125.82.43:35876] helo=mail-wm0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/24-35596-73027285 for ; Sat, 12 Nov 2016 08:59:20 -0500 Received: by mail-wm0-f43.google.com with SMTP id g23so24962479wme.1 for ; Sat, 12 Nov 2016 05:59:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=WqQlnXmhl0IUQf4CkoiR1RxYOibco97T8+AMb3lHHZk=; b=B181l5Jtptaz+LHa+Mvp3v22UTuVw+BqUV2Amum6PwisQkZSSx6SejXSzDPSJyT2Al k+6l2Ah4mgJcQZ8UH9lOarzv+R/HzSm068B3NhhyLCBs6tQrh6IDYKFcPjccCvEb0LDo DzzWgoZdQv9LQBUudQDoofVC8jkvqbawWV5QcHLsnetKLG9f1ev0+MxCB7VZAWxBTJpl 12PdEtEE0VZT1oo94o7atDh3uxHBhGwMwfw2YTkJE1f3W7LZSn1Uc94rk/DGKcWng8VR JWoU/HTTdXlN7uG1pseQiDeYXZ+fEK/ODHJceMrpGNWX6iTiyOVnHNk/wQbRANfw+I5S zHbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=WqQlnXmhl0IUQf4CkoiR1RxYOibco97T8+AMb3lHHZk=; b=e/MNCmpE/mLg/3anLL+e5xAIFOZIqLsOXqwKP051Gu+GWWdg7aD9Oxr3wb7YQYfzCk zFqLXldk1uf+ThqfkzqFXgj8Jd/z0KNKPRIBevR3tOXhHNrXdM6VuRBCXMl2FRdq6Gdx XDt/tYaClTBWijSLAlIOO7hPO6oQrNPibJuINOkHJ3Q0Agg/I7u8lOfY5c22NMNtFgQx /kNEPWqklMqaO4t1Khcp4Nl8OUW6aCrvjQz9Rw17hCXJfK76HWNHvUIDaJGA2Vxe3Xsb LOMpgA1vJ6Q41qo29/tu2v5K7steDv35P9upkNRSxQ05CKV6LQlDJVN3l1ULNuuTkBUZ wYeQ== X-Gm-Message-State: ABUngvdpKueZBaswhadGKYvUgUGkQi9Hus60ZxJX0qpMdLQjozqZV7w3GUac9MflLn7Wu/gC70vqCmRMkiOsUw== X-Received: by 10.28.214.133 with SMTP id n127mr3028436wmg.28.1478959156952; Sat, 12 Nov 2016 05:59:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.170.79 with HTTP; Sat, 12 Nov 2016 05:59:16 -0800 (PST) In-Reply-To: References: Date: Sat, 12 Nov 2016 14:59:16 +0100 Message-ID: To: Joe Watkins Cc: "Christoph M. Becker" , PHP internals Content-Type: multipart/alternative; boundary=001a11474194300c3605411b0301 Subject: Re: [PHP-DEV] Re: C89 vs. C99 From: nikita.ppv@gmail.com (Nikita Popov) --001a11474194300c3605411b0301 Content-Type: text/plain; charset=UTF-8 On Sat, Nov 12, 2016 at 2:21 PM, Joe Watkins wrote: > Morning Nikita, > > All good points, that it's hard to refute. > > However, right now, I know where all variables that are going to be used > are declared, no matter the size of the function or it's complexity. If not > at the very top, eyes get good at scanning for blocks. > > What I don't want is to have to scan already complicated code to find out > when a variable was declared. > > We need to have rules of thumb, and unless someone can defend their use > rigorously, I would say the rule of thumb that code shouldn't be mixi ought > to be followed. At least it ought to be followed in the top layer of PHP > (anything inside a PHP|ZEND_FUNCTION and such). > > A defence of elegance is legitimate, so long as their use does genuinely > increase elegance. Such examples exist, but I think more examples of mixi > code being harder to follow exist ... > > Cheers > Joe > I have the feeling that we both sort-of agree, but are really talking about different things. 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) Thanks, Nikita --001a11474194300c3605411b0301--