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."
Another fashionable addition for PHP: (Score:4, Insightful)
PHP 5.3 also adds support for local GOTOs. This langauge is so up with the times.
WTF? (Score:1, Insightful)
Being different to be different, aren't we?
That's because.. (Score:1, Insightful)
There's obvious drawbacks for using a period (.) as a string concatenator, it's easy to put strings together since typing a period is a lot easier than a plus (+), but this means you can't use a period for namespaces as many OO coders are used to..
I have to say they are working really hard.... (Score:5, Insightful)
A long overdue addition (Score:2, Insightful)
Just my 2 cents.
Re:what wrong with (Score:5, Insightful)
PHP uses the . as the concatenation operator. PHP does not support operator overloading...
The BASIC of the 21st century (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?
Re:yet another wtf (Score:1, Insightful)
All I can say is that "\" is a key combination of a right hand key with AltGr on a German keyboard. How is that easy to type? "::" is Shift-. on all keyboards that I know of.
other issues (Score:5, Insightful)
Maybe they could starting fixing the noun-verb vs verb-noun problems instead.
Re:A long overdue addition (Score:5, 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.
Re:Well, That Does It! (Score:4, Insightful)
It's not just developers, it's things like IDEs which highlight anything starting with '\' as an escape sequence.
Which - since nearly every other common programming or scripting language uses '\' to mark the beginning of an escape sequence - is something you might reasonably expect.
Come to think of it, so does PHP... ooops...
Re:The BASIC of the 21st century (Score:3, Insightful)
The last one was seen downloading a Ruby On Rails development environment.
Easier on which keyboard layout? (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.
Re:WTF? (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.
Re:That's because.. (Score:5, Insightful)
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.
Re:Gripe Moan Bitch and Holler! (Score:4, Insightful)
Scripting languages are for those of a weak mind and poor technical skills and the singular lack of the ability to plan a system out before you write one line of code.
Or for projects that need to be compiled at runtime. But, nice magnanimity.
Re:Going back to DOS style... (Score:3, Insightful)
Re:what wrong with (Score:5, Insightful)
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.
Re:I have to say they are working really hard.... (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.
Re:That's because.. (Score:3, Insightful)
Calling a variable "myInt" doesn't make it an integer -- it was a float from the second you added a dot.
First, duh. Second, are you sure it will return "hello1.0" and not "hello1.00" or "hello1"? I'm not, I could test to find out, but that makes my point. It adds ambeguity to the language and makes me think about something I really should be thinking about. To use your example, what does the following result in?
function blah(arg1) {
var blah = "10" + arg1 + 5 + "hi";
}
alert(blah("hi"));
alert(blah(1));
alert(blah("1"));
My example isn't as contrived as yours. What if blah() was in some other JS file. It could be easy to trip the function up based on what you pass in.
Using "." for string concatenation at least gives both you, the code reader, and the compiler a hint at what you mean. That way the compiler can barf if you do something silly like concatenate an integer with a string. Using "+" for both addition and concatenation just makes more work for both parties.
In any case, I don't find concatenation nearly as useful as interpolation, most of the time. In Ruby, at least, interpolation is known to execute faster than concatenation. But that doesn't help you if you're using JavaScript.
I agree with this statement. I much prefer how Ruby and Perl do it... just toss the variables into your string and it will interpolate them.
BTW, I'm not too familiar with Ruby. Does it pull the same trick Perl does and use a different operator for string comparison?
if($myStr eq "hi") { print "hi";}
Re:Another fashionable addition for PHP: (Score:5, 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.
Re:Phalanger (Score:3, Insightful)
Why, exactly? English is not the only language spoken in the world, you know, and programmers in many countries feel more at ease naming identifiers using their native language rather than trying to come up with an English translation with their limited knowledge of English. In fact, when people who don't know English well are forced to use English names in identifies, the mistranslations that result can often be very confusing - take it from someone who has to deal with such code daily. And most languages in the world require at least a few letters not in ASCII.
By the way, have you seen Fortress programming language? You know, the one that not only allows Unicode, but uses its fully in the core library, including all standard mathematical operators (with their normal meaning). It is surprisingly readable.
Unicode is used throughout for several years now. Programming languages are pretty much the only place where ASCII still holds, but ever since Java, this has been relaxing more and more - and rightly so. Look back 30 years - do you remember all that code written in all-uppercase because many computers of that time simply didn't have lowercase letters? And it's all gone now, because there's no longer any need to account for such machines - they don't exist anymore. Restrictions on plain ASCII only are heading the same way, and for the same reasons. All editors support Unicode now, so it is used already, and it will be used more and more.
Re:Another fashionable addition for PHP: (Score:4, Insightful)
Modern languages have "exit for" or "break" to bail out of a loop.
If you have a triple nested loop in the same function, you should refactor the code and move the inner loops into another function.
What do you mean by "Clean Up Code"? If you have so many branches in a single function, again, refactor the code and split them into multiple functions.
See also: Code Complete [cc2e.com]
Re:Easier on which keyboard layout? (Score:5, Insightful)
This line from the IRC discussion says it all:
[16:24:51] bjori: switch to US layout ;)
Re:Another fashionable addition for PHP: (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.
Re:The BASIC of the 21st century (Score:4, Insightful)
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.
Re:Another fashionable addition for PHP: (Score:5, 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!).
Re:Going back to DOS style... (Score:3, Insightful)
So how do you like scamming your ads off of Wikipedia's content ?
Just when I thought the human race couldn't get any more pathetic, I get proven wrong.
Re:WTF? (Score:2, Insightful)
Given that / support has only been present in recent Windows versions, I have to say
[citation sorely needed]
Re:What about Eval? (Score:3, Insightful)
You'd have to do that anyway, because you used double quotes, "$instance" is going to get evaluated and your eval will fail anyway.
Re:It's all a joke (Score:4, Insightful)
:: is already used for static methods on classes... it would be harder to implement the differentiation of :: for namespaces and :: for static methods... especially if people started to use classes with the same name as a namespace (which is likely if all modules get their own namespace)
I actually think that '\' is appealing for what it will be used for. The one thing I first though of was SomeModule\new_object::test_function();
Wouldn't it try to evaluate the '\n' as a \n new line? I suppose it will be out of the double quite string scope so it could be alright... could get messy if eval()-ing code, though.
Re:Another fashionable addition for PHP: (Score:3, Insightful)
Although rare, there are times when GOTO is the cleanest way out.
I recall being stunned to run across one of them writing the code for my dissertation, and noting that I was going through a *lot* of code to avoid a single, simple GOTO. Yes, I could have avoided it, but under the circumstances, the GOTO was much cleaner.
Oddly, I don't remember the circumstances; just my sheer amazement that such circumstances actually existed.
hawk
Forty years down the road (Score:3, Insightful)
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!
Re:Well now we all know what trouble this is going (Score:3, Insightful)
Re:Another fashionable addition for PHP: (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.
Re:It's all a joke (Score:5, Insightful)
"People with laptops" is a very, very tiny minority?