On Jan 19, 2010, at 5:54 PM, Alain Williams wrote:
>>> $eep->oop()->ork()->ah()->ah();
>>> 
>>> the newcomer will have to spend significant time rummaging around the
>>> source code to figure out what classes are involved.
>> As opposed to:
>> $oop = $eep->oop();
>> $ork = $oop->ork();
>> $ah = $ork->ah();
>> $ah2 = $ah->ah();
>> 
>> where it instantly becomes crystal clear! Come on, this argument of "I 
>> could read any code without ever knowing anything about anything but you 
>> feature broke it" is getting really stale. You couldn't, and the feature 
>> changed nothing.
> +1
> 
> At least with $eep->oop()->ork()->ah()->ah() you don't have stray/unwanted
> variables hanging round to confuse (or be misused) later.


+1

It also supports the "allocation is not initialization" (or anti-RAII) pattern 
found in languages like Objective-C:

Objective-C:
String *s = [[String alloc] initWithFormat:@"I'm a little teapot, %@ and %@", 
@"short", @"stout"];

PHP:
$s = (new String)->sprintf("I'm a little teapot, %s and %s", "short", "stout");

(Obviously a very, very contrived example, meant only to illustrate the 
pattern.)

-- Gwynne


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

Reply via email to