Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112754 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40875 invoked from network); 4 Jan 2021 22:28:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Jan 2021 22:28:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0F21C1804DD for ; Mon, 4 Jan 2021 14:04:23 -0800 (PST) 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,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 4 Jan 2021 14:04:22 -0800 (PST) Received: by mail-qt1-f177.google.com with SMTP id h19so19589916qtq.13 for ; Mon, 04 Jan 2021 14:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=N6Jw2vMnincN+0sEGJ7c6pcWAnKeGCKrYOLXqyNU0Oc=; b=VGY4bqbTLYjqj3LPf19QU4966NcyGmOKGwe0lKfv5qgNJugrYpejm0+XCaL4VczdkT qBNKViTxT8cNBh8IhoBhA0sonWcFMJw+3IjfAyEEvSZyrrBLGp75rXl4b5bW0FMb13v4 fKxDICADbrf3jaq7WUDpO2JF3wvz8WdqH87wza7B1p7n1931eMh6sVFA6usthaKoZ2a1 qtkrW8PeaKryC+KOxxHl/OFWhP5fEzlV0d8DlFz5c5liiV8gPF7AnDuavTT1UEYOZ5cN ryn/bnxKgtpGoliso5NGEJTh14IPuS4EPlx/nfT8yrVLUUgxk4npadwIpCoix07YSqq2 wMHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=N6Jw2vMnincN+0sEGJ7c6pcWAnKeGCKrYOLXqyNU0Oc=; b=QzBGZeNEekqnM5qtVmunAswYTDljoenS6C96WChhOR16811JU3yeAx4k2XwKtkfP4k IzmVfi+j8eri9wVD91QOxM2R8T/y+ucINSF85JfiyoHVVQPuDVfHp5y5YbJlAhRNcNz3 3l+jNb9mpLdXmYBbs9DDOtc5p3fTteKAmJMvDbgXjIQYbt69HdWQbbDUVlshZq5Aqpnl WEVfxE7bKlMgJqBjQnilBlgEXyAaVfU6hocHf0Nj5fMoixTAVcrl+wbnPZ/9NPtglTcw YXXQ8g6cNKJ7cSI4LeQBLt34UwEvHM/PnA6sLBL7VB9dKDksiIJZWpmhUE7uUlkZWRVM bS5w== X-Gm-Message-State: AOAM531jUecB1tXMk5ZDgYb5hU/O9ET6N2uiH90lNxv/JEVyljxuvNdb xbnvNy9ImKsitSPhe2OznT3ZJQ== X-Google-Smtp-Source: ABdhPJwhOcPjUSuCt74RT4aK8Z9av9UCtfsHE7jaZAjWVMHsLSndOD6YhfcRtHRP2hLsejQ381aERg== X-Received: by 2002:aed:2d83:: with SMTP id i3mr74779247qtd.248.1609797858591; Mon, 04 Jan 2021 14:04:18 -0800 (PST) Received: from [192.168.1.239] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id 8sm39003598qkr.28.2021.01.04.14.04.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jan 2021 14:04:17 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) In-Reply-To: Date: Mon, 4 Jan 2021 17:04:16 -0500 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <8aa05350-05fc-df9d-e5d6-fa0f4feb57ba@alec.pl> <4eec7448-f7ab-9955-8c2d-68cd4f822535@gmail.com> <7d8ce2a2-8d85-4312-af22-da643faa3a7f@www.fastmail.com> <1BC8BF20-B961-4360-855B-5BB95338BB8A@newclarity.net> To: Rowan Tommins X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Enumerations, Round 2 From: mike@newclarity.net (Mike Schinkel) > On Jan 4, 2021, at 9:05 AM, Rowan Tommins = wrote: >=20 > On 04/01/2021 11:15, Markus Fischer wrote: >> On 03.01.21 12:01, Mike Schinkel wrote: >>> So in my perfect world this: >>>=20 >>> enum BookingStatus { >>> case PENDING; >>> case CONFIRMED; >>> case CANCELLED; >>> } >>>=20 >>> Would be equivalent to: >>>=20 >>> enum BookingStatus { >>> case PENDING =3D "PENDING"; >>> case CONFIRMED =3D "CONFIRMED"; >>> case CANCELLED =3D "CANCELLED"; >>> } >>=20 >> I'm with Mikes' suggesting here, see also my previous messages [1] = [2]. >>=20 >> I don't know how to back this up with numbers, but the way I see it = the majority of use cases will have a benefit of being able to directly = use the literal values derived from the lexical ones and the ability to = have custom values is feature next to it. >=20 >=20 > I would personally be OK with this if it was allowed but opt-in, e.g. = adding the ": string" would default the values in that way, or even = something magic like ": auto". >=20 > I'm still not a fan of having values *always* defined, because I want = to be able to pick case labels without worrying about whether they make = sense as values. >=20 > For instance, there's a similar maintenance issue to named parameters: = having a default value means if I write "case PENDING;" in v1.0, I can't = change that to "case PENDING=3D'P';" or "case PENDING=3D1;" in v1.1, in = case somebody is relying on the value being 'PENDING', which was never = intended. You make a good point about being able to define without defaults, and = for being opt-in instead. A use-case I am thinking about is a long list of application-specific = error codes where you don't want to have to come up two values for each = error code and/or worry about keeping them the same. I don't quit get how you are thinking of with ": string"; can you give = an example? Conversely, (something like) this might be a viable way to opt-in = default values: enum defaults BookingStatus { case PENDING; case CONFIRMED; case CANCELLED; } -Mike=