Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123390 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 20BBE1A009C for ; Tue, 21 May 2024 22:48:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1716331787; bh=mf0Gq/Wj+o/FOcfv5ypdTbvE+s7FIkSWIFSmLcIRtYQ=; h=Date:Subject:To:References:From:In-Reply-To:From; b=b6AJdj08h2py3c+rxG3dHoOC/lSxue6BBmssGCJjl72Sktj5PoaPfytlPA8HK27BV 1MEeK25RLeJdBmQ09ZrLuXEtCehQCcbzh9YUkAyAINCLUOaQXxTSFgPKQ8Jc1n3bk7 1l3lGeM+dPhyzIRgssIr7ltHcNA1htGU7qt9YPq8E881jKO/PQToemfWSSsCKJ4+No n2w6jkhFsmsA4HCHZ8LDDiJvJ02PmbncxIqvekssOlYJNYePRVPqyl8uY4cT/Xwcnn SsQl5VJtAZYz4CjA0NCrM/DXonuAZazenCFLv6RUR7s9xtAgW/h2EzO5FoXE3JCIdx FFdjCNu4v2vmQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8DDF11804E0 for ; Tue, 21 May 2024 22:49:46 +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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 ; Tue, 21 May 2024 22:49:46 +0000 (UTC) Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42016c8db2aso2513055e9.0 for ; Tue, 21 May 2024 15:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1716331729; x=1716936529; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=tO/1bEB3tcVJ3JDNO79lDpQzYo2dqx0OwnhXmgHofy0=; b=IjRuGiCWBYcTEWacZLnt+aMABhj7ple0WHsusKfZUSPhs0NE5MgFPFxcC63pUmvXSP HKKYINiQzfb4ySw8SLRKhEwVM1WIdteKB3wd/1jQLTO7WxvU3pp6Fjp3gJmyD2X3V00S XpAJ+MPBm8ckjUofn5QR2CleuvUaK9LpUvIU5eSpYkVnAk2+kcqvsb5gsAx37kHD3UyM 7h5arac1Ink/H9SZ5izeZGUOfjrgCSMewizHqtZRZpvMUyHDvTZCSXwNnE7k2juP7nSE ROk6xBoJNxlyPvFpM37YsU+fe6P86bbkFJhxCG6cY01N5W0YmMo0BQK9NKt4YAamOcHa tacw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716331729; x=1716936529; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tO/1bEB3tcVJ3JDNO79lDpQzYo2dqx0OwnhXmgHofy0=; b=Hn01wEggn6183bzgk8cTME4uX5tb2wknTICMKztcgn2fTzYBKa6lg9qL/Oh42a+Q5X /d8qfoJS+A4pBzWasBL2t6Go/4f72vXIA04PZzihCzJAlMplumynLBYNq09gaHosbkj+ dwN8WY7LCuhqzmgjcxSXCBcAr2IafP3IVSxX3TmF9mJdrzG6NggxC97VvbMRkpeMGnnD ZB2rD7vVraZRRPsSn8OENbq/pCmW7ot9uXnJEkIbz7+BQei7b1XuFZDontyuXZ+fQDV0 C4ZAlCvroUtS159U+kGjwKfwUFq3CNuv0DM/16S6u9+m/pF9ek9fO/mMYag6m9xLlN3F 37ng== X-Gm-Message-State: AOJu0YxdIaLfq7CcniNviSItelgElnHXEV/npOQirkgj+1MaEVPtRzot J0DEbYlgfkiP8u2DshLLYJAKdySjXi7XUBn/CacmTz/nMnVojxzxQ8INyJgTl9KcUFh6WENYPQj n X-Google-Smtp-Source: AGHT+IExCfKXNznUYs6AGTYCO/7MFACrC8vBvFGbSsHE3ybZ4RpGKDm/GKkc59z6Puxu4Td/E6Gnnw== X-Received: by 2002:a05:600c:35ce:b0:41b:3c4c:211b with SMTP id 5b1f17b1804b1-420fd31a454mr1771835e9.22.1716331728685; Tue, 21 May 2024 15:48:48 -0700 (PDT) Received: from ?IPV6:2a01:4b00:bf09:5101:2587:d9b1:339a:a3e9? ([2a01:4b00:bf09:5101:2587:d9b1:339a:a3e9]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3502b79bdc7sm32784803f8f.22.2024.05.21.15.48.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 May 2024 15:48:48 -0700 (PDT) Message-ID: <99c30f5d-e2f3-4027-a8fc-b3b9c71fb6d1@scriptfusion.com> Date: Tue, 21 May 2024 23:48:47 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [Discussion] Implicitly backed enums To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit From: bilge@scriptfusion.com (Bilge) On 21/05/2024 23:35, Larry Garfield wrote: > On Tue, May 21, 2024, at 5:30 PM, Bilge wrote: >> Hi Internals, >> >> I struggle to understand the benefit of "basic" enumerations and their >> diminished API. In particular, I often find myself wanting to use >> `from()/``tryFrom()` to convert a string to an enumeration. To do this, >> I must convert it to a "backed" enum and copy & paste each name to its >> value. In all other regards, I still want it to behave like a "basic" >> enumeration, so I won't abuse the value of the names to act like a >> mapping; the values will always mirror the names, and if I need to do >> any mappings, I'll add match() functions. >> >> My question, then, is why can't basic enumerations have these semantics >> by default? Or, to state it more concretely, what would be the downside >> to having all "basic" enumerations actually being "backed" enumerations >> whose values implicitly mirror their names for the purposes of >> converting to/from strings? Would this not make basic enumeration more >> useful without any particular downsides? >> >> Kind regards, >> Bilge > Making enums not be "fancy strings" was a very deliberate decision. The RFC covers that some. There's more information in our comparison research here: > > https://github.com/Crell/enum-comparison > > And I wrote an article about enum usage a while back here: > > https://peakd.com/hive-168588/@crell/on-the-use-of-enums > > --Larry Garfield Hi Larry, Thanks for the resources! Whilst I can appreciate this was a deliberate design decision that did not come about by accident, I still didn't find (skimming) anything that directly answers the question: >What would be the downside to having all "basic" enumerations actually being implicitly "backed" enumerations? I gather from your (presumably derogatory) referencing of the same as "fancy strings" that you would not approve such an implementation, but I am struggling to understand why. Cheers, Bilge P.S. Sorry for the (previously) incomplete subject line.