Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52725 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56834 invoked from network); 1 Jun 2011 22:47:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jun 2011 22:47:56 -0000 Authentication-Results: pb1.pair.com header.from=david.zuelke@bitextender.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=david.zuelke@bitextender.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain bitextender.com from 80.237.132.12 cause and error) X-PHP-List-Original-Sender: david.zuelke@bitextender.com X-Host-Fingerprint: 80.237.132.12 wp005.webpack.hosteurope.de Received: from [80.237.132.12] ([80.237.132.12:34745] helo=wp005.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EC/E9-32367-491C6ED4 for ; Wed, 01 Jun 2011 18:47:50 -0400 Received: from dslb-092-075-002-048.pools.arcor-ip.net ([92.75.2.48] helo=[192.168.0.102]); authenticated by wp005.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) id 1QRuCW-0001yA-TB; Thu, 02 Jun 2011 00:47:45 +0200 Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: multipart/signed; boundary=Apple-Mail-2-96266466; protocol="application/pkcs7-signature"; micalg=sha1 In-Reply-To: Date: Thu, 2 Jun 2011 00:47:44 +0200 Cc: PHP internals Message-ID: <71782BA1-DCF7-4C16-AA14-04CC4771ABA7@bitextender.com> References: <4DE5368A.6050603@moonspot.net> <8BEEEE49-8DA3-4634-BF9C-120F7A15B613@roshambo.org> To: John Crenshaw X-Mailer: Apple Mail (2.1084) X-bounce-key: webpack.hosteurope.de;david.zuelke@bitextender.com;1306968470;cc94aacc; Subject: Re: [PHP-DEV] RFC: Short syntax for Arrays (redux) From: david.zuelke@bitextender.com (=?iso-8859-1?Q?David_Z=FClke?=) --Apple-Mail-2-96266466 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Just because the MongoDB developers were stupid enough to build a query = language on top of JSON does not mean that JSON or JavaScript object = literals need to be supported in PHP. And it wouldn't be possible anyway = since JSON allows Unicode escape sequences, and PHP cannot even = represent those as it is not aware of runtime encodings. Besides, outside the use case of json_decode(), stdClass is rarely ever = useful, so I don't understand why we're even discussing {} shorthands = here. It's not in the RFC either, so good job on focusing on the issue = and not diluting the discussion. Getting back to the RFC: I think it's problematic to have two separate = syntaxes for the key/value separator. For consistency's sake, I'd rather = just have "=3D>" but not ":". Just my $0.02. David On 02.06.2011, at 00:09, John Crenshaw wrote: > For small linear arrays, neither format is "more readable" but for = even mildly complex structures, there is a clear difference. Consider = the following Mongo query: >=20 > $query =3D array( > 'time'=3D>array('$and'=3D>array( > array('$gt'=3D>strtotime('-1 day')), > array('$lt'=3D>time()), > )), > '$or'=3D>array( > array('foo'=3D>'bar'), > array('hello'=3D>'world') > ) > ); >=20 > Vs. the JSON form: > $query =3D { > time: {'$and': [ > {'$gt': strtotime('-1 day')}, > {'$lt': time()}, > ]}, > '$or': [ > {foo: 'bar'}, > {hello: 'world'} > ] > }; >=20 > Because of the clear readability difference I'll take anything, but = JSON would be much better than just an "array shorthand". >=20 > John Crenshaw > Priacta, Inc. >=20 > -----Original Message----- > From: Anthony Ferrara [mailto:ircmaxell@gmail.com]=20 > Sent: Wednesday, June 01, 2011 5:18 PM > To: PHP internals > Subject: Re: [PHP-DEV] RFC: Short syntax for Arrays (redux) >=20 > Personally, I think focusing on a character savings is the wrong > reason to take on any problem. I don't care how long it takes for me > to type code. I don't care how much extra hdd space it takes. But > what I do care about is how readable it is. >=20 > To me, the array shortcut syntax is pointless. Do you really mean to > tell me that `[1, 2]` is more readable/easier to understand than > `array(1,2)`? To me, it's about a wash. >=20 > However, the object shortcut syntax is a major win. For example: >=20 > $person =3D new stdClass(); > $person->city =3D 'ogden'; > $person->state =3D 'ut'; > $perspn->country =3D 'usa'; > $person->favoriteNumbers =3D array(4, 12, 37, 42); > $person->somethingWithNumbers(); > $person->unluckyNumbers =3D array(6, 13, 21); > $person->likesPhp =3D 'very much so'; >=20 > vs >=20 > $person =3D { 'name' =3D> 'Justin', > 'city' =3D> 'ogden', > 'state' =3D> 'ut', > 'country' =3D> 'usa', > 'favoriteNumbers' =3D> [ 4, 12, 37, 42], > 'unluckyNumbers' =3D> [ 6, 13, 21], > 'likesPhp' =3D> 'very much so' > } >=20 > Did you notice what happened there? There's two differences. Try to > find them. Neither would be possible with the shortcut syntax. >=20 > Now, the only reason I would personally support the array shortcut is > if it was an implementation of JSON. I know that's not on the table > here, but that's the only benefit I can see to implementing a shortcut > for arrays (that would save 5 characters per instance). >=20 > Just my $0.02... >=20 > Anthony >=20 > On Wed, Jun 1, 2011 at 5:02 PM, Justin Carmony = wrote: >> To address the soapbox: >>=20 >> Its not just to reduce the five characters at the beginning, but when = you have more complex structures as well. There was already a great = example shown = (http://paste.roguecoders.com/p/0747f2363c228a09e0ddd6f8ec52f2e8.html) = of that. Also, if object support is added (which we need to add to the = RFC), you can cut down on a lot more verbose code, especially with = objects. >>=20 >> $person =3D { 'name' =3D> 'Justin', >> 'city' =3D> 'ogden', >> 'state' =3D> 'ut', >> 'country' =3D> 'usa', >> 'favoriteNumbers' =3D> [ 4, 12, 37, 42], >> 'unluckyNumbers' =3D> [ 6, 13, 21], >> 'likesPhp' =3D> 'very much so' >> }; >>=20 >> Characters: 192 >>=20 >> Current way: >>=20 >> $person =3D new stdClass(); >> $person->city =3D 'ogden'; >> $person->state =3D 'ut'; >> $person->country =3D 'usa'; >> $person->favoriteNumbers =3D array(4, 12, 37, 42); >> $person->unluckyNumbers =3D array(6, 13, 21); >> $person->likesPhp =3D 'very much so'; >>=20 >> Characters: 229 >>=20 >> That is a 37 character difference. But the real driving factor is = given PHP's lack of named parameter syntax, passing objects and arrays = (or sometimes a mix, depending on the framework) is becoming very = popular. So not only do you save some typing just once, but if you use = this pattern a lot, you save a lot of typing over your entire project. = Also, when dealing with objects, I have to make sure I retype "person" = correctly each time. If I don't, I'll get a notice error. But with the = new syntax, it'll throw a parsing error so I can know a lot quicker what = my issue is. >>=20 >> As for syntax highlighters, IDEs, books, etc all being outdated, = first off no one is suggesting to deprecate the array() function. So you = will only use this new syntax if you choose to do so. Second, we broke = syntax highlighters, IDEs, and so forth when we introduced namespaces, = and every IDE and syntax highlighter I used updated very quickly to = support them. I'm assuming the IDEs spent a great deal more time adding = Namespacing support than it will to support a short syntax for arrays = and objects. >>=20 >> PHP has made short syntax for other things, such a if statement short = codes. Yet many books don't cover it, since it is one of those things = you read in the documentation later and decide "Do I want to use this?" = No one is forcing anyone to use (1 =3D=3D 1 ? true : false) type of = if/then logic. The same will work with the new syntax. >>=20 >> My two cents. >>=20 >> Justin >>=20 >> On Jun 1, 2011, at 2:37 PM, Michael Shadle wrote: >>=20 >>> On Wed, Jun 1, 2011 at 1:01 PM, Pierre Joye = wrote: >>>=20 >>>> I modified the vote page, pls move your votes to the desired syntax >>>> (or global -1) >>>=20 >>> This is a good idea to group things like this. >>>=20 >>> Back on the soapbox. All of this is just to reduce typing "array" (5 >>> characters) before things? >>>=20 >>> Old: >>> $foo =3D array('a' =3D> 'b', 'c' =3D> 'd'); >>>=20 >>> More than likely new: >>> $foo =3D ['a' =3D> 'b', 'c' =3D> 'd']; >>>=20 >>> 5 character difference for each array being saved. That's it. At the >>> expense of syntax highlighters, IDEs, books, all becoming outdated = and >>> need to be updated. For a language construct that has been around = for >>> what, 10 years? >>>=20 >>> Oh, and for anyone desiring a ":" for this new shorthand, why stop = at >>> array shorthand. Why not change this from: >>> foreach($foo as $key =3D> $val) >>>=20 >>> To: >>> foreach($foo as $key: $val) >>>=20 >>> That would save one character for each array iteration like that. >>>=20 >>> Also - if we're worried about saving characters and shorthand why = not >>> just remove the "$" language construct? That's a LOT of keystrokes. = In >>> my WordPress install, that's 75,412 characters saved. Versus 6,960 >>> "array(" matches, which would save 34,800 characters. >>>=20 >>> These were quick examples from a coworker. Just another PHP user who >>> said "wait why would they make another way to express an array?" >>>=20 >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>>=20 >>=20 >>=20 >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 >=20 --Apple-Mail-2-96266466 Content-Disposition: attachment; filename=smime.p7s Content-Type: application/pkcs7-signature; name=smime.p7s Content-Transfer-Encoding: base64 MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIMZDCCBW4w ggRWoAMCAQICECzy3OO4bIaKwclpYXzU0GAwDQYJKoZIhvcNAQEFBQAwgd0xCzAJBgNVBAYTAlVT MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEfMB0GA1UECxMWVmVyaVNpZ24gVHJ1c3QgTmV0d29y azE7MDkGA1UECxMyVGVybXMgb2YgdXNlIGF0IGh0dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9ycGEg KGMpMDkxHjAcBgNVBAsTFVBlcnNvbmEgTm90IFZhbGlkYXRlZDE3MDUGA1UEAxMuVmVyaVNpZ24g Q2xhc3MgMSBJbmRpdmlkdWFsIFN1YnNjcmliZXIgQ0EgLSBHMzAeFw0xMDEwMTQwMDAwMDBaFw0x MTEwMTUyMzU5NTlaMIIBGzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlT aWduIFRydXN0IE5ldHdvcmsxRjBEBgNVBAsTPXd3dy52ZXJpc2lnbi5jb20vcmVwb3NpdG9yeS9S UEEgSW5jb3JwLiBieSBSZWYuLExJQUIuTFREKGMpOTgxHjAcBgNVBAsTFVBlcnNvbmEgTm90IFZh bGlkYXRlZDEzMDEGA1UECxMqRG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