Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88413 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64707 invoked from network); 22 Sep 2015 16:39:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Sep 2015 16:39:34 -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.49 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.213.49 mail-vk0-f49.google.com Received: from [209.85.213.49] ([209.85.213.49:35926] helo=mail-vk0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DE/EE-56639-54481065 for ; Tue, 22 Sep 2015 12:39:33 -0400 Received: by vkfp126 with SMTP id p126so10272783vkf.3 for ; Tue, 22 Sep 2015 09:39:30 -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=K7pxsScwJ43YPa3DIptTritUj+hdy4OjxrK6xm3VTG4=; b=SVDz6+VaCZnOXKohNZYTN5MRC6Y1cvUqEd5xtCub754rZpwqHYg3OppBKtgm1Izdt/ ww0aKPxVdDf8m7HwyZ2VCb9l4h8RRMVaFLSWS7j7cVWETmuNO4d9blUPNgbzOEz7N9/d /4o6lL5T7J9NcHpP0KLMtkqIpDF4YZmD7HdwvkJ96LOoJIqWRav+ljFMlAWGR+3Z7fqj Ca8Nau9LH+tXq1GTnR7J+NeDnb2n1pleUoXiZtGeSlNiW3NYJS6yAy51s6lAjhkk37vW nmDJRdaiAib/AkRDYd6EQQ8JAk1in3KApbAq/kAAFMwfuZn2QJB4yvpyn+nA9NA2YIxF Ey4A== MIME-Version: 1.0 X-Received: by 10.31.108.196 with SMTP id j65mr17900054vki.81.1442939970348; Tue, 22 Sep 2015 09:39:30 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.31.41.205 with HTTP; Tue, 22 Sep 2015 09:39:30 -0700 (PDT) In-Reply-To: <560181F2.3020304@gmail.com> References: <55FB4791.4040807@gmail.com> <55FB4DFC.2060204@domain.invalid> <55FB555C.9070701@gmail.com> <560181F2.3020304@gmail.com> Date: Tue, 22 Sep 2015 10:39:30 -0600 X-Google-Sender-Auth: Y0XnnJLkS6x8DDrVMToa_rxJtM0 Message-ID: To: Rowan Collins Cc: internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: Let's discuss enums! From: levim@php.net (Levi Morrison) On Tue, Sep 22, 2015 at 10:29 AM, Rowan Collins w= rote: > Dan Cryer wrote on 22/09/2015 16:06: >> >> C#'s enums seem a good model to follow. > > > It's worth pointing out that C#'s enums are basically the same as C's - a > typedef over int with a handful of helper methods in the standard library= . > They don't even range-check on assignment, so that a "weekday" variable c= an > be given the value 42. [1] > > This is very different to Java or Python, where enums are a special kind = of > object, strictly typed, and comparable only with themselves. (Python clas= ses > can relax these constraints by overloading various operators.) > > Java's enums have no intrinsic "value", but can have arbitrary fields set= up > by a constructor. They do have an ordinal() method, but "Most programmers > will have no use for this method." The toString() method returns the name= of > the Enum constant. [2][3] > > Python's enums have both a name and a value, but the value can be of any > type. Most of the examples in the manual do use integer values, though, a= nd > there is a suggestion of how to implement auto-numbering. [4] > > References: > [1] https://msdn.microsoft.com/en-us/library/cc138362.aspx > [2] https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html > [3] http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html > [4] https://docs.python.org/3/library/enum.html All good things to point out. This is the kind of thing I had hoped to point out when I submitted it officially for discussion=E2=80=A6 but enums = got brought up before I could do that. I would also like to point out that Swift has several kinds of enums[1]. Rust's enums are different as well[2]. Enums are very different in different languages. Essentially I don't know if we will ever agree on which style of enums to have, but the hope is that we can all agree that the common functionality of all of them is useful and go forward to that point. [1]: https://developer.apple.com/library/prerelease/ios/documentation/Swi= ft/Conceptual/Swift_Programming_Language/Enumerations.html [2]: http://rustbyexample.com/custom_types/enum.html