The author missed the only valid argument: PHP already has a namespace operator! It is '::' just as it is in C++. Classes are namespaces and PHP should have worked just like in C++ where they stole the design from in the first place.
Instead, because nobody wanted to fix the bunged up internals to make it work properly, they decided to add this new character and make the whole language that much more complicated. Now we have this new operator that we didn't need and a bunch of different syntax and semantics for accessing static class members and namespaces.
While you're right, in theory, it would take a complete change of PHP's semantics to pull that off. PHP adopted Java's static class model, even though it makes little sense in a dynamically typed, interpreted language. There are a few upsides to that (Less meta programming makes it easier to understand programs), but the downside is a rather inconsistent language.
Why would it take a complete change of PHP's semantics? Accessing static members of classes follow C++ syntax, there's no reason why namespaces couldn't follow the same syntax and semantics. It would break nothing in the PHP language spec.
namespace foo1; function bar();
class foo2 { function bar(); }
namespace foo2; // Syntax error; class foo2 already exists.
The problem is, the internals of PHP are that namespaces and classes are in different hashes and the call to either compile to entirely different byte code. The "correct" implementation would have namespaces and classes together and both calls compile to the same code. Now I accept that the PHP internals are perhaps too convoluted to resolve this issue but that doesn't make this any less terrible. It's a hack solution.
Death by a million cuts. The scope-resolution operator doesn't matter. The weird scoping rules aren't so bad. The inconsistent function parameters are really no big deal. What's one more mis-feature right?
I was really hoping that PHP was going to grow up and shed some its moronic nature but this is yet another half-ass solution.
The fact is that as much as everyone likes to complain about parameter order, the only case I've seen with the needle/haystack order flipped is the in_array() method, which in that context the flipped order just makes sense.
And I'm not sure what you mean by "weird scoping."
The real beef most people have with PHP -- and is hard to defend -- is its type coercion. But PHP is not alone here, any implicit coercions are bound to make somebody unhappy some of the time.
In summary, you're jumping on a bandwagon without any merit. Say that you can make better applications and in less time in another language. Say that you can find more talented programmers for less money. But of all the things to whine about you chose the namespace operator? Really?
You completely missed the point. Yes, you can defend all those things individually. And individually, they aren't a big deal. But together PHP seems like a big ball of mud.
I'm actually a big user (and defender) of PHP; between posting this I'm working on PHP code. I've used it since PHP 3.0 and I'm pretty forgiving of legacy problems -- it's an organic language with pieces added when they're needed. The PHP 3.0 time was great because every release (which was frequent) brought some new feature you were wishing for.
PHP 5.0 has been great and PHP 6.0 with unicode is going to be a nice addition too. But it's like 2 steps forward and 1 step back. There's no reason for PHP to add namespaces in such a confusing and different way. PHP borrows from C, Java, Perl, and C++ and anyone familiar with those languages is going to feel comfortable with it. But this namespace implementation is just bizarre. And it can't be blamed on any legacy issues or backwards compatibility.
I'd like to dial this back a bit. But not without saying that knocking down strawmen is not "defending things individually."
And really... you find it "confusing and different" that PHP uses a backslash for delimitation? Seriously? You can simultaneously wrap your mind around recursion, closures, pointer arithmetic and continuations but you're confused by the use of a backslash opposed to a colon, double-colon or triple colon?
Confusing and Different? Seriously? Variety is unambiguously good. This is mutation and evolution. And it results in languages as fantastically different as Haskell, C, F#, Python, Perl, Lisp and even PHP.
Programmers are by and large a smart bunch and the last thing we need to do is dumb-down languages for the least common denominator.
Variety is not unambiguously good. Variety is good if you're producing something different. Variety is bad if it's different for no reason. I work in many different languages, and having to learn yet another syntax unnecessarily is not a good thing.
The PHP developers had a chance to add namespaces in a way that didn't make the language worse -- they didn't do that. Sure, maybe it's not a big deal -- just like all the other bad decisions, like magic_quotes, weren't a big deal. It's just disappointing that they couldn't do it right.
Frankly, and I hate to devolve into the ad hominem, you're taking this religiously. You've turned this into a Bikeshed issue.
This is only a "bad decision" because you've decided that YOU know TheWay.
Those languages that use the dot for scope resolution have created an ambiguous operator in the plus sign. Concatenation? Addition? In a dynamic language you'll have to do some looking. And that's a good thing? Just because it's familar to you?
And for your test of variety, I truly enjoy that you ommitted every single langauge that would give you some actual variety. You chose 6 languages all from the same paradigm.
This is the last reply I'll be writing. I made the mistake of thinking that if you are a programmer, able to presumably create software that actually ships and makes peoples lives easier, you MUST be able to hold and weigh opposing view points and judge the relevance of things. I honestly wonder if you're the type that sits on the team, picks apart working code, and refactors and refactors and never actually ships. I'm not saying you are but I am saying that everyone of those types that I have come across share your same academic sense of RightWay and WrongWay.
There are things that each language does wrong, that is, things that are confusing. But if you are CONFUSED by a backslash, you ought to reconsider your choice of profession.
And finally, something you seem to have glossed over, is that if you find this as important as you seem, why don't you take the opportunity to create a working patch that uses the double-colon?
Those languages that use the dot for scope resolution have created an ambiguous operator in the plus sign.
Yeah, I think that's a bad idea too. Javascript is particularly bad because it's dynamically typed -- you may have to insert a few extra empty strings to get what you want.
You chose 6 languages all from the same paradigm.
Um, yes, that's the point!! All languages from the same paradigm doing things mostly the same. I can switch between Java, C#, PHP, and Javascript without too much trouble. If you've got a radically different language, it doesn't really matter to this discussion.
This is the last reply I'll be writing.
This is good, since you've run out of things to say except attack my programming skill and teamwork even though you don't know me. Typical.
But if you are CONFUSED by a backslash, you ought to reconsider your choice of profession.
I'm sorry you feel that everything is beyond criticism. I wonder, is there anything you actually care about? Go back to coding in COBOL -- if "ADD 1 TO VARIABLE" doesn't confuse you, I'm sure you'll be happy.
why don't you take the opportunity to create a working patch that uses the double-colon?
It's a fair question. Unfortunately I'm very busy, I have enough time to code, take care of the kids, and post to hackernews. I'm also a PHP programmer not a C programmer (right now, anyway). But the implication of your question is that I have no right to complain about open source projects?
The PHP internals team could have pushed 5.3 out the door last November with :: as the separator. It was in the alpha. It worked. Except it didn't. If they had pushed it out then, knowing it broke down, that's a half-ass solution.
They changed it. They made it right. It pushed the release back by over half a year. That's hardly half-assed.
They made the easy choice -- add a character to the language so the parser has something else to grab onto so they can treat static class access and namespace access as different things.
I don't call that making it right. It made it "work". Adding another confusing symbol to a language already filled with symbols is not right.
A proposed work around for the ambiguity was being explicit about ambiguous cases.
The internals team wanted to do ::, they did ::, and they convinced themselves otherwise (and suffered through a lot of pain in the process).
[17:00:05] <@CelloG> I am the strongest advocate for :: - every patch I have made up to this one was designed to preserve it, and I am convinced it just isn't technically possible to use it
I've read that link and I understand it. They treat namespace access and static class access as different things. If they were the same, and namespaces and classes shared the same hash, and static class access and namespace access where the same (like in C++) this would be a non-issue.
As for your ambiguity, it's a simple name clash. On the second declaration, you should get an error because foo::bar is already defined. You know, like you would in C++.
Ummm, no. In C++, classes are looked up the same as namespaces, you can have a namespace called foo::foo::foo::foo which contains a class called foo!
The only restriction is that you can't have a class or namespace with the exact same fully qualified name. That's a perfectly reasonable restriction. The whole purpose of namespaces is so you can have a class called foo in a different namespace from another class called foo.
It doesn't change the fact that, the way you're suggesting, I cannot have both a namespace and class named foo in the global scope or within the same namespace.
if I did, I'd see the same ambiguity the PHP internals developers were discussing.
And spin it however you'd like, having a namespace conflict with a classname is far more confusing than trying to wrap your head around this (apprently) insanely complex use of the backslash operator as a namespace delimiter.
I cannot have both a namespace and class named foo in the global scope or within the same namespace.
Yes, but you make that sound like a bad thing. In real life, having classes and namespaces with the same names would not be good. Nobody is going to do it, so why support it? Can you think of an example where it makes sense to have a class and namespace with the same name?
And spin it however you'd like, having a namespace conflict with a classname is far more confusing
Really? Because that's how every other language works from Java, C#, C++, Perl, etc. If you didn't know that, it's probably not such a big deal.
Having started using the new namespaces as well as some of the other new features (late static binding FTW), I completely agree with the author.
I too got caught up in the hype when the whole namespace debacle first hit, but after using them in a sizable project I have no gripes whatsoever.
Also, the character choice isn't really bad at all. And before those with non-english keyboards start griping, I'm currently consulting in Stockholm and as far as the Swedish keyboard goes, you guys have much bigger fish to fry (it's even hard to type a semi-colon).
So the PHP internals team made a poor decision, but because namespaces are better than the ridiculous measures taken to work around the lack of namespaces, they're vindicated?
No. PHP may be getting better, but I can't stand it any longer after using things like Ruby and Python.
My approach to new features in PHP is very pragmatic, after having been bitten a couple of times I wait for two major releases before using a new feature. The ones that survive the intermediary release are usually here to stay.
PHP is a great language in concept but I really wished the powers that be would have a little more sense of orthogonality in what they build.
Anybody that designs a language should have a look at the 68K series assembler, it's so compact and predictable. They did a real good job there. And the PHP designers did a lousy one.
Scope and namespaces in PHP are amongst the weirdest I've ever encountered in a language.
After using namespaces in 5.3 I'm more than sold, I'm in lust
Woah now, it's just a little syntax... relax a little. There's a whole world of programming languages out there with more variations on syntax than you can dream of. Then again, maybe I don't see what the big deal is?
The lust has nothing to do with the syntax and everything to do with the functionality. Namespaces are long overdue in PHP (how has it taken so long)?
This is going to make developing larger scale projects (and projects that mix and match 3rd-party libraries) very different than pre-5.3
The initial uproar over the backslash failed to provide any commentary on the underlying implementation. I regret conflating the syntax with the implementation because the implementation is rock solid. The syntax, with a little practice, winds up feeling more natural than you'd think (or perhaps feel comfortable admitting :)
Though I agree with you, I'd argue that namespaces took so long due to the fact that (as you state in your post) PHP is the most widely used scripting language today.
Like all widely used languages it evolves more slowly than those with smaller or niche communities. The PHP devs focus has clearly been stability and integrating the most widely used extensions into the core.
As you yourself said, "so goes the life of a language whose design is driven by demand and not theory."
Then again, maybe I don't see what the big deal is?
The big deal is that 99% of the PHP community has no clue about programming, so if they hear someone talking about something they get overly excited about it and start talking about it too. That way they "look smart".
This is not totally unique to PHP, but man, they have a weird-ass community.
The author missed the only valid argument: PHP already has a namespace operator! It is '::' just as it is in C++. Classes are namespaces and PHP should have worked just like in C++ where they stole the design from in the first place.
Instead, because nobody wanted to fix the bunged up internals to make it work properly, they decided to add this new character and make the whole language that much more complicated. Now we have this new operator that we didn't need and a bunch of different syntax and semantics for accessing static class members and namespaces.