Live data from Hacker News

PHP Short Syntax for Arrays: developers say no.

wiki.php.net

51–60 of 89 posts

Re: PHP Short Syntax for Arrays: developers say no.

#51
post #4

Contra ... Not searchable through search engines That's a ridiculous argument.

You can't search for -1 either. Are they going to switch to negate_number(ONE, true) for people who haven't learned that syntax?

(The "true" causes the value to be returned rather than printed, obviously.)

Re: PHP Short Syntax for Arrays: developers say no.

#52
post #5

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.

No I meant "syntactic sugar" in a good way, i didnt realise it was a pejorative. I mean it as per the definition on wikipedia: Syntactic sugar is a computer science term that refers to syntax within a programming language that is designed to make things easier to read or to express, while alternative ways of expressing them exist.

It is not generally perjorative. Some people interpret it as automatically perjorative, feeling that any syntactic sugar must necessarily carry costs in excess of benefits, but they are in the minority. Sizable minority, but minority.

Concentrations of people who dislike all syntax sugar can be found in the Forth community and concatenative languages in general, Lisp, and to a lesser extent, in the Haskell community. People who think syntax sugar is the answer to everything can be found in the Perl 5 community, and Perl 6 is arguably syntax sugar spun into cotton candy, hardened, and used to build a glorious gossamer castle in the sky, which they are currently working on landing. I have taken this metaphor too far.

Re: PHP Short Syntax for Arrays: developers say no.

#53
post #48
post #47

Earlier quoted context omitted.

I catch myself feeling that way, too, but it is uncharitable and inaccurate. They do work a lot of work on developing the language. The issue is that sometimes their idea of what is should be differs from the idea that most people have.

I don't think it's possible to be too uncharitable about the developers of PHP. Courtesy demands that we give them the benefit of the doubt; but by this stage there is very little doubt left, so very little benefit as well.

the language they built and let everyone in the world use for free powers sites from wikileaks to whitehouse.gov, and its simplicity allowed a lot of non-programmers to write working code and sometimes even start new careers. so it is possible to be too uncharitable about them.

that decision, though, is unfortunate IMHO. esp seeing that the userland votes are overwhelmingly pro while the devs are con.

Re: PHP Short Syntax for Arrays: developers say no.

#54
post #48
post #47

Earlier quoted context omitted.

I catch myself feeling that way, too, but it is uncharitable and inaccurate. They do work a lot of work on developing the language. The issue is that sometimes their idea of what is should be differs from the idea that most people have.

I don't think it's possible to be too uncharitable about the developers of PHP. Courtesy demands that we give them the benefit of the doubt; but by this stage there is very little doubt left, so very little benefit as well.

If courtesy means giving undeserved benefit of the doubt, I'm all for discourtesy. This is about rational discourse.

The statement that "It's like they don't even _want_ to fix the language" is inaccurate. It does not relate to the state of things in the real world.

Accusing the developers of some warped intent to keep it in a broken state is an understandable expression of frustration, but it does nothing to advance our discussion and contributes to a misunderstanding of the situation.

Re: PHP Short Syntax for Arrays: developers say no.

#55
post #28

Earlier quoted context omitted.

Sure but this seems better: $foo = [ 'bar': TRUE, 'baz': 'socks' ]

It's kind of JSON-wish, so this would make more sense: $bar = [1, 2, 3]; $foo = { 'bar': TRUE, 'baz': 'socks' };

What would be your syntax when you mix them? Which is perfectly legal to do:

  array(1, 'bar' => TRUE, 3, 'baz' => 'socks');
But I do like this syntax idea.

Re: PHP Short Syntax for Arrays: developers say no.

#56
post #28

Earlier quoted context omitted.

Sure but this seems better: $foo = [ 'bar': TRUE, 'baz': 'socks' ]

It's kind of JSON-wish, so this would make more sense: $bar = [1, 2, 3]; $foo = { 'bar': TRUE, 'baz': 'socks' };

IIRC in PHP every array is internally a hash (ie "associative array"), so $bar is {0:1, 1:2, 2:3} in any case?

Re: PHP Short Syntax for Arrays: developers say no.

#57
post #22

I'm of the opinion you should be writing your PHP in a readable fashion similar to this: $foo = array( 'bar' => TRUE, 'baz' => 'socks' ) (pretend you also have proper tabs as well)

It's been a long time since I did any PHP, but are trailing commas illegal? Normally, it seems like languages follow one of these two patterns, depending on whether their syntax allows extraneous commas or not:

    foo = [
      'first',
      'second',
      'third',
      ]
or

    foo = [ 'first'
          , 'second'
          , 'third'
          ]
The difference between those two examples and yours being that when you want to add a new entry, you only have to edit the line of the entry, rather than having to edit the line before the entry (to put in the comma) as well as the line that you care about. Just an idle question, really.

EDIT: pull unnecessary commentary

Re: PHP Short Syntax for Arrays: developers say no.

#58
post #28

Earlier quoted context omitted.

Sure but this seems better: $foo = [ 'bar': TRUE, 'baz': 'socks' ]

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.

Re: PHP Short Syntax for Arrays: developers say no.

#59
Few people asked for, or even wanted GOTO, yet that seemed to make it through with flying colors. When people would argue against it, the rationale was "well, you don't have to use it!"

Why does the same criteria not apply to short array syntax? If you don't want to use it, don't use it, but hundreds of thousands of other people likely do want it.

FWIW, I first remember hearing about this in 2003/2004, and at that time I was against it for most of the same reasons I've read in opposition to adding it. Working outside of PHP for some time, I've come to realize the shortsightedness I labored under, and would fully love to have this.

I'm not 100% sure the votes on that page are from May 2011 - it's hard to tell for sure.

Re: PHP Short Syntax for Arrays: developers say no.

#60
post #57
post #22

I'm of the opinion you should be writing your PHP in a readable fashion similar to this: $foo = array( 'bar' => TRUE, 'baz' => 'socks' ) (pretend you also have proper tabs as well)

It's been a long time since I did any PHP, but are trailing commas illegal? Normally, it seems like languages follow one of these two patterns, depending on whether their syntax allows extraneous commas or not: foo = [ 'first', 'second', 'third', ] or foo = [ 'first' , 'second' , 'third' ] The difference between those two examples and yours being that when you want to add a new entry, you only have to edit the line o…

No, trailing commas are not illegal. It's actually preferred.

$a = array(1,2,3,); works just fine.

Post reply on HN