Call chaining works really well for something like jQuery where you are constantly working with a generic type of data (a selection of dom nodes in that case) with common methods. Most of what you do in jQuery is either modifying what is selected, or calling methods on the selection.
There are some "getter" versions of various methods that naturally don't chain, but all other methods that can be called on a selection are chainable. It's this momentum in the library that makes the practice easy for developers, because it's easy to learn the few exceptions when its 90% chainable vs. 10% not-chainable. I have doubts that enough of MediaWiki's data structures would be conducive to chaining for reasonable momentum to be established.
Another issue is, until we have PHP 5.3 as a base requirement, the use of closures isn't allowed in MediaWiki. Closures are not required for call chaining, but they round out the solution by allowing arbitrary bits of code to be passed around through callbacks and iterators, making call chaining a more viable alternative for most tasks.
To the other points, about null results being treated as objects - this is all part of why call chaining is something that should be a part of the the overall architecture and not something you slap on at the last minute like a bumper sticker.
PHP is a rather primitive language, and call chaining is a fairly advanced technique (when done right) - it's really not a very good match.
- Trevor
On Wed, Nov 16, 2011 at 10:02 AM, Platonides Platonides@gmail.com wrote:
(...)
$this->getOutput() ->setPageTitle( wfMsg( 'abusefilter-examine' ) ) ->addWikiMsg( 'abusefilter-examine-intro' );
vs
$out = $this->getOutput(); $out->setPageTitle( wfMsg( 'abusefilter-examine' ) ); $out->addWikiMsg( 'abusefilter-examine-intro' );
And if $out was indeed null, just the line number would point out which object was, instead of needing to test the whole chain.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l