Slashdot is powered by your submissions, so send in your scoop

 



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 joaommp ( 685612 ) on Sunday October 26, 2008 @01:04PM (#25518371) Homepage Journal

    ... and comming full circle.

    • Re: (Score:3, Funny)

      by eulernet ( 1132389 )

      Scroll your screen to see the animation:

      \
      -
      /
      |

  • by Anonymous Coward on Sunday October 26, 2008 @01:06PM (#25518387)

    PHP 5.3 also adds support for local GOTOs. This langauge is so up with the times.

    • by chrysalis ( 50680 ) on Sunday October 26, 2008 @04:24PM (#25520043) Homepage

      GOTO is what your CPU is actually doing 80% of the time.
      You can pump up your ego by imagining that using a language without something explicitely called "GOTO" makes your code "up with the time". But what you actually do is nothing but GOTOs, just written in a different manner.

      Ironically, the VM that PHP uses is completely GOTO-based (well, you can pick several methods at compile-time, but GOTO is what a lot of distributions chose because performance is often better than CALL and it's very stable nowadays).

      Oh and even JAVA has GOTO and relies a lot on it. The compiler hides an explicit thing called "GOTO", but what you get after compilation is full of GOTO. And it's actually why apps can actually do something.

      Laughing at "GOTO" is ignorance, or just blind trolling because you read somewhere that BASIC had a "GOTO" keyword. I guess in a few years your children will laugh at those horrible "$", "$this", "->", ":" and "\" symbols, that would remind them the old time of a language called PHP. Though you are proud of them now.

      Using temporary variables like "$should_exit", dummy loops just to "break" at the right place, or named loops to work around "break" that would only exit the first loop is nothing but writing "GOTO" in an obfuscated and inefficient way. "GOTO" is not synonym for "spaghetti code" (the famous keyword always used by people blindly repeating that GOTO is bad).

      Oh and grep for "goto" in your Linux kernel or in any BSD operating system. Wow, tons of them. Really. But I guess this is just because these source codes are shits written by people who can barely write GW-BASIC, and of course none of these operating systems actually work. Glad you are there to help. Teach them how to code, tell them that their code is so passé.

      Or shut up.

  • by jspenguin1 ( 883588 ) <jspenguin@gmail.com> on Sunday October 26, 2008 @01:06PM (#25518391) Homepage
    I couldn\'t read the summary because it had an unterminated string literal.
  • by Anonymous Coward on Sunday October 26, 2008 @01:09PM (#25518409)

    It'll be /, just to keep things interesting.

  • by A beautiful mind ( 821714 ) on Sunday October 26, 2008 @01:13PM (#25518443)
    ...to make PHP the most retarded computer programming language on the planet.
    • 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] ;)
      • Hm... Thanks for the link. Enlightening reading.

        Now I'm slowly getting why people even bother to use Python for Web. Pretty much natural choice for all who can't (or refuses) to grok Perl, yet want to have a real language at their disposal.

        I used PHP around year 2000. It was simple like toy. But it seems that its developers didn't realize that the language did outgrow the sandbox they were living in. Also - the responsibility they carry before all the web developers who invested time into learning PH

        • For the record, I grok Perl just fine, but fell in love with Python because it felt like "Perl done right". I don't avoid Perl because I have to, but because I can. I just mentioned that because a lot of people really seem to believe that Python is for people who can't handle anything else.

      • Seriously...
        That link compares PHP to Perl.

        I spit on Perl and so does everybody else I know. Had it at least been Python, Java or something, but Perl?!

        My biggest gripe with PHP now, is the lack of support for good IDE with -GOOD- debugging capabilities. God damn !"#%@-Zend...

        • Re: (Score:3, Insightful)

          That link compares PHP to Perl.

          And pretty soundly shows Perl to be as good as or better than PHP, in some fundamental ways.

          I spit on Perl and so does everybody else I know.

          You apparently don't know a lot of people who actually understand Perl.

    • by mangu ( 126918 ) on Sunday October 26, 2008 @01:20PM (#25518505)

      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?

      • by rawg ( 23000 )

        and I'm migrating them over to Ruby on Rails or Merb. PHP is lame.

      • by Dragonslicer ( 991472 ) on Sunday October 26, 2008 @01:37PM (#25518627)
        PHP is far from dead. PHP5, with support for real OO, was a huge improvement. There's been a lot of hard work put in to PHP in the last few years to make it a much more viable modern programming language.

        Then I see people suggesting \ for a namespace separator, and I wonder what happened to all the people that put so much work into making PHP5 good, and why we can't get them back.
        • Re: (Score:3, Insightful)

          by mangu ( 126918 )

          I wonder what happened to all the people that put so much work into making PHP5 good, and why we can't get them back.

          The last one was seen downloading a Ruby On Rails development environment.

        • by chrysalis ( 50680 ) on Sunday October 26, 2008 @04:42PM (#25520199) Homepage

          PHP ? Real OO? Thanks for the great joke.
          How can I add methods to Number? Ehm you know, the class used for numbers... In order to write 3.times() for instance... ah, it doesn't exist? Ok, so how can add methods to strings? Impossible, strings aren't objects either?

          Stop kidding.

          Why do PHP programmers use classes for? Just to avoid collisions between two functions with the same name when files are included. Really... very few PHP code instanciates more than one object per class.

          Introduction of namespaces might limit this.

          But there's something else that PHP miss: a "static" keyword.

          Guess how very large source code like OS kernels or demos have been built in C or assembler, without namespaces, without classes, without symbols like \, but without coders constantly fighting about names collisions?

          The reason is file-local symbols, ie. the static keyword in C (and local symbols in assembler). Only export (ie. make non-static) what you need to use in other files. As a bonus, it helps the compiler in order to optimize the code.

  • While at it, they should have picked a page from the W3C and made namespaces full, compliant URIs.

    That would have been epic! /sarcasm.

    • At least in a sense. You can map a .NET namespace to an XML namespace. Say you have namespace that is:

      Shados.Awesome.Controls

      You can map that into:

      http://www.shados.com/controls

      In c# you'd plunk this into your AssemblyInfo.cs file:
      [XmlnsDefinition("Shadows.Awesome.Controls","http://www.shados.com/controls")]
      And thus add it to your XAML code:


      <UserControl xmlns="http://www.microsoft.com/xml/something"
      xmlns:shadow="http://www.shados.com/controls">
      <shadow:AwesomeControl x:Name="myControl" param="aPar

  • yet another wtf (Score:3, Interesting)

    by larry bagina ( 561269 ) on Sunday October 26, 2008 @01:18PM (#25518489) Journal

    The rfc [php.net] claims that typing "**" is easier than typing "%%" or "^^".

    • This sounds similar to some programmers complaining about case sensitivity. If there is a typo risk in typing the same same character two or three times in a row ala ::: or ** how in the world are you having any success with the other 20,000,000 characters you're stringing together?
    • by e4g4 ( 533831 )

      The rfc [php.net] claims that typing "**" is easier than typing "%%" or "^^".

      But it is! ... if your right shift key is broken...

  • As a developer who primarily works with C#/.Net, with a little PHP on the side, IMO this addition is long overdue. It would be nice to have a more standard separator, but when I RTFA they seem to have a just reason for it, and it's using semantics that PHP coders are used to. I will happily adjust myself in this ONE manor in order to reap the MANY benefits of namespaces.

    Just my 2 cents.
  • Backslash! (Score:4, Funny)

    by SEWilco ( 27983 ) on Sunday October 26, 2008 @01:24PM (#25518537) Journal
    Just make sure they name it a backslash in the documentation, not a slash.
  • by 3seas ( 184403 ) on Sunday October 26, 2008 @01:27PM (#25518561) Homepage Journal

    ... to cause for windows servers...

    imagine what directories will be deleted due to a typo!

    • Re: (Score:3, Insightful)

      by glwtta ( 532858 )
      Yeah, and if you are running PHP on a Windows server, do you really need any more trouble?
  • other issues (Score:5, Insightful)

    by adamruck ( 638131 ) on Sunday October 26, 2008 @01:34PM (#25518613)

    Maybe they could starting fixing the noun-verb vs verb-noun problems instead.

    • I speak an subject-object-verb [wikipedia.org] language you insensitive clod. RPN is the One True Way.
    • or (needle,array) / (array,neddle) confusion

      Even with years of coding, I can't remember exactly function names or attributes, which is blaming when PHP.net site is down.

      I bet having better naming/call conventions will save them wagons of bandwith !

  • by redink1 ( 519766 ) <redink1NO@SPAMhotmail.com> on Sunday October 26, 2008 @01:48PM (#25518689) Homepage Journal
    The number of days that an old, crusty Perl developer can laugh at another language are few and far between.

    Thank you, PHP.
  • Is the problem that they chose something 'different' than what everyone else uses, or is there a real technical reason behind the snarkiness? I think it's a good thing they even considered the issues involved, though I'd disagree with the 'ease of typing' issue - once your fingers leave the home row, you dramatically increase the chances of a typo. People who aren't touch typists have some pretty serious misunderstandings about typing ease. (Hello, Apple keyboard designers, I'm looking at you.)

    • 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 coryking ( 104614 ) * on Sunday October 26, 2008 @02:33PM (#25519121) Homepage Journal

        Now do you have to escape your namespaces before passing them through eval?

        eval("$instance = new My\\Super\\Class(\"blah\"););

        Since they now are using the escape character for namespaces, I wonder what kinds of security implications this might have? What happens when a PHP program for some reason evals() some user input that doesn't properly escape the namespaces?

        • Re: (Score:3, Insightful)

          by prockcore ( 543967 )

          You'd have to do that anyway, because you used double quotes, "$instance" is going to get evaluated and your eval will fail anyway.

  • It's interesting to see what the Phalanger [php-compiler.net] guys are going to do now. They've already been using ":::" as a namespace separator for their .NET/CLR language extensions, as the next most logical choice. And now this.

    On the whole, though, this is probably just as bad as using "." for string concatenation (it was sort of okay for Perl because back then it wasn't yet used ubiquitously as a member access operator, but for PHP, it was a dumb choice). Backslash has a near-universal meaning as an escape character

  • by Anonymous Coward on Sunday October 26, 2008 @01:54PM (#25518761)

    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.

    • Re: (Score:3, Interesting)

      by Tom ( 822 )

      I couldn't agree more. When I read this my only thought was "what the fuck?". On a German Mac keyboard, \ is Alt+Shift+7. I think on Linux and Windos it's something equally retarded.

      Will the people who made PHP a good programming language please fork it and take it away from the clueless morons who have taken over?

    • by Tom ( 822 ) on Sunday October 26, 2008 @04:05PM (#25519883) Homepage Journal

      This line from the IRC discussion says it all:

      [16:24:51] bjori: switch to US layout ;)

  • 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.
  • Other suggestions (Score:3, Interesting)

    by lepidosteus ( 1102443 ) <lepidosteus@gmail . c om> on Sunday October 26, 2008 @02:26PM (#25519029)

    For additionnal fun, read this: http://wiki.php.net/rfc/namespaceseparator [php.net]

    Looks like they considered stuff like :> and :) as separators for namespace. Seriously.
    Also, they don't give any malus for tybe-ability to \ while on most european keyboards it's a lot harder than any other suggested separator. Way to go !

  • From the TFA:

    \ looks a lot like / and is easy to accidentally flip, especially for unix users

    Um, that should be "especially for DOS / Windows users". Unix was here first dumb asses

    Furthermore, using the character, that just about every other programming language uses for the escape character, as an operator (or separator) is just plain stupid -- I'm also talking to you Microsoft, but that horse has definitely left the barn...

  • by sfjoe ( 470510 ) on Sunday October 26, 2008 @03:27PM (#25519549)

    Since PHP is open source, someone will make a fork with a different separator and the dumber of the two choices will wither away.

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

    with 4GB RAM machines with TB hard drives - and we're still worrying about "the number of characters".

    Oh, please. Fucking nerds.

    For the last forty years, we've been constrained by one pointless limitation after another, not to mention the complete inability of a PC to discern what is an identifier and what is command syntax if it has fucking SPACES in it.

    Get your heads out of your asses.

    And learn to type.

    "Number of characters" - Jesus Baron von Christ!

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

Love may laugh at locksmiths, but he has a profound respect for money bags. -- Sidney Paternoster, "The Folly of the Wise"

Working...