Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82622 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45444 invoked from network); 13 Feb 2015 16:50:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Feb 2015 16:50:17 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.171 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.171 mail-wi0-f171.google.com Received: from [209.85.212.171] ([209.85.212.171:56989] helo=mail-wi0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/E0-40724-54B2ED45 for ; Fri, 13 Feb 2015 11:50:15 -0500 Received: by mail-wi0-f171.google.com with SMTP id hi2so13342872wib.4 for ; Fri, 13 Feb 2015 08:50:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=bKz4CgHrhG9ErkwgzbsO5L7/iLIpgTW2RSMhiAjzAQY=; b=ebB1CKmUEhwcCLNzH+wPscbd3tV1IniUddF9f2tb62WhH1nULBJiz6/V85XmB3q5+e W19SCXw9eKJ4g7PmzOvk8s3Cjz4JlfscsOkrVFRGL2FJhD0kNQ0k0lH4SOsDqLY8Gf+O x18wHBBhp1Ib9BpjqxruvPrAjldRbTzbNjr+oAY3MnuAi1YN9zDayZwO1/3WiwmfZeUN hBTmtLBIFQTC148ZkG4jkV6hKTAWJu3HnV49XD8t3d5CLIWa5/tp5tIuiNAUzWw9SGIx jSvafGizUiSqHT3dkmaHrmVv4XzvuyMR0yaFA8o8iom28Se7c9L64WPH/xWm0SyW37XA EpRQ== MIME-Version: 1.0 X-Received: by 10.194.2.75 with SMTP id 11mr20017860wjs.78.1423846209986; Fri, 13 Feb 2015 08:50:09 -0800 (PST) Received: by 10.27.10.168 with HTTP; Fri, 13 Feb 2015 08:50:09 -0800 (PST) In-Reply-To: References: Date: Fri, 13 Feb 2015 17:50:09 +0100 Message-ID: To: marcio3w@gmail.com Cc: PHP internals Content-Type: multipart/alternative; boundary=047d7b3a834c8fa5d7050efb07cc Subject: Re: [PHP-DEV][RFC][VOTE] Group Use Declarations From: nikita.ppv@gmail.com (Nikita Popov) --047d7b3a834c8fa5d7050efb07cc Content-Type: text/plain; charset=UTF-8 On Fri, Feb 13, 2015 at 5:24 PM, Nikita Popov wrote: > On Wed, Feb 11, 2015 at 9:50 PM, Marcio Almada > wrote: > >> Hi internals! >> >> Since no new discussion topics appeared, the voting on the Group Use >> Declarations RFC for PHP7 is now open: >> >> RFC: https://wiki.php.net/rfc/group_use_declarations#votes >> Patch: https://github.com/php/php-src/pull/1005 >> >> As requested I've split the vote into two slightly different syntax >> choices, so be sure to pick the right choice if you are going to vote yes. >> The voting will close in exactly 14 days counting from now. >> > > I'm in favor of this RFC. Honestly I don't really understand the > negativity it is getting around here. > > The ability to import multiple items from one namespace is a > well-established feature you'll find in many languages employing some kind > of namespacing. I don't think the availability of what I lovingly call "IDE > vomit" is a good reason to decline a feature - a programming language > should be able stand on its own and not require IDE assistance for > reasonable use. > > The syntax seems pretty obvious as well - but maybe I just had too much > exposure to Rust, which makes extensive use of the same syntax. > I'd like to follow up with another point. I've seen multiple people claim that code that requires so many "use"s that this proposal becomes relevant violates the single responsibility principle, because it simply uses too many different classes. I don't think that this statement is correct and would like to provide an example. The responsibility of the NameResolver class [1] from the php-parser project is to resolve all names to be fully qualified where possible (which sounds reasonably narrow to me). However in order to do this it must consider a large number of different AST nodes, so that the full import list (if you individually import every class, which is customary in PHP) would look as follows: use PhpParser\NodeVisitorAbstract; use PhpParser\Error; use PhpParser\Node; use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\Use_; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Interface_; use PhpParser\Node\Stmt\Trait_; use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Const_; use PhpParser\Node\Stmt\Catch_; use PhpParser\Node\Stmt\TraitUse; use PhpParser\Node\Stmt\TraitUseAdaptation\Precedence; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\Instanceof_; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\ConstFetch; Damn, this looks unwieldy. With this proposal it becomes: use PhpParser\{NodeVisitorAbstract, Error, Node}; use PhpParser\Node\{Name, Name\FullyQualified}; use PhpParser\Node\Stmt\{ Namespace_, Use_, Class_, Interface_, Trait_, Function_, Const_, Catch_, TraitUse, TraitUseAdaptation\Precedence}; use PhpParser\Node\Expr\{ StaticCall, StaticPropertyFetch, ClassConstFetch, New_, Instanceof_, FuncCall, ConstFetch}; Which in my eyes is a much cleaner. There are simply some things that require interacting with a lot of different classes - processing a syntax tree is one of those. Lastly I would also encourage everyone to see beyond the usual object-oriented mindset. PHP is a multi-paradigm language and object- or class-oriented code are not the end of the line. While, by convention, PHP uses a 1-to-1 mapping for classes to files, this is not at all common for functional and functional-ish code. If you write function-based libraries you will define many functions in one file, which will again make use of many other functions (which are preferably imported). As such you can end up with many imports without any SRP violation. Thanks, Nikita [1] https://github.com/nikic/PHP-Parser/blob/master/lib/PhpParser/NodeVisitor/NameResolver.php --047d7b3a834c8fa5d7050efb07cc--