Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88340 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84308 invoked from network); 18 Sep 2015 17:04:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Sep 2015 17:04:48 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.42 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.213.42 mail-vk0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:36425] helo=mail-vk0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F5/84-60254-F244CF55 for ; Fri, 18 Sep 2015 13:04:47 -0400 Received: by vkfp126 with SMTP id p126so33660456vkf.3 for ; Fri, 18 Sep 2015 10:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=inPGHHvCzgMaPxrH2cREhvHCS+ivxGQnIttNNOBKPyc=; b=vaOcMXMEwN5yOdGhObfcvQ5DxAB2VgAFcj5rX/zsonUAGpm7IXw44A8Pp3au913wiY 7TTCW1G3iXVGshVIxfjOcpVijcuON70XR6E1LTT4DPqlu5vjr1c7GVXFjoXSp3hMhAaO TCU/NBhtzMRJPUWw5cO9tZUvTELSNpGNn6HY1+D7Bqr+RQvuvQ5xoXx7K/fWggWDkVcT Kz1GcBTsZgSpAyov8an4YQksMzzb3lr7FoIu0oSr8fRRPCIePpHxiVpc7zQ4TV4ccusb zy2a6rs24D4lEq9Oht5xOsfzrtS0absYd8jPgLYCaNB/sM+cd33isAnDV9BYBXtusEwn AHlQ== MIME-Version: 1.0 X-Received: by 10.31.163.75 with SMTP id m72mr1589231vke.54.1442595884904; Fri, 18 Sep 2015 10:04:44 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.31.41.205 with HTTP; Fri, 18 Sep 2015 10:04:44 -0700 (PDT) In-Reply-To: References: <55FB4791.4040807@gmail.com> <55FC34E6.8020009@gmail.com> Date: Fri, 18 Sep 2015 11:04:44 -0600 X-Google-Sender-Auth: JfGSTsZEVBMY9SzpiXqTNbeYjRE Message-ID: To: Jefferson Gonzalez Cc: =?UTF-8?Q?Pavel_Kou=C5=99il?= , Rowan Collins , internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Let's discuss enums! From: levim@php.net (Levi Morrison) (CC'ing internals as it was apparently dropped by Jeff) On Fri, Sep 18, 2015 at 11:03 AM, Levi Morrison wrote: > On Fri, Sep 18, 2015 at 9:59 AM, Jefferson Gonzalez wr= ote: >> On 09/18/2015 10:21 AM, Levi Morrison wrote: >>> >>> On Fri, Sep 18, 2015 at 1:05 AM, Pavel Kou=C5=99il = wrote: >>>> >>>> On Fri, Sep 18, 2015 at 1:06 AM, Rowan Collins >>>> wrote: >>>>> >>>>> Hi All, >>>>> >>>>> This has come up in passing a few times recently, but I'm not sure >>>>> there's >>>>> ever been a dedicated discussion of it: would it be useful for PHP to >>>>> have a >>>>> built-in Enumeration type, and if so, how should it look? >>>>> >>>>> Many other languages have enum types, with varying functionality. The >>>>> central concept is always that there's some declared type with a bunc= h >>>>> of >>>>> named constants, but beyond that there's a lot of variability: for >>>>> starters, >>>>> is it a type of object, a special way of naming integers, or an >>>>> uncomparable >>>>> type more like booleans and nulls? >>>>> >>>>> >>>>> So, what are anyone's thoughts? Am I rambling on too much as usual? ;= ) >>>>> >>>>> Regards, >>>>> >>>>> -- >>>>> Rowan Collins >>>>> [IMSoP] >>>>> >>>> >>>> Hi, >>>> >>>> personally, I feel that you should be able to assign numeric value to >>>> each element (and have them implicit if not specified). >>>> >>>> This is imho better for serialization (but it can be done with names >>>> as well, yeah) - but more importantly, it also allows usage with >>>> bitwise operators, so you could use them as a "flags" (ie. $weekend = =3D >>>> Days::SATURDAY | Days::SUNDAY). >>> >>> >>> In my opinion this is the least valuable form of enums that exists in >>> any language I am aware of. However I was careful in the RFC to not >>> prevent this from being a possibility. I would much, much prefer enums >>> that are more like Rust's, Haskell's or Swift's. It's worth noting >>> Swift has at least three different kinds of enums, one of which would >>> allow the kind of behavior you are wanting. >>> >> >> It may not be valuable in your opinion, but I have seen this kind of enu= m >> usage on a lot of open source projects which is really useful to represe= nt >> more than 1 value in a single variable, which would be more efficient an= d >> less memory consuming than doing something like: >> >> $weekend =3D array( >> Days::SATURDAY; >> Days::SUNDAY; >> ) >> >> And anyway, most new languages have over engineered the purpose of enums= . >> Enums should just be a nice way of grouping constant values with a human >> readable name where the ordinal value should be optionally set for >> consistency in case that storing it is required. > > According to type theory the enumerated type is just a special case of > the union type where each type constructor in the union takes exactly > zero parameters (meaning they are all singletons). So=E2=80=A6 what is th= e > purpose of an enumerated type? To create a finite set of values that > are all unique. That's it =E2=80=93 that's the whole purpose. > > Anything else is trying to add value in some way =E2=80=93 in your case y= ou > are adding a primitive value that the language will automatically map > for you. I'm not saying that is a bad thing but I hope you can at > least recognize that it is an addition and not the bare minimum. The > RFC I am planning on proposing will have only the bare minimum because > it's the least controversial part and is the most useful. The other > stuff we can debate about later.