Slashdot Mirror


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

16 of 523 comments (clear)

  1. Another fashionable addition for PHP: by Anonymous Coward · · Score: 4, Insightful

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

    1. Re:Another fashionable addition for PHP: by lgw · · Score: 4, Insightful

      Wow, can't type today. Let's try again:

      GOTO remains the best way, in most programming languages, to exit multiple loops, branch to common clean-up code before leaving a function, etc.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    2. Re:Another fashionable addition for PHP: by chrysalis · · Score: 5, Insightful

      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.

      --
      {{.sig}}
    3. Re:Another fashionable addition for PHP: by lgw · · Score: 4, Insightful

      Yes, for school problems, refactoring the code to make the inner loop a function is great. For real-world legacy crap code, it's often impractical. You might have 15 variables that would need to be passed into that inner loop, and you might have shop standards preventing you from passing some of those types into functions, etc, plus your boss (often rightly) object to you "refactoring" code that works today. "Refactoring" is a charmingly naive expectation for legacy crap code to begin with. And if you're not working with legacy crap code today, consider yourself lucky: you don't know how good you have it.

      And by "clean-up code" I mean: you allocate resources at the top of a function, so they must be cleaned up at the bottom of the function (and no sneaky returning from the middle of the function). That code at the bottom of the function is "clean-up code". If you have 15 possible errors in your function, you either have some unreadable mess with 15 nested if statements that hide a perfectly straightforward logic flow, *or* you branch to the clean-up code in each of the 15 error cases, making the actual logic of the function obvious.

      Of course, most coders are simply incompetant, don't even bother to check for errors, and certainly don't ensure that every resource allocated at the top is easily visually identifyable as being freed at the bottom, which is why there are so many job maintaining legacy crap code (and why Java exists in the first place).

      And of course there are languages in which "goto" is pronounced "throw" and all the clean-up happens automatically, but mostly it's inventory and payroll databases that get coded in such languages: give me legacy crap code that does something *interesting* any day! I will forever cherish the one job I had in which C++ was used correctly (not the usual typing C into a cpp file) and goto was really unnecessary, but I don't expect lighting to strike twice in my career.

      Blah, blah, Code Complete. Some of us were doing that stuff correctly long before Steve McConnell (and I'd hardly cite Microsoft as an example of a stable, secure, maintainable code base!).

      --
      Socialism: a lie told by totalitarians and believed by fools.
    4. Re:Another fashionable addition for PHP: by Thuktun · · Score: 5, Insightful

      GOTO is what your CPU is actually doing 80% of the time.

      And your car's engine spends all of its time repeatedly causing small explosions with volatile petroleum.

      The driver is generally recommended to let the engine do this and not try to intervene or do it themselves.

  2. I have to say they are working really hard.... by A+beautiful+mind · · Score: 5, Insightful

    ...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
  3. Re:what wrong with by anotherone · · Score: 4, Insightful

    PHP uses the . as the concatenation operator. PHP does not support operator overloading...

    --
    Username taken, please choose another one.
  4. The BASIC of the 21st century by mangu · · Score: 5, Insightful

    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?

  5. other issues by adamruck · · Score: 4, Insightful

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

    --
    Selling software wont make you money, selling a service will.
  6. Re:A long overdue addition by Shados · · Score: 4, Insightful

    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.

  7. Easier on which keyboard layout? by Anonymous Coward · · Score: 5, Insightful

    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.

    1. Re:Easier on which keyboard layout? by Tom · · Score: 4, Insightful

      This line from the IRC discussion says it all:

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

      --
      Assorted stuff I do sometimes: Lemuria.org
  8. Re:WTF? by caluml · · Score: 5, Insightful

    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.

  9. Re:That's because.. by SoapBox17 · · Score: 4, Insightful

    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.

  10. Re:what wrong with by moderatorrater · · Score: 4, Insightful

    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.

  11. Re:It's all a joke by Haeleth · · Score: 4, Insightful

    So spend the $5 and get a new keyboard? Unless your keyboard is physically, permanently attached. Then again we get into the very, very minority.

    "People with laptops" is a very, very tiny minority?