Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112447 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73778 invoked from network); 7 Dec 2020 01:32:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Dec 2020 01:32:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BC7DB1804C9 for ; Sun, 6 Dec 2020 17:00:56 -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=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 ; Sun, 6 Dec 2020 17:00:56 -0800 (PST) Received: by mail-ot1-f45.google.com with SMTP id f16so11036328otl.11 for ; Sun, 06 Dec 2020 17:00:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1cqqNAIIDvZ1CwkS1SJCEeNWjda1y6T+3BLPsEPr7vE=; b=ZTav3Pv5urFqIr1ANaRYDHna3rt6Y1tCGQ3HbqtGdsrHqyNbTMiXimed/t1gq40IT3 9/fIYYrzR+7VML0gdFwzQveNwzzBswe2c2ozmGwA3x91QHZt7qHdHoNGEpD5uEFhj43r Mu7cAK+A2LDNCmD6fwYJ/EGOxHKHxzsvyDZg2haZeYqK/ztIXKV2gSG3ucTIARbeHg5O 1gBtXnV47ID6a7rceJ181qBcCE7frJdrM+tAsxonpJ6Wuujk8X6fYPxcJN+IxvwoJ0xj 7tNXbRgq9As9VxJrmXPyhkhxGwlNMnoLADD5xzvo54PnL4nw2EUog5k5dVp+xMfJNa9Q zKDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=1cqqNAIIDvZ1CwkS1SJCEeNWjda1y6T+3BLPsEPr7vE=; b=t4tXlCv34vPsIkKnhxBwUwVT9UJhLyIUty3MRxACA+9MKsF0C3IDVYhotD+khYSLpL jfYvkdn1Z3zIPQjdOxS6b+Y2L4wLxN3VwT5/PbKVzMaA9gbGcUP4LJnjBOk6icPGljnO YO14AYbfKlsW+57jLP7i8VauAawFIJAyYfw8MBWrLzJeuBcfHvs4TL1tPJsSCwrbr106 S+MOXFswNWMj6sZBSlq0lIXsb0hV1AohpKIjcAdFWFH4mT8sYThAXHnyQbln8L9GnC1Y eC2FtwraOmVzq52j8ydXPGd4ayU0ZfTsmAiW3C/wCUP1UGWlpxJ6DhmvIaCfSULIcWuv fCxg== X-Gm-Message-State: AOAM532dNL8ED0Ex0yqieeUP7XTUH0UcL7k1BkafgjTCELKBpAlmnPSf QQUV7qdBkazLZXUfXXHAEDDhPt9/wfkhvv82UA== X-Google-Smtp-Source: ABdhPJwrJhl6tXxY33jeJZg1qfZEDXZHAuFX6RAbmz5uGEPX0iPzzRiQnJE+vtfymNfaQSqE3V6xrgF8BddawcLkwNs= X-Received: by 2002:a05:6830:22eb:: with SMTP id t11mr11770503otc.114.1607302853723; Sun, 06 Dec 2020 17:00:53 -0800 (PST) MIME-Version: 1.0 References: <32277b43-079d-4cd7-a159-8ad555096742@garfieldtech.com> <31c9d66b-771a-35ed-1b11-c681bbcc02c3@gmail.com> In-Reply-To: <31c9d66b-771a-35ed-1b11-c681bbcc02c3@gmail.com> Date: Sun, 6 Dec 2020 17:00:42 -0800 Message-ID: To: Rowan Tommins Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Enumerations From: paul.crovella@gmail.com (Paul Crovella) On Sun, Dec 6, 2020 at 7:12 AM Rowan Tommins wrot= e: > > On 06/12/2020 00:17, Paul Crovella wrote: > >> enum cases have no state > > Unless there's a bit left out from this RFC this is not completely > > true, you've just limited them to annoying ways of working with data, > > e.g. static variables. > > > I'm not sure what you mean here, but it sounds a bit like you're saying > there are ways to emulate mutable state, so why bother restricting it? Static variables don't emulate mutable state, they are mutable state. My question is why go out of the way to restrict things arbitrarily, particularly when the result is ineffective and just makes things suck more. It's irrelevant extra work to annoy people with no gain. > The point is that since enum cases are singleton objects, any instance > state would actually be global across the program, which is probably not > what people would expect. Instance state being global is a well-known problem with singletons. Maybe don't use singletons then. Or simply document them as was done in the RFC. I'd prefer the former since singletons don't seem to buy much here but problems, though maybe I'm missing something. In any case why is static state being (kinda sorta) restricted along with it? > >> static methods on cases, which without data are exactly the same as no= rmal methods > > This is an argument against instance methods, which you kept, rather > > than static methods, which you didn't. How is this division anything > > but arbitrary? > > > On a singleton object, instance methods and late static binding are > equivalent, but instance methods are probably more intuitive, since > people are more used to writing code like "$this->suit->shape();" than > "$this->suit::shape();" > > I guess both could be supported, but other than more code style > decisions to make, I can't think of what they'd add. Consistency. Which reduces both the wtf factor when working with them and edge cases for other features that interact with them. > > Again, what is it particular to enums that necessitates adding these > > inconsistencies to the language? I get that*you* want to avoid state, > > but how is that an enum thing rather than a you thing? > > > "Inconsistency" is a straw man here, because these are a brand new > concept that already does things objects don't do. Inconsistency is in no way a straw man. This RFC has enums being implemented as "fancy objects", based on classes, backed by objects, with the results being treated as classes and objects in every way except for.. well mostly a bunch of artificial restrictions that appear to have nothing to do with enums at all. > So let's flip it > around: do you have any use cases for directly storing state on an enum > case, remembering that such state would be unavoidably global? No, that is a garbage standard that's been abused around here for too long. This RFC is proposing to introduce inconsistencies into the language, it's up to it to justify them. It is not up to me or anyone else to come along and pass your personal code review just to ask for that justification. > Restricting them will likely make other desirable features easier - for > instance, how would serialization work: Like serialization already works with objects, including singletons. > $a =3D Suit::Hearts; > $a->setColour(Colour::Pink); > $serialized =3D serialize($a); // does this serialize the instance state? > $a->setColour(Colour::Purple); > $b =3D unserialize($serialized); > assert($a =3D=3D=3D $b); // as discussed elsewhere, this should be true > assert($a->getColour() =3D=3D=3D $b->getColour()); // are they both pink= ? > both purple? > > > Note that Larry's longer term plan is for "algebraic data types", > including "tagged unions": https://wiki.php.net/rfc/adts Unlike > straight-forward enum cases, these are not singletons, and each instance > has its own associated state. Longer term plans are irrelevant except to avoid inadvertently shutting the door on something. This RFC is up for discussion, and will be up for voting, in isolation. It has to be able to stand on its own. > Regards, > > -- > Rowan Tommins (n=C3=A9 Collins) > [IMSoP] >