6 ms·
On PHP 5.3's Namespace Backslash Backlash: The PHP Internals Team was Right?
- jacquesm 17y agoMy 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.
- shaunxcode 17y agoI still don't see why the single : would not have worked?
- vulpes 17y agoBecause 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
- shaunxcode 17y agostun taken - I seriously had forgotten about that.
- kenver 17y agoIt's also used in the ternary operator x = condition ? if_true : if_false;
- Maascamp 17y agoHaving 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 17y agoWouldn't those with non-english keyboards already have a heckuva time with PHP given the abundance of the "$" character ?
- jsonscripter 17y agoAfter 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?
- jrockway 17y agoThen 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.
- KrisJordan 17y agoThe 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 17y agoThough 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 17y agoA wealth of links for further background, if anyone is interested on the original issue. http://news.ycombinator.com/item?id=344198 http://news.ycombinator.com/item?id=344198
- wvenable 17y agoNo, 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 17y agoWhile 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 17y agoWhy 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 17y agoOk, i'll bite... why does it matter? Why on Earth does it matter? What could you do better with the scope-resolution operator?
- generalk 17y agoSo 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.
- TweedHeads 17y agoSomebody 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.