Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
PHP Programming IT Technology

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."
This discussion has been archived. No new comments can be posted.

PHP Gets Namespace Separators, With a Twist

Comments Filter:
  • by FooAtWFU ( 699187 ) on Sunday October 26, 2008 @01:16PM (#25518457) Homepage
    Oh, they've been at it for a while now [www.tnx.nl] ;)
  • by Anonymous Coward on Sunday October 26, 2008 @01:18PM (#25518491)

    Uhm no. Because the DOS commands used '/' for indicating options as opposed to the '-' of the UNIX world.

  • by larry bagina ( 561269 ) on Sunday October 26, 2008 @01:20PM (#25518507) Journal

    which was based on CPM and VMS.

  • by coryking ( 104614 ) * on Sunday October 26, 2008 @02:03PM (#25518825) Homepage Journal

    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.

  • by janwedekind ( 778872 ) on Sunday October 26, 2008 @02:04PM (#25518833) Homepage
    Looking at the IRC discussion [php.net] it seems that they didn't have much of a choice.
  • Re:what wrong with (Score:2, Informative)

    by mysidia ( 191772 ) on Sunday October 26, 2008 @02:07PM (#25518853)

    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

  • by mysidia ( 191772 ) on Sunday October 26, 2008 @02:20PM (#25518959)

    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.

  • by Anonymous Coward on Sunday October 26, 2008 @02:49PM (#25519275)

    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.

  • by Anonymous Coward on Sunday October 26, 2008 @03:11PM (#25519429)

    Umm C# would be.


    using System.Windows.Controls;

    ListBox box = new ListBox();

  • Re:what wrong with (Score:5, Informative)

    by moderatorrater ( 1095745 ) on Sunday October 26, 2008 @03:37PM (#25519627)
    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.
  • by msuarezalvarez ( 667058 ) on Sunday October 26, 2008 @03:51PM (#25519783)
    Give Haskell (or ML, Scheme, Lisp and friends) a try: using PHP to prototype algorithmically intrincate stuff is simply absurd.
  • by woot account ( 886113 ) on Sunday October 26, 2008 @04:35PM (#25520137)
    See instead: Linus Torvalds [kerneltrap.org]
  • by lgw ( 121541 ) on Sunday October 26, 2008 @05:41PM (#25520749) Journal

    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.

  • by Master of Transhuman ( 597628 ) on Sunday October 26, 2008 @06:06PM (#25520935) Homepage

    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)

    by ESqVIP ( 782999 ) on Sunday October 26, 2008 @08:17PM (#25521975)
    I don't like to make assumptions about others, but you seem to believe that the majority speaks exclusively English.

    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.

  • by Anonymous Coward on Sunday October 26, 2008 @08:51PM (#25522171)

    But we did start our own language, PHP was created by Danish-Greenlandic programmer, so I'd say it is very Scandinavian.

  • 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)

    by Requiem18th ( 742389 ) on Sunday October 26, 2008 @10:24PM (#25522773)
    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
  • by Adam Jorgensen ( 1302989 ) on Monday October 27, 2008 @05:16AM (#25524531)
    Erm... You sir, are a twit... Seriously... Yes, there are a lot of crap PHP coders out there. And yes, there is a lot of awful PHP code out there. As is always the case though, that is not the be all and end all. There is actually good PHP code out there, there are actually good PHP coders out there. Describing PHP as the BASIC of the 21st century is actually quite ridiculous and merely illustates that your encounters with the langauge have been limited to bad experiences rather than good ones. Also, your rant about the static keyword (Which PHP does have but which is used in a different fashion) is compltely IRRELEVANT because you are comparing apples (C) and potatoes(PHP). Just because PHP looks like C does not mean that it is C. Please reapply to the Department of Mental Affairs for a functioning brain...

2.4 statute miles of surgical tubing at Yale U. = 1 I.V.League

Working...