23 points · by KrisJordan · 17y ago · 37 comments
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.
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.
// classes.php /////
namespace foo::bar;
function baz() {}
namespace foo;
class bar { static function baz() {} }
// someotherfile.php /////
include('classes.php');
foo::bar::baz(); // Ambiguity
/////
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
http://wiki.php.net/rfc/backslashnamespaces#resolution_of_t_...
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).
No. PHP may be getting better, but I can't stand it any longer after using things like Ruby and Python.
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.
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?
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 :)
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."
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.
<?php if($var == true): ?>
Hello world
<?php else: ?>
Cake is a lie
<?php endif; ?>
Edit: syntax x = condition ? if_true : if_false;