On Tue, Sep 22, 2015 at 10:29 AM, Rowan Collins <rowan.coll...@gmail.com> wrote:
> 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 can
> 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 classes
> 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, and
> 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… 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/Swift/Conceptual/Swift_Programming_Language/Enumerations.html
  [2]: http://rustbyexample.com/custom_types/enum.html

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to