PHP Gets Namespace Separators, With a Twist 523
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."
Re:I have to say they are working really hard.... (Score:5, Informative)
Re:Going back to DOS style... (Score:4, Informative)
Uhm no. Because the DOS commands used '/' for indicating options as opposed to the '-' of the UNIX world.
Re:Going back to DOS style... (Score:2, Informative)
which was based on CPM and VMS.
Re:HOLY FUCKING SHIT!?!?! (Score:5, Informative)
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.
Classes, namespaces, and subnamespaces (Score:4, Informative)
Re:what wrong with (Score:2, Informative)
PHP uses the . as the concatenation operator. PHP does not support operator overloading...
You don't need operator overloading. To use the same symbol in different contexts.
You need a parser worth its salt.
a.one = $b.two . $a.one
Only has one use of the concatenation operator if 'a' and 'b' are namespaces.
A good convention is to simply require space around the concatenation operator. Or to require both operands meet the lexical conventions of a variable or string constant, for it to be interpreted as a concatenation.
I.e. $X = $A . $B
Is a concatenation
$X = $A.$B
Is a parse error
$X = $A.B
Is an assignment of 'X' to the 'B' variable within the 'A' namespace
Re:so what's the problem here? (Score:5, Informative)
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.
Re:Going back to DOS style... (Score:1, Informative)
I was wondering the same, Google helped very little, maybe lower bandwidth? Seems useless to link to. Not sure why Wikipedia is mirrored so often, what is Wikipedia's uptime? I'd be shocked if it were below 99.9%, maybe even a 5-niner.
Pikiwedia (unlike Wikipedia) is plastered with adverts, which I suspect is the reason for its existence, along with most other unofficial WP mirrors. WP provides a ready source of content to attract eyeballs. That's it; it's for their benefit, not yours.
Maybe I'm being cynical, but there's not even a search box on the site (perhaps because it doesn't include all the WP content anyway). It even copies the "welcome to Wikipedia" message on its front page.
Re:HOLY FUCKING SHIT!?!?! (Score:1, Informative)
Umm C# would be.
using System.Windows.Controls;
ListBox box = new ListBox();
Re:what wrong with (Score:5, Informative)
Re:PHP sucks, but it has a very important niche (Score:3, Informative)
Re:Another fashionable addition for PHP: (Score:2, Informative)
Re:Another fashionable addition for PHP: (Score:3, Informative)
In you example, F() took only two arguments, and the extra processing overhead of the function call was (presumably) not a concern. There are times when one or the other of those factors is practical. If the inner loop needs 15 variables (and is modifying some of them), the code can become far less readable than a simple goto, and noticably less performant. Of course, code performance is less of an issue every decade, but multiply nested loops are the one place where it still tends to matter.
And just to add to that (Score:3, Informative)
calling a computer programmer a "software engineer" is like calling a crack whore a "courtesan".
There's no "engineering" involved for ninety nine percent of them.
Re:It's all a joke (Score:3, Informative)
Yes but we are talking about a very, very slim minority here are we not? No offense intended but it seems like your whole point is hinging on the absolute minority of people out there. I can't think of any systems off hand that do this
According to Wikipedia, the circumflex accent is "used in written Croatian, Esperanto, French, Frisian, Norwegian, Romanian, Slovak, Vietnamese, Romanized Japanese, Romanized Persian, Welsh, Portuguese, Italian, Afrikaans, Turkish and other languages".
I don't know the keyboard layouts used by all of them, but I'd bet most (if not all) of them use a dead key for both the caret and the circumflex rather than including additional keys, and Portuguese and French have a reasonable number of speakers. Plus there are those who, despite not speaking one of these languages, still have dead keys (for example on US-International [wikipedia.org]). What's the layout used by the people who speak Spanish in the US? If it's US-International, that should be a sizable part of the population even in an English-speaking country.
So spend the $5 and get a new keyboard?
Um, no, not always possible. I know this comment went more into my particular problems, but still I saw similar complaints on Reddit. I guess people in other countries also have the same issues of every now and then having to deal with other layouts.
Re:Easier on which keyboard layout? (Score:1, Informative)
But we did start our own language, PHP was created by Danish-Greenlandic programmer, so I'd say it is very Scandinavian.
Re:Another fashionable addition for PHP: (Score:5, Informative)
Goto's are useful. Labels are useful. Yes they can lead to problems, but so do things like pointers, dynamic typing, operator overloading, namespaces and automatic memory management. But they can also solve problems that are otherwise intractable, which is what the GP was trying to tell you. Dismissing them just because E. Djisktra said so is not really good enough.
If you want an argument from authority, or just a good read, here's Donald Knuth on Structured Programming with GOTO Statements [snu.ac.kr]. You need to read that paper before you can have a proper opinion on the GOTO statement. Otherwise you're just adhering to dogma.
Re:It's all a joke (Score:5, Informative)
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
Re:The BASIC of the 21st century (Score:2, Informative)