Finally namespaces

There’s a lot of whining whining about the new namespace separator these days. Not only on blogs. At first I was a bit negative towards the choice but is more and more convinced it is a good one.

First of all, few of the people complaining seem to have read the RFC documents explaining in detail the pros and cons of different choices. So here goes, read carefully before deciding.

To be honest. If some of the other suggestions in the RFC “Namespace separators” above would have won I think a lot more people would have had better reasons to rant. The backspace “\” is probably the most readable choice and thus less prone to typos which is a Good ThingTM.

Most of the criticism seem to stem from the problems you could get from having namespaces in strings and that backslash is used for escaping. I am a unix based developer but I guess that to developers using windows this is a no brainer. They’re already used to have a backslash in another context. If you then have a look at the way many projects, including for example Zend Framework, organize their classes and what should be namespaces into directories it makes sense to a lot of people.

So it’s not all bad. I’m looking forward to not having to instantiate insanely named classes like

$upload = new Zend_File_Transfer_Adapter_Http();
Tagged with:
Posted in PHP
5 comments on “Finally namespaces
  1. I’m one of the ‘whiners’, and yes, I did read the problems and discussion, and \ is still a poor choice. That’s my view – it’s not ‘whining’.

    :: or ::: would have made better choices. Heck, even > would have made a better choice. \ is a well understood symbol which means something in PHP already, and will end up causing problems or limiting the ability to do some dynamic stuff ($variable namespace components I’m betting, but it might be something else). What it seemed to come down to is “\ is easier to type” vs ” ::: confuses me to look at”.

    ::: is visually similar to :: and therefore indicates a similarity in purpose (much like == and ===). People complain about those, but they serve a purpose. Do they trip some people up in development? Sure, but everyone gets tripped up by something. \ is going to trip people up as well.

    Given PHP’s history of having multiple aliases for the same function, I’m a bit surprised that the option of both wasn’t given. \ or ::: could be used, and let the mass of developers out there decide by actually using it in real code for awhile. If the PHP group would want to make a different choice for PHP6, fine.

  2. Josh Davis says:

    Regarding the article’s example, if you’re in your own namespace you’ll still have to write it as $upload = new \Zend\File\Transfer\Adapter\Http();
    …but that’s right, if you’re already in the \Zend\File\Transfer namespace, you’ll only have to write $upload = new Adapter\Http();…and that’s pretty sweet :]

  3. Danne says:

    That’s my view – it’s not ‘whining’.

    I did not mean to offend anyone by using the word “whining”. Maybe the word was a bad choice ;) I respect your opinion!

    Regarding the ::: versus :: I totally agree with a lot of people. When having many of those on the same line it is confusing to the eye. Comparison to == and === I think is not really valid as they are more closely connected in meaning and easier to read. Readable code is actually rather important.

    I’d also say that the :: and ::: would be even more confusing to new programmers than the = versus == operators.

    I don’t think having multiple aliases on functions is a good thing. Even worse would aliases on operators be.

    $upload = new \Zend\File\Transfer\Adapter\Http();

    I actually like it. It’s not directories but almost related. Way better than $upload new Zend:::File:::Transfer:::Adapter:::Http();.

  4. devsmt says:

    php core developers should start thinking at the beaty of the language, which is drastically lower than the competitors, non only at the moment convenience

  5. Chris says:

    This is why C# is beginning to look better and better. I have been a hardend PHP developer for 10 years now, but some of the things the PHP group is doing is just plain stupid.

    Personally I think we are going to start seeing the downward spiral of PHP soon. Stupid things like

    $object = new object();
    $object->method();

    is cool, but say you want to access objects static methods then you have to

    object::staticMethod();

    and that is just stupid. C# is the same for all methods regaurdless of if you are in the objects context or not. Why not use the same operator for all object access types. Another thing that has started to bother me about PHP is the lack of support for true properties like C#, PHP5 has been praised for its OO capabilities, but honestly it really did nothing more then add a few “magic” methods and the scope visibility keywords. Also no support for partial classes etc.

    I am not too fond of the choice of \ for the namespace scope seperator it is just piss poor design. I would also kill to see full out type hinting on method parameters as well.

    Thanks!

1 Pings/Trackbacks for "Finally namespaces"
  1. [...] Danne has the stuff, but I can tell that backslash is the buzz! [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>