Baronen Posted October 18, 2009 Share Posted October 18, 2009 Hey Guys. I'm a PHP-developer from Sweden who is new at phpfreaks.com, and so far i'm liking it. At my Swedish blog I have had a discussion with a .NET developer who says that the use of Method Chaining is "bad practice" and makes the code hard to read. I use chains in my projects and personally I like them i think the code is easier to read. What do you guys think about Method Chaining, "bad practice", hard to read?, better perfomance? Quote Link to comment https://forums.phpfreaks.com/topic/178125-the-use-of-method-cahining/ Share on other sites More sharing options...
Daniel0 Posted October 18, 2009 Share Posted October 18, 2009 Personally, I think method chaining makes the code much cleaner to read if done properly. Performance-wise it doesn't matter at all. It's purely a matter of personal preference. Quote Link to comment https://forums.phpfreaks.com/topic/178125-the-use-of-method-cahining/#findComment-939173 Share on other sites More sharing options...
corbin Posted October 19, 2009 Share Posted October 19, 2009 I love method chaining. I hardly ever use it personally, but it's very convenient when it is usable. (jQuery without method chaining would be a lot more typing for example.) Quote Link to comment https://forums.phpfreaks.com/topic/178125-the-use-of-method-cahining/#findComment-939446 Share on other sites More sharing options...
448191 Posted October 20, 2009 Share Posted October 20, 2009 I haven't read the blog, but if I had to guess I'd say their may be some confusion between you and the .NET developer about what "method chaining" is. At the one side there's method chaining as used in ZF, also known as "privoding a fluent interface", then there's what has been dubbed (by someone at ThoughtWorks, don't remember who), a "train wreck". This is a typical fluent interface: $foo ->setBar(1) ->setBlah(2) ->execute(); This is a train wreck: $foo ->getBar() ->getBlag() ->execute(); I'm not implying that the difference between fluent interface and trian wreck is as simple as mutator vs accessor, there's obviously something else going on: example 2 fetches deep into the structure behind $foo, ignoring implied encapsulation, and violating the "tell don't ask" heuristic. Example 1 just operates on the same object. Quote Link to comment https://forums.phpfreaks.com/topic/178125-the-use-of-method-cahining/#findComment-940267 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.