
On PHP 5.3's Namespace Backslash Backlash: The PHP Internals Team was Right? - KrisJordan
http://www.newmediacampaigns.com/page/php-namespaces-backslash-example
======
wvenable
No, the PHP internals team was not right.

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.

~~~
troels
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.

~~~
wvenable
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(); }

foo1::bar(); // Namespace call foo2::bar(); // Static method call

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.

~~~
encoderer
Ok, i'll bite... why does it matter? Why on Earth does it matter? What could
you do better with the scope-resolution operator?

~~~
wvenable
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.

~~~
KrisJordan
"Half-ass Solution"

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.

~~~
wvenable
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.

------
Maascamp
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).

~~~
encoderer
Wouldn't those with non-english keyboards already have a heckuva time with PHP
given the abundance of the "$" character ?

------
generalk
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.

------
jacquesm
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.

------
jsonscripter
_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?

~~~
KrisJordan
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 :)

~~~
Maascamp
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."

------
Batsu
A wealth of links for further background, if anyone is interested on the
original issue.

<http://news.ycombinator.com/item?id=344198>

------
shaunxcode
I still don't see why the single : would not have worked?

~~~
vulpes
Because a single colon is used in an alternative if/else/foreach etc syntax:

    
    
      <?php if($var == true): ?>  
      Hello world  
      <?php else: ?>  
      Cake is a lie  
      <?php endif; ?>
    

Edit: syntax

~~~
kenver
It's also used in the ternary operator

    
    
      x = condition ? if_true : if_false;

------
TweedHeads
Somebody please take PHP, fork it, fix all the annoyances and inconsistencies,
rename it as PHX and I'll drop old PHP like a herpetic whore.

