News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen:
Use statements
March 17, 2014 @ 10:13:08

Rob Allen's latest post focuses in on something that's been a part of PHP for a while now, back when namespacing was introduced - the "use" keyword. He shares some thoughts, both from others and himself, about whether or not they make code more readable.

I was having a discussion on IRC about use statements and whether they improved code readability or not. [...] Those longer class names make it a little hard to quickly parse what it going on. The [example with "use" statements] is clearly less cluttered, but is at the expense of ambiguity. Exactly what class is User? I would have to go to the top of the file to find out. Should I use aliases? If so, how should I name them?

He went out to Twitter for advice from other PHP developers on the issue too. The feedback from his question came mostly in support of the "use" statements:

  • "I think use statements just abstract where the class is coming from. Some people find that useful."
  • "I think it's helpful seeing all of the packages used by a class without having to look through the full code."
  • "One reason I like them is that I can glance at a file and know dependencies immediately."
  • "I do appreciate what you are saying about the indirection use statements introduce."

There's also a bit of talk about "aliasing" with namespaces rather than the full classname, then using the namespace and class name in the code to "minimise ambiguity".

0 comments voice your opinion now!
use statement namespace twitter advice feedback alias

Link: http://akrabat.com/php/use-statements/

blog comments powered by Disqus

Similar Posts

Zend Developer Zone: PHP Abstract Podcast Episode 44: Ed Finkler on Spaz

PHPWomen.org: NancyW - PMP - Women in open source

7PHP.com: Speaker & Attendee Feedback Of The Previous Laravel4 Talk Of NomadPHP June 2013

Johannes Schluter's Blog: I have nothing to say - but maybe PHP...

DevShed: Enhancing Dynamic Twitter Signature Images with PHP


Community Events





Don't see your event here?
Let us know!


opinion series language laravel podcast testing symfony2 developer threedevsandamaybe community introduction release unittest code interview install configure framework experience list

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework