Earlier quoted context omitted.
I don't think that a concise method of working with arrays should be thought of as syntactic sugar, not if you mean it in a pejorative way. I found array_map, array_filter, array_key_exists, array_this, array_that painful to write, but never felt that I was gaining any sort of readability for it.
Wouldn't it be nice if PHP arrays acted as objects and all of those functions were methods? $newArray = $array->map("function_name"); Not gonna happen, but would be nice. Any extensions doing this?
PHP Short Syntax for Arrays: developers say no.
71–80 of 89 posts
Re: PHP Short Syntax for Arrays: developers say no.
#72Earlier quoted context omitted.
It's kind of JSON-wish, so this would make more sense: $bar = [1, 2, 3]; $foo = { 'bar': TRUE, 'baz': 'socks' };
For being JSONish it should be $foo = { bar: TRUE, baz: 'socks' }; where keys are unquoted. The less typing the better.
I know some browsers allow it, but it's not true JSON.
Re: PHP Short Syntax for Arrays: developers say no.
#73Why try to make PHP more readable? Just use another language. PHP, like C++, is a big industry dinosaur that can't and won't change. In my opinion, the best think you could do is create a new language which compiles to PHP. I.e. A coffeescript for PHP. You don't have to "vote" and get stupid arguments against; you don't have to be backward compatible; and you only have great programmers in that project since crappy o…
But why not make it more readable? The patch exists - all it would take is for it to be accepted. And there are a ton of people who can't justify the switching costs of moving to a different language. And true, a lot of us aren't great programmers. So? Better tools help. And it's perfectly okay to build and improve tools that regular people will use. Even if they won't be creating the Mona Webapp. ;)
It is, unfortunately PHP resists changes that most of the rest of us consider improvements. I think at this point we might be better served by putting our efforts in to replacing PHP rather than improving it. The replacement need not be the ultimate web language, but should try to be a good language while maintaining a low barrier to entry.
Re: PHP Short Syntax for Arrays: developers say no.
#74Re: PHP Short Syntax for Arrays: developers say no.
#75This does not seem reasonable. I mean that literally -- this feels more like a choice driven by culture than by reason. The cons seem nowhere near strong enough to counter the fact that the overwhelming majority of users want this syntax, and have been asking for it for years.
Which is why it's being brought up again for 5.4, since this vote took place in 2008.
I really don't see the issue here.
Re: PHP Short Syntax for Arrays: developers say no.
#76Earlier quoted context omitted.
The votes are old. The discussion has been raised again for 5.4 ( http://markmail.org/message/fx3brcm4ekh645se ) goto is a limited goto, and the reasoning for it's inclusion makes sense when you consider the other forms of limited goto already in place (breaks, cases, try/catches). It's not an unlimited goto.
The wiki page would have diffused this entire post if it had the dates of the votes on it :) I understand GOTO, but the reaction to people who thought it was a bad idea was "don't use it!", ignoring the fact that whether we use it or not, we have to deal with other peoples' code that do use it.
The people shouting "don't use it!" are thinking of a limitless goto. It's a shame, but not surprising really.
Re: PHP Short Syntax for Arrays: developers say no.
#77Earlier quoted context omitted.
Wouldn't it be nice if PHP arrays acted as objects and all of those functions were methods? $newArray = $array->map("function_name"); Not gonna happen, but would be nice. Any extensions doing this?
You could write that if you wanted, using __call, would be like 10 lines of code or something.
Re: PHP Short Syntax for Arrays: developers say no.
#78I would give up hope for the ability to have a short syntax for arrays (or lots of other syntactical pleasantries) if the core team would please finally implement named arguments.
Could you explain what you mean by this? edit: ahh, found it. Knew what it was, but not what it was called: http://en.wikipedia.org/wiki/Keyword_argument Would definitely be a solution to PHP's ridiculous argument ordering inconsistencies.
The most common way that we get to implement (hack) it now is by using an associative array, which then hides parameters in the implementation of the method as opposed to exposing it in the interface which helps both with reading someone elses code as well as provides for parameter initialization and type hinting (which assoc arrays remove).
I agree with you about argument inconsistencies, and named parameters would help with that, but it even goes beyond that, e.g. how many times have you seen this:
function foo($bar = true, $baz = 5, $qux = "change me"){ ... }
foo(true,5,"this is what i wanted to change");
when all you should have to do is: foo(qux="this is what i wanted to change");Re: PHP Short Syntax for Arrays: developers say no.
#79Cons: Unreadable
What does that even mean?
Re: PHP Short Syntax for Arrays: developers say no.
#80This does not seem reasonable. I mean that literally -- this feels more like a choice driven by culture than by reason. The cons seem nowhere near strong enough to counter the fact that the overwhelming majority of users want this syntax, and have been asking for it for years.
> and have been asking for it for years. Which is why it's being brought up again for 5.4, since this vote took place in 2008. I really don't see the issue here.