Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46812 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80119 invoked from network); 19 Jan 2010 17:18:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2010 17:18:08 -0000 Authentication-Results: pb1.pair.com header.from=oorza2k5@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=oorza2k5@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.226 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: oorza2k5@gmail.com X-Host-Fingerprint: 209.85.219.226 mail-ew0-f226.google.com Received: from [209.85.219.226] ([209.85.219.226:63130] helo=mail-ew0-f226.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/F9-29385-F49E55B4 for ; Tue, 19 Jan 2010 12:18:08 -0500 Received: by ewy26 with SMTP id 26so1233639ewy.23 for ; Tue, 19 Jan 2010 09:18:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=8fQS+/AcIJ1tE8eDtpFJVO7bcRPFEqo5H1JsemX8NJw=; b=Q1K8mutoKXgg7lOafmWHLR4oqJMEo/QgjCwkNLIjMEROg5NommypknriCF7ABxSMqg qvGQh0r0iVmESDZKyWCg5vWKgQqHwqz8fnwftTZJpyntP2JFdgjMotMKuZClna4nbYg/ C6w60qh2n6vy4/b9pkEYoR8u5zjhajkmW9OPU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=BI32dB3dmIZtyfZnLt+luENiRCI5NUU0OlVltU7Zgn1bLYmVQzKvmIWM0/RE7Rzjqz goxvbuRHP4b/uxJzfZLpiR2BKxJ5ij/EMcatU5TKLSiKqulV/DNvIxmv4YxvgtN1d4Wg EDnr61yg7Ldw0fEHAAaMY+bb5W4aOukm7qhfM= MIME-Version: 1.0 Received: by 10.213.1.132 with SMTP id 4mr2596422ebf.11.1263921483860; Tue, 19 Jan 2010 09:18:03 -0800 (PST) In-Reply-To: <4B55E591.8060708@lerdorf.com> References: <4B54FC87.8070106@zend.com> <4F.56.22457.408955B4@pb1.pair.com> <4B55D850.8000604@zend.com> <68de37341001190820p486b7c31o5689ab5554b8d260@mail.gmail.com> <4B55E591.8060708@lerdorf.com> Date: Tue, 19 Jan 2010 12:18:03 -0500 Message-ID: <68de37341001190918x18d4d026ie8cac60b23d59c42@mail.gmail.com> To: Rasmus Lerdorf Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: function call chaining From: oorza2k5@gmail.com (Eddie Drapkin) On Tue, Jan 19, 2010 at 12:02 PM, Rasmus Lerdorf wrote= : > Eddie Drapkin wrote: >> On Tue, Jan 19, 2010 at 11:05 AM, Stanislav Malyshev wro= te: >>> The second was next on my list, while the first seems to me kind of exo= tic - >>> why create object only to call one method and immediately drop it? Why = this >>> method is not static then? >> >> >> Why would this imply "dropping" the object? >> >> This: >> =C2=A0 =C2=A0$foo =3D (new bar())->someSetter(); >> Looks a lot better than this >> =C2=A0 =C2=A0$foo =3D new bar(); >> =C2=A0 =C2=A0$foo->someSetter(); > > The second version is much clearer. =C2=A0You know exactly what $foo is. = =C2=A0In > the shortened version you have no idea what $foo is without reading the > code for the someSetter() method. =C2=A0On first glance I would assume th= at > $foo would be the success/failure return of the setter and that the > object is dropped. > > -Rasmus > I don't think that's necessarily a fair statement to make. If you were working within a set of guidelines, or even within just a style, that "dictated" that setters return $this consistently across several class (or even all of them), it wouldn't be any less clear than the second. Assuming that you had no idea what the class did, or what any of its methods returned, you could make the argument that the former is less readable, but then again, if you're making wild guesses at what methods return without reading code/documentation, you've got bigger issues than the readability of a constructor + method call. Even accepting the argument against readability, I don't think it's strong enough to say that the feature is unacceptable. If used properly, it can very well aid in the concision and readability of code (especially if you're a fan of the "fluent" interface); I don't agree with the thinking that presenting a case where a feature can be used improperly is grounds for its dismissal. Were that the case, nearly every feature in the language would be able to be dismissed, no? And to illustrate what I mean by fluent interface, there's a lot of cases in code that I've written where I have something that looks like: Class::someFactory()->blah()->blah()->foo()->bar()->baz()->hello()->world()= ; //well, this is a little extreme Which I think looks much better, and is more self documenting, as: (new Class())->blah()->blah()->foo()->bar()->baz()->hello()->world();