Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79532 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50862 invoked from network); 10 Dec 2014 18:27:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Dec 2014 18:27:20 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:56611] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/04-29826-68098845 for ; Wed, 10 Dec 2014 13:27:19 -0500 Received: by mail-wi0-f180.google.com with SMTP id n3so6140299wiv.7 for ; Wed, 10 Dec 2014 10:27:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=FGiA2VYJ41d3VqyZSUDUksQ6qf8t0Mckgzto3S/1FQ8=; b=fCLkksRi+Xtgj36pKE/GTmXDG6YDrxhSyPtCo9GXBgUwkNOhzd2tv9T69+ks98XEnM voTjcboy9sBzP0WfYts8Q/qLfUiMUZYxxPewr8Y8cAOtkVLeGaQfCgFyGC+so+RzfEbj ErG2n4HBszqDwcYVv1ZXYJmXZQJtVynt5TlcO0MNoC8yfK+8DTL/mbwURqAyknlYC9Nx YV5MqIJOf7010Hv7SRe54GXN7sQrVzOINN+YEoNOlvxHkv+cht82MySFfGYr9kO+G8rB BccMsfeytdmUMiyETr4pgWTMEPYe457Q3I6ClLbNpSoUZzX8jf2K52+iGHS2VZNfDcr/ doBQ== X-Received: by 10.194.185.167 with SMTP id fd7mr9285799wjc.108.1418236036096; Wed, 10 Dec 2014 10:27:16 -0800 (PST) Received: from [192.168.0.148] ([62.189.198.114]) by mx.google.com with ESMTPSA id fo12sm18924489wic.19.2014.12.10.10.27.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Dec 2014 10:27:15 -0800 (PST) Message-ID: <54889077.9020004@gmail.com> Date: Wed, 10 Dec 2014 18:27:03 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: internals@lists.php.net References: <95A581EE-A062-4926-BE44-BCA87FC9B356@fb.com> <9230CB24-22FC-4A0E-A9D5-F02523B65A02@ajf.me> In-Reply-To: <9230CB24-22FC-4A0E-A9D5-F02523B65A02@ajf.me> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Nullsafe calls From: rowan.collins@gmail.com (Rowan Collins) Andrea Faulds wrote on 10/12/2014 17:19: > Finally, this may encourage bad code. As someone helpfully pointed out in the reddit discussion (http://redd.it/2ot15u), this encourages breaking the Law of Demeter, i.e. that objects should only talk to their immediate friends. Usually, long chains of method calls across multiple objects are not a good idea, yet the main benefit of this RFC is to reduce the boilerplate needed for that scenario. It's an interesting thought, but reading the Wikipedia article, I see that that "Law" has acknowledged downsides, and so code breaking it is not universally acknowledged as "bad". I actually think it's a better argument against chaining property access (which implies deep knowledge of structures) than against chaining methods (which may be completely abstract actions unrelated to structure). In particular, long method chains are commonly associated with "fluent interfaces", which can be a very effective way of creating a Domain-Specific Language in an OOP system - database query builders, for instance, tend to use this approach. It may not even involve exposing additional objects at all, just "return $this" at the end of a mutator. On the other hand, methods designed to be used like that should have strong return contracts, and throw exceptions themselves on error, so neither engine exceptions nor an extra operator would be necessary if the underlying library was written well. I'm kind of on the fence as to whether this is the right solution to the problem. -- Rowan Collins [IMSoP]