Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124987 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id B59631A00B7 for ; Fri, 16 Aug 2024 18:32:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1723833254; bh=dR1OGr7RxJjrGZ5PtMAWE3GtRdaWAk9Ak7bTN6nVkVQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UmIYk5ns/lyGkrbueFTruRWbSWXGxTJAz1ZiRlYgocGRnhWh4A9zvoQGAWjBEIpLB JyQ+N++xs9D6iJUOOzC4IjKRKmnfuhve9cPqA96mGVdwGsWrD6zxXdMf++MVistlU+ EV5lL8gUUFbPn6uWm9p0wiDmnuZXdypr5rVe1U8KLEMzUC4DTBz9E+x8naYcX7ooco mEHa8dPIknLoYRnikHWmsIsygHdKgD3tejbdATR6VALNuKnSo9qwOnBFSbiG2LLfYS t0DBEPcncjowHHqXeBNctq4ScL3hJxrYoXC2a+0bxszVUeDZtmKRQZr/PlU/GLZthm rbkOyPa4eRnwA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B74551801D4 for ; Fri, 16 Aug 2024 18:34:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 16 Aug 2024 18:34:09 +0000 (UTC) Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-37193ef72a4so669888f8f.1 for ; Fri, 16 Aug 2024 11:32:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723833141; x=1724437941; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=PJqO0GtpRVrJKIgyxT4RnftpGoOyxzYSqHGXB2tziNA=; b=bZUFT0doEQD8tc1/+XVtVhUlqOnEn9oBMgTYAMkpQK88T/24Ye57yYuIOvjpL7c8Ob 9eNpcZWaB6DjTquWBrC2qwC0AT7jUXNSoXkKYamoBc/YsGh4ejjRlGkfjR7zTiz1eIvI pgHYw8DyuDo9j5BBMNR+QORN+MeIMFppSWVo08o/zYLC4TMNe05BocSrWoy8+UF7pVhs r5F8Di5ie0D69hr3HFG1el5XBWZrMEXjGOktBarssuk9DyOfDRSjHN8OCk55uIBX3oc7 aA1ywql1Fwfj+hFo1kgvGkQiAK/VuI1FWat5k+6VlUrfcel+KHbP/JfVoKuH2l4ovd2p dAMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723833141; x=1724437941; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PJqO0GtpRVrJKIgyxT4RnftpGoOyxzYSqHGXB2tziNA=; b=r5E006hwsVf1tZq+6wRb8wipLjtG6SRam77S9PQi4B6McZmz5QaTG3b2MTbjauw4ha PRqi7M5MX4Ej2Ene8yEYTQ1jesuqMr33Hg7GUoktsef+JZhGz2QW53gXNp88ZRs3oJvg /bWcvnI+sKtx1HQy9Gewx0SmIJ025o9SrBeeP3POp1vN4n8+Z2lxTdO5t4FQGLVsqppw KBN1UHUFNNWFWnXEnJxA2HuC2HQ+8noIbDPmw1SDF7bnZyOlVQ8jabFxCJld/UNZ5k0V GnlaaKYrlUEwyOTj4AeFOiYHLC4JUcMzT073MYGuj9Bawic40spegv2aKxJUOg+nRsF9 I1xA== X-Gm-Message-State: AOJu0YzsmPTFFDrnQtWJX9T0Rtz2dHrZ/hMFO7+d6OEgVp06h7GBMnba S+vL3OjV8Bm5WzRJwdBg/JSrX8Fm1zxpEiTkdiV3GDz1SOBt6Dq7fIM2F27a5uY7OuLaRTN+wDh SB8V2BeJADW+asJ/9N15eeqqe3DREvg== X-Google-Smtp-Source: AGHT+IHnI19NypmG5zyckZXjwFyLfsgQJBoxm3/wAryAhxn1i4LzThyAoErUYLrAjvje9OekMfwnMh3YDWoCph5hYfY= X-Received: by 2002:a5d:69cc:0:b0:367:905c:823e with SMTP id ffacd0b85a97d-3719464e8d4mr2370781f8f.24.1723833140472; Fri, 16 Aug 2024 11:32:20 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <34548342633f1d87b2fc77c643bd895a18f71b66.camel@ageofdream.com> <79817594-f9a9-4f02-b48a-4bf39e4372e6@app.fastmail.com> In-Reply-To: <79817594-f9a9-4f02-b48a-4bf39e4372e6@app.fastmail.com> Date: Fri, 16 Aug 2024 21:31:44 +0300 Message-ID: Subject: Re: [PHP-DEV] [DISCUSSION] Class Constant Enums? To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000fd7496061fd12d9a" From: arvids.godjuks@gmail.com (Arvids Godjuks) --000000000000fd7496061fd12d9a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 16 Aug 2024 at 17:18, Larry Garfield wrote= : > On Fri, Aug 16, 2024, at 6:35 AM, Alexandru P=C4=83tr=C4=83nescu wrote: > > Hi Nick, > >> > >> Is there any interest in having enums as class constants? > >> > >> I'm often finding cases where I would like to have an enum inside of a > >> class, but don't want a free-floating enum that's basically like > >> another class. > >> > > > > ...... > > > >> > >> class SSHClient { > >> > >> public const enum CommandResult > >> { > >> case Success; > >> case Failure; > >> case Unknown; > >> case Timeout; > >> } > >> > >> // ... > >> } > >> > >> > >> // Usage: > >> > >> SSHClient::CommandResult::Success > > > > > > I feel this topic could be maybe more broad and be called "nested > > classes" that are already supported in multiple languages: Java, Swift, > > Python, C#, C++, JavaScript, etc. > > > I agree with Alexandru. Since enums are 90% syntactic sugar over classes= , > "inner enums" would be 80% of the way to "inner classes". And I would be > in favor of inner classes. :-) There's a lot of potential benefits there= , > but also a lot of edge cases to sort out regarding visibility, what is > allowed to extend from what, etc. But that would support inner enums as > well. > > Based on .... > > --Larry Garfield > Hello Larry, I feel obliged to remind about the 80/20 rule where the last 20% of progress ends up being 80% of all the work. And from the discussion it's already looking like there are some major questions and caveats and engine problems that are gonna rear their ugly heads. I'm more in favour starting with somewhat self-contained features and steadily work to expand on them as people put the effort into it. The same as was done with the type system. You can lay the proper foundation now, so it's not blocking future expansion, but I really do not think full embedded classes are gonna be a short endeavor - probably multiple years if not half a decade going by prior record on features of this size. --=20 Arv=C4=ABds Godjuks +371 26 851 664 arvids.godjuks@gmail.com Telegram: @psihius https://t.me/psihius --000000000000fd7496061fd12d9a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, 16 Aug 2024 at 17:18, Larry G= arfield <larry@garfieldtech.co= m> wrote:
On Fri, Aug 16, 2024, at 6:35 AM, Alexandru P=C4=83tr=C4=83nescu wrote: > Hi Nick,
>>
>> Is there any interest in having enums as class constants?
>>
>> I'm often finding cases where I would like to have an enum ins= ide of a
>> class, but don't want a free-floating enum that's basicall= y like
>> another class.
>>
>
> ...<snip>...
>
>>
>> class SSHClient {
>>
>>=C2=A0 =C2=A0 public const enum CommandResult
>>=C2=A0 =C2=A0 {
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 case Success;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 case Failure;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 case Unknown;
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 case Timeout;
>>=C2=A0 =C2=A0 }
>>
>>=C2=A0 =C2=A0 // ...
>> }
>>
>>
>> // Usage:
>>
>> SSHClient::CommandResult::Success
>
>
> I feel this topic could be maybe more broad and be called "nested=
> classes" that are already supported in multiple languages: Java, = Swift,
> Python, C#, C++, JavaScript, etc.
<snip>

I agree with Alexandru.=C2=A0 Since enums are 90% syntactic sugar over clas= ses, "inner enums" would be 80% of the way to "inner classes= ".=C2=A0 And I would be in favor of inner classes. :-)=C2=A0 There'= ;s a lot of potential benefits there, but also a lot of edge cases to sort = out regarding visibility, what is allowed to extend from what, etc.=C2=A0 B= ut that would support inner enums as well.

Based on <snip>....

--Larry Garfield

Hello Larry,
I feel obl= iged to remind about the 80/20 rule where the last 20% of progress ends up = being 80% of all the work. And from the discussion it's already looking= like there are some major questions and caveats and engine problems that a= re gonna rear their ugly heads. I'm more in favour starting with somewh= at self-contained features and steadily work to expand on them as people pu= t the effort into it. The same as was done with the type system. You can la= y the proper foundation now, so it's not blocking future expansion, but= I really do not think full embedded classes are gonna be a short endeavor = - probably multiple years if not half a decade going by prior record on fea= tures of this size.
-- <= br>

Arv=C4=ABds Godjuks
+371 26 851 664
<= div>Telegram: @psihius=C2=A0https://t.me/psihius
--000000000000fd7496061fd12d9a--