Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114998 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80350 invoked from network); 21 Jun 2021 23:45:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Jun 2021 23:45:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 83C501804CC for ; Mon, 21 Jun 2021 17:03:59 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2064.outbound.protection.outlook.com [40.92.18.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 21 Jun 2021 17:03:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MFiBvPZ4ZpKmOuFYjsXLORGalxVIIcIe51DsAxhUwB17UxLCtBMB+e9uny2sM7vQNd0NEuDRTGlcF3vmPesA2EFHyHGw95HQX3dhbgV16eNjQ9+z8vqiQaqqLm3PuKMiNkqgBzcMAFVI3k42OoSxuz28PIxw6MyKe7LXYRpWTQDzI+XefVRFw9jqBk3vX2BnZcY0baxgMq2ydTuR1oGq8bSGLGqKBHEYpaXU0TOlXGsGw0+S2oI28JSwC/OpJ/69YW0SI9/8xT7Csg71FWF5fiLhrYvXN4V9R/wcoT3cM9B+Tmkr7IXiEEmwXHqSUPVfsL0Znbu14a7fkpW+UDNKQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f+1qapYKKUUzw/MnEvlE0qXCkEAAYyL9w+kOd86JKDs=; b=HVEfpM5lxqzK+4Qa9ypkQa+XMZWrtih+v2NxOdnrgWQgJkD9eX9Ouxw3HfSwuO0gpc24Lp/PkESBNLxR/uskh6P7VHlJ2TnGTFXKy0tgxlJRb6QbMUfOJfIcLkTqdsNstGCCo2CWbyrBNjjCiZiNm8U4mOYTdMGySC7ZomHrfjJVGaaZO8tD435N57WtcF7MDgyY8LNDVAHLBfR9E8EYk9Dnoj7CP1AVHqhDJTy+kArmC1ZgvCd0BOclfwvNPy//M48wzYoIvAcrrCRavvuR6xTHPm/SCw3KF19ujokXKaDawfEKGP7wFQa7tBcdN3SQJu6tPG5zYLZbI5fR+afKLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f+1qapYKKUUzw/MnEvlE0qXCkEAAYyL9w+kOd86JKDs=; b=Edz9ZZ4bMooD7Bp49tu+O+0kgY67IeKZ17QxHErB0AnrI5CZuRvxyAbBAlkXvTs5jsMKNdXj4f0TJXsSoWfBs4uUtkkf8cpQVXoHQmJKLsqD4p8nbBfOITzW+n01pArCTxFaavGf06y2qYQKCkc8xgqCiFQHdy37CNisZA9Brw1EbHImuqZqhgVm0l5vw2aJ31B27iChnrwRAkr8xDJC++l/74kchVfsqm74bL29QYAQNyJZyTHuFdhVLi9FYVUBot/JuGditMGiE4N0MmMAqUpu5ulPjVLTnqmO7tIPARhbZI5mDTPcAYFSlBOXLZ+cYKF/w2kVUV4PfxSVAtUtMw== Received: from DM6NAM11FT060.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::48) by DM6NAM11HT165.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::427) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16; Tue, 22 Jun 2021 00:03:56 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc4d::48) by DM6NAM11FT060.mail.protection.outlook.com (2a01:111:e400:fc4d::319) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16 via Frontend Transport; Tue, 22 Jun 2021 00:03:56 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::20ed:6cd1:4fe2:eea7]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::20ed:6cd1:4fe2:eea7%3]) with mapi id 15.20.4242.023; Tue, 22 Jun 2021 00:03:56 +0000 To: "internals@lists.php.net" Thread-Topic: [PHP-DEV] [PROPOSAL] Bare name array literals (again) Thread-Index: AQHXZryCJm/mj5rNokqkQmATCwMJ5qseudGAgABma00= Date: Tue, 22 Jun 2021 00:03:56 +0000 Message-ID: References: ,<7f2da982-e29b-ccca-bddc-24ae7f4b0390@gmail.com> In-Reply-To: <7f2da982-e29b-ccca-bddc-24ae7f4b0390@gmail.com> Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:97B0725701B8AFDAD5C7C9D93EE48F515A45B85B0159C787C1778A7B2983557B;UpperCasedChecksum:EBAA5239417CC7F383959513364D80A5B2D2AAE3A6D79C1E0F380B7921D62920;SizeAsReceived:7088;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [4q6znVcOQeGLpYK8v90kzcPovVcesXSwXLBebulPYmzfImUO6/SAx/kJlnIJ08iS] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: afeecdff-f476-46cc-b77b-08d935113ab9 x-ms-traffictypediagnostic: DM6NAM11HT165: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: T0ht9gGqxqFh9ZRL/vZnIF8xC9MNw/bj7PIoq5gp0me+D/bXyMk5U1tCyP+x/hTf1+eBbsS3jjDNSng58qoVEMS2+vnC+o+O5ikFSrf9FNMF+7Y+lHCyhbwgZE9X9NamRf5y2zq256wjg9PSBeSJg3NWcOpOlngEfUP7Rfelvdr2j39RqdQbLw2rOqP4OKKZltVSTMRH4LzcfGLPuA994jauysP+8796xVBDJnqlsbR4uvoqgoswZYjNIgG9XOCWClwo3PfKB017dcE1XFbJCj/g8cylrQYbAaqr+qAhyQmw28EOJ/Lsmk+68Pnp8u3q1oZjyAn/27/G02H1utvWEiW7oMbABgXqgPOlUMbw7np2K094Y1pExCIc7gnE3GslNXI8Cjc9/CcdjBPS90vuyX9V+DYQI0M5sdSI5kjOPqF4wbu2Z24Wg/akDWWs9p9ln++K2gRn2CFCgBeqJErXXzZsLXOoK0gvp0eWxSRfir4= x-ms-exchange-antispam-messagedata: jSaRcEzGdROGJ6+rLBtScCKhrhdUK5+HHy/J465voTuISivbPE8Kh/q69T3Hp3m/Ktd6QvmBGRGipqWC4W3AtelzakKWvaBMKZVw0TvFSmnFQro+anFzu1PhXxsIewMVm9AeaBaRUdbcR4UYGtrr5sA1y9k0nOpnm6aIcAnaG+dXOJlebBNjPV90coWmunzq+tohxQtfMAmyE3TGEim4uw== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: afeecdff-f476-46cc-b77b-08d935113ab9 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Jun 2021 00:03:56.4812 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM11HT165 Subject: Re: [PHP-DEV] [PROPOSAL] Bare name array literals (again) From: tysonandre775@hotmail.com (tyson andre) Hi Rowan Tommins,=0A= =0A= > This is an immediate "no" from me: it multiplies the ways to write the=0A= > same thing from 2 to 4, in order to save a few bytes, in a few instances.= =0A= =0A= It's from 4 to 6 if you include single quoted strings vs double quoted stri= ngs.=0A= If linters and automatic fixers were set up for a project to enforce it (e.= g. phpcbf),=0A= there would only be one way that literals would be used in a project either= way.=0A= =0A= > I think this is something that Douglas Crockford got absolutely right=0A= > when he simplified JavaScript object syntax to formalise JSON: every=0A= > valid key can be represented as a quoted string, so if the quotes are=0A= > always there, you don't need to remember a list of rules about reserved= =0A= > words, allowed characters, etc.=0A= =0A= It's the same rules as parts of identifiers or variable names.=0A= I don't think there are any reserved words for named params or this proposa= l(`default`, etc. are allowed despite being keywords)=0A= =0A= What makes sense for a serialization format which will have hundreds of enc= oders/decoders may not make sense for a programming language.=0A= =0A= > > This is useful for shortening long arrays where the keys are known lite= rals,=0A= > > e.g.=0A= > > =0A= > > return [success: true, data: $data, cursor: $cursor];=0A= > > // is equivalent to the following, but shorter:=0A= > > return ['success' =3D> true, 'data' =3D> $data, 'cursor' =3D> $cursor];= =0A= > =0A= > Although common, this is not a good use of arrays; if your keys are=0A= > "known literals", they should be fields of some object:=0A= > =0A= > return new Result(success: true, data: $data, cursor: $cursor);=0A= =0A= If there is only a single place where an array with those keys is returned,= =0A= or if dynamic properties get added later,=0A= then creating a class may not be worth it.=0A= =0A= Developers would have to switch between files and keep track of which class= es were =0A= ordinary data storage and which had side effects or transformed parameters.= =0A= =0A= > If you don't want to declare a class (yet), you can use an anonymous=0A= > object. Rather than yet another way to write arrays, it would be great=0A= > to have some more powerful syntax for those; currently you'd have=0A= > something like this:=0A= > =0A= > return new class(success: true, data: $data, cursor: $cursor) { public=0A= > function __construct(public bool $success, public array $data, public=0A= > CursorInterface $cursor) {} };=0A= > Brainstorming, we could perhaps extend property promotion into the "new= =0A= > class" clause, so that you could write this:=0A= > =0A= > return new class(public bool success: true, public array data: $data,=0A= > public CursorInterface cursor: $cursor) {};=0A= =0A= I think anonymous objects would benefit some use cases but would not be use= ful for every use case (e.g. short single-file shell scripts),=0A= though the typed properties and constructor property promotion are definite= ly convenient.=0A= =0A= Also, with no common interface between those anonymous classes,=0A= using just anonymous classes would be writing functions that accept any obj= ect or return any object, =0A= which would be error prone and hard to analyze.=0A= =0A= Those anonymous classes wouldn't have any ancestors in common for `instance= of` checks.=0A= Also, if there were optional parameters, that can be represented in non-sta= ndard JSDoc supported by static analyzers=0A= (`success: bool, data?: array, cursor?: CursorInterface, errorMessage?: str= ing`),=0A= but that wouldn't be represented in an anonymous class=0A= (setting a property to null is not the same as omitting it).=0A= =0A= This reminds me of https://docs.python.org/3/library/collections.html#colle= ctions.namedtuple=0A= but I don't plan to propose that (something similar could be done by valida= ting all property names are valid, =0A= getting the sha1 of the ordered list of property names to choose a class na= me, =0A= and optionally setting properties to `readonly` (if the RFC passes) and for= bidding dynamic properties,=0A= and extending some common interface).=0A= =0A= Thanks,=0A= Tyson=0A=