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();
Tags: PHP
October 27th, 2008 at 11:40 pm
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.
October 27th, 2008 at 11:50 pm
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 :]October 28th, 2008 at 12:02 am
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();.
October 28th, 2008 at 1:55 am
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