Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52704 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12279 invoked from network); 1 Jun 2011 21:02:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jun 2011 21:02:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=justin@justincarmony.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=justin@justincarmony.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain justincarmony.com from 209.85.212.173 cause and error) X-PHP-List-Original-Sender: justin@justincarmony.com X-Host-Fingerprint: 209.85.212.173 mail-px0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:48832] helo=mail-px0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0B/B1-32367-1F8A6ED4 for ; Wed, 01 Jun 2011 17:02:42 -0400 Received: by pxi16 with SMTP id 16so112090pxi.18 for ; Wed, 01 Jun 2011 14:02:38 -0700 (PDT) Received: by 10.68.55.104 with SMTP id r8mr1451556pbp.425.1306962158819; Wed, 01 Jun 2011 14:02:38 -0700 (PDT) Received: from [192.168.1.101] (c-24-10-180-216.hsd1.ut.comcast.net [24.10.180.216]) by mx.google.com with ESMTPS id n1sm1384403pbi.63.2011.06.01.14.02.36 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 01 Jun 2011 14:02:37 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: multipart/alternative; boundary=Apple-Mail-26-89956142 In-Reply-To: Date: Wed, 1 Jun 2011 15:02:34 -0600 Cc: Pierre Joye , PHP internals Message-ID: References: <4DE5368A.6050603@moonspot.net> <8BEEEE49-8DA3-4634-BF9C-120F7A15B613@roshambo.org> To: Michael Shadle X-Mailer: Apple Mail (2.1084) Subject: Re: [PHP-DEV] RFC: Short syntax for Arrays (redux) From: justin@justincarmony.com (Justin Carmony) --Apple-Mail-26-89956142 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii To address the soapbox: 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. $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' }; Characters: 192 Current way: $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'; Characters: 229 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. 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. 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. My two cents. Justin On Jun 1, 2011, at 2:37 PM, Michael Shadle wrote: > 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 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 --Apple-Mail-26-89956142--