PHP Gets Namespace Separators, With a Twist
jeevesbond writes "PHP is finally getting support for namespaces. However, after a couple hours of conversation, the developers picked '\' as the separator, instead of the more popular '::'. Fredrik Holmström points out some problems with this approach. The criteria for selection were ease of typing and parsing, how hard it was to make a typo, IDE compatibility, and the number of characters."
... and comming full circle.
Onda Technology Institute
PHP 5.3 also adds support for local GOTOs. This langauge is so up with the times.
I couldn\'t read the summary because it had an unterminated string literal.
It'll be /, just to keep things interesting.
...to make PHP the most retarded computer programming language on the planet.
It takes a man to suffer ignorance and smile
Be yourself no matter what they say
PHP uses the . as the concatenation operator. PHP does not support operator overloading...
Username taken, please choose another one.
I once did a lot of work on PHP. Today, when people ask me for upgrades I just migrate it to Python.
This unfortunate choice of the escape character for namespace separator is stupid, but seems almost irrelevant to me. How many nails do they need in the PHP coffin to bury it?
While you're livin' it up at your stately manor, I'm coding PHP out of my garage, you insensitive clod!
The World Wide Web is dying. Soon, we shall have only the Internet.
... to cause for windows servers...
imagine what directories will be deleted due to a typo!
Maybe they could starting fixing the noun-verb vs verb-noun problems instead.
Selling software wont make you money, selling a service will.
Thats all good. I personally feel its just easier to avoid PHP altogether and not have to adjust to all of the language's quirks for little to no benefits from other offerings. Simpler that way.
The number of days that an old, crusty Perl developer can laugh at another language are few and far between.
Thank you, PHP.
You should say "thanks" they haven't chosen something else. e.g Jam (build system; make analog) uses "!" as a "platform neutral" path separator. During evaluations for new build system I joked that I oppose jam since we do not need a "platform neutral" system - we need one for *nix and cygwin. To my surprise many supported me.
I think their decision to use '\' is very very dumb one.
I'm still huge fan of Objective-C in that aspect. Unlike C++, which tried to marry C and objects, ObjC took more pragmatic approach: C constructs remains C constructs and object oriented constructs got new distinctive syntax so that you can never mix up what code you are looking at.
In that aspect, I think PHP folks would regret their decision in future: '\' isn't distinctive enough and they would need to introduce more silly syntax hacks when extending language further.
All hope abandon ye who enter here.
How is it possible for even American developers to be this clueless. Which characters are convenient to type depends entirely on the keyboard layout that is used. Case in point, $ is insanely painful to type on Scandinavian layout.
If your choice of characters used in your programming language is affected by how easy/hard it is to parse the code, you probably shouldn't be involved in developing a programming language.
I think their decision to use '\' is very very dumb one.
You've summed up my opinion concisely. That is *truly* retarded to use the (almost?) universal escape character for another reason. Almost as retarded as Microsoft going with \ for a directory separator.
Get your own free personal location tracker
Except you just made a typo. It is "\" instead.
Either way, most languages use either "." or "::" for namespaces
# perl looks like
use My::CPAN::Module qw();
my $instance = My::CPAN::Module->new("junk");
# c# looks like
using System.Windows.Controls;
System.Windows.Controls.ListBox box = new System.Windows.Controls.ListBox();
# c++ looks like (I think)
namespace Blah::Blah;
# php will now look like
$object_instance = new My\PEAR\Module("myvar");
I'll leave the "looks" of PHP's method to the reader.
Looking at the IRC discussion it seems that they didn't have much of a choice.
Since PHP is a weakly typed language, using + for string concatenation would introduce a number of problems. + is used numeric addition, and thus automatically converts the operands to numbers before adding them.
So using + for string concat too would be basically impossible... When would you decide to concat the operands, and when would they be added? If you base it on the results of the string to number conversion, you get situations where the same line of code sometimes adds numbers and other times concatenates strings, or where it is impossible to concat two strings which contain only digits.
The problem is not merely that it is different.
The problem is they chose the ESCAPE character as a namespace separator.
This is even worse than using $ as the namespace separator.
Because of the problems it causes syntax highlighters, the problem it causes to programmer sanity when storing identifier names in a string.
The problem it causes when searching through and sanitizing code.
For example, since \ has a special meaning in the context of a regular expression, searching and replacing using regular expressions just got very painful.
Copy and paste no longer works for searching and substituting.
Refactoring just became a major bitch.
The whole purpose behind using '.' as string concatenation instead of '+' is that it eliminates ambiguity. What you're suggesting throws the ambiguity back in. Remember, if it's more complex for the parser to understand, it's more complex for a human to understand. As a programmer who moves between PHP and Javascript a lot, I can tell you that I miss being able to use a dot for objects when I'm in PHP, but the ambiguity in string concatenation/addition in javascript is an order of magnitude more annoying.
I suspect they're doing the same thing with namespaces. The backslash isn't used for anything except escaping strings, and I doubt that's going to add any ambiguity at all. There are a lot of problems with PHP, and it's well worth your ridicule, but making sure that separate operations have separate operators isn't one of those problems.
Since PHP is open source, someone will make a fork with a different separator and the dumber of the two choices will wither away.
It's simple: I demand prosecution for torture.
As I remember, everything more complex than just outputting the value of the variable (ie calling a method, accessing a property, etc) requires you to use brackets inside of the string. Namespaces would work the same way without adding any complexity that wasn't already there.
And this is (one of) the many reasons PHP sucks:
Java:
Attribute/Method access: foo.bar
Static method access: Foo.bar
Package access: foo.bar.baz
C#:
Attribute/Method access: foo.bar
Static method access: Foo.bar
Namespace access: foo.bar.baz
Python:
Attribute/Method access: foo.bar
Static method access: Foo.bar
Module access: foo.bar.baz
PHP:
Attribute/Method access: $foo->bar
Static method access: Foo::bar
Namespace access: foo\bar\baz
But... the future refused to change.
"People with laptops" is a very, very tiny minority?