Talk:Enumerated type
This is the talk page for discussing improvements to the Enumerated type article. This is not a forum for general discussion of the article's subject. |
Article policies
|
Find sources: Google (books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
This article is rated C-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Context template
[edit]Specific confusing sentences:
- "Typically the compiler will select a small integer to represent each enumeration value at run-time, but this representation is not always visible to the programmer." Why does the compiler do this? Why isn't it visible to the programmer?
- Answer: For example, the purpose of the three symbols (apple,orange,banana) is to identify a fruit, not a number! How the values (fruits) are represented is not important to anyone but the compiler and the CPU, hence it is hidden from the programmer. This can be compared to the binary representation of characters or real numbers (or jpg-pictures or MP3-songs for that matter), normally not so interesting to the programmer or user either. / HenkeB 17:02, 2 March 2007 (UTC)
- I disagree with HenkeB regarding the importance of knowing the values. Some debuggers will show the integer value of fruit as 3 and the programmer has no way of knowing that the fruit is yellow and has a peal (i.e. it is equal to a banana )! DGerman (talk) 22:56, 27 November 2021 (UTC)
- "In some languages, the boolean type of truth values is considered a predeclared enumerated type of two values." What is a predeclared enumerated type?
- Answer: As if somebody had written type boolean = (false,true) at the beginning of every source file.
Foxjwill 18:14, 18 December 2006 (UTC)
Improved Context
[edit]I attempted to improve the context. Can we remove the note now? Dw31415 17:17, 10 October 2007 (UTC)
Removed from Introduction
[edit]I removed the following from the introduction as most of it is not universally true for all programming languages that support enumerated types and the issues are covered with reference to specific programming languages in the rest of the article.
More about enums:
The enum keyword is used to declare an enumeration, a distinct type consisting of a set of named constants called the enumerator list. Every enumeration type has an underlying type, which can be any integral type except char. The default underlying type of the enumeration elements is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1. For example:
enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
In this enumeration, the sequence of elements is forced to start from 1 instead of 0.
A variable of type Days can be assigned any value in the range of the underlying type; the values are not limited to the named constants.
The default value of an enum E is the value produced by the expression (E)0.
enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};
In this enumeration, Sat is 0, Sun is 1, Mon is 2, and so forth. Enumerators can have initializers to override the default values. For example: —Preceding unsigned comment added by 81.155.142.9 (talk) 19:23, 3 August 2008 (UTC)
Enum (C) history
[edit]This puts the first usage of enums in C in the ANSI standard. I recall reading about enums (together with changing structs in C to be like PL/1 / Pascal structs) in BYTE in 1983. I believe this change was for PWB UNIX 7 (6?).Mzk1 (talk) 16:29, 29 December 2011 (UTC)
Problem with definition of enum
[edit]Currently the article begins this way:
- In computer programming, an enumerated type (also called enumeration or enum) is a data type consisting of a set of named values called elements, members or enumerators of the type.
This strikes me as poorly expressed, if not wrong. I think that something like this might capture the idea better:
- In computer programming, an enumerated type (also called enumeration or enum) is combination of (a) a class and (b) an ordered list or unordered set of named instances of that class, where the list or set contains, and so specifies, all valid instances of the class. The instances are called elements, members or enumerators of the type.
I think this concept could be expressed in a Python-like pseudocode this way:
class Color: pass # define the class Color
blue = Color() # enumerate the valid instances of color
red = Color()
yellow = Color()
colors = [red, yellow, blue] #define an ordered list of all valid colors
Comments? StephenFerg (talk) 00:36, 14 August 2012 (UTC)
So how can enums exist in languages without classes? 1Z (talk) 12:02, 14 August 2012 (UTC)
- See Planning poker - the physical meaning. Seagateups (talk • contribs) 22:38, 19 November 2015 (UTC)
- An enumerated type is a set of integers to which names are assigned. Keeping things as simple as possible, but no simpler, that is the definition that belongs in the lede. Vincent J. Lipsio (talk) 13:14, 20 November 2015 (UTC)
@Lipsio: I agree. In particular, enumerated types are not limited to "computer programming". For example, they are widely used in hardware descriptions:
type state_type is (S0, S1, S2, S3); -- enumerated type in VHDL
Lambtron talk 14:58, 18 November 2020 (UTC)
- @Lambtron: Yes, they are used in hardware, and I've often mapped HW enumerations into C Language structures. I've long intended to add a real-life example of that to this article, and perhaps now will. Vincent J. Lipsio (talk) 19:32, 19 November 2020 (UTC)
- @Lipsio: Great! That would be a very useful addition. In conjunction with that, it seems reasonable to revise the lede along the lines you suggested above. Also, I think (1) the distinction between enum type declarations and instances should be more prominent and clear, (2) "classes" should not be so prominent because they are language-specific type declarations, and (3) it should be stated that an instance may be a variable or a constant. Lambtron talk 20:41, 19 November 2020 (UTC)
Split off to page Comparison of programming languages
[edit]Ushkin N (talk · contribs) recently split off parts of the article Enumerated type to a page Comparison of programming languages (types, enums) (diff). This page then was speedily deleted under A10: Recently created article that duplicates an existing topic. While I don't think that reason applies as Comparison of programming languages (types, enums) clearly was intended to be a split page, I still am not sure that splitting off that content is an improvement. – Tea2min (talk) 08:09, 22 May 2016 (UTC)
Add list of databases that support enum under "Databases" section
[edit]Would this be a good addition? On top of my head I know MySQL and PostgreSQL support enums. Nsz no (talk) 10:43, 4 January 2017 (UTC)
External links modified
[edit]Hello fellow Wikipedians,
I have just modified one external link on Enumerated type. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
- Added archive https://archive.is/20130201203915/http://www.rps-obix.com/docs/manuals/enumerated_data_type.html to http://www.rps-obix.com/docs/manuals/enumerated_data_type.html
When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.
This message was posted before February 2018. After February 2018, "External links modified" talk page sections are no longer generated or monitored by InternetArchiveBot. No special action is required regarding these talk page notices, other than regular verification using the archive tool instructions below. Editors have permission to delete these "External links modified" talk page sections if they want to de-clutter talk pages, but see the RfC before doing mass systematic removals. This message is updated dynamically through the template {{source check}}
(last update: 5 June 2024).
- If you have discovered URLs which were erroneously considered dead by the bot, you can report them with this tool.
- If you found an error with any archives or the URLs themselves, you can fix them with this tool.
Cheers.—InternetArchiveBot (Report bug) 17:50, 21 September 2017 (UTC)
add an example on how to use enums like Pascal's sets
[edit]enum cardsuit {
Clubs = 1,
Diamonds = 2,
Hearts = 4,
Spades = 8
};
...
// a possible use
enum cardsuit card;
...
if ( card & (Diamonds | Hearts) ) ... // action for red suits
else if ( card & (Spades | Clubs ) ... // action for red suits
else ... // action for out of range error
Tbere are better ways to exemplify this, however this, but I don't want to write another example because it has to be consistent with the rest of the article — Preceding unsigned comment added by 2806:106E:B:400F:F9:F69F:2ED7:3753 (talk) 06:32, 4 September 2022 (UTC)
Enums in R
[edit]The beginning of the article lists R factors as an example of enumerated types. However, while R factors are indeed lists of named values, they are used to efficiently store categorical data and are not usually used in the same ways other languages use enums. They would in fact be quite cumbersome for those kinds of usage. I believe that this reference to R factors should be removed. Semcebag (talk) 10:37, 13 January 2024 (UTC)
- C-Class Computing articles
- Low-importance Computing articles
- C-Class software articles
- Mid-importance software articles
- C-Class software articles of Mid-importance
- All Software articles
- C-Class Computer science articles
- Mid-importance Computer science articles
- C-Class Java articles
- Mid-importance Java articles
- All Computing articles
- C-Class C/C++ articles
- Mid-importance C/C++ articles
- C articles
- C++ articles
- WikiProject C/C++ articles
- WikiProject Java articles