![]() The size savings might be significant if: If you expect the enum to be used mainly as an argument for flow of control, the size makes little difference. The underlying type needs to be different than Int32 for easier interoperability with unmanaged code expecting different-size enums.Ī smaller underlying type would result in substantial savings in space. The enum is a flags enum and you have more than 32 flags, or expect to have more in the future. ✔️ CONSIDER using Int32 (the default in most programming languages) as the underlying type of an enum unless any of the following is true: ✔️ DO provide a value of zero on simple enums.Ĭonsider calling the value something like "None." If such a value is not appropriate for this particular enum, the most common default value for the enum should be assigned the underlying value of zero. They are used to track the state of the enum rather than being one of the values from the set represented by the enum. ❌ DO NOT include sentinel values in enums.Īlthough they are sometimes helpful to framework developers, sentinel values are confusing to users of the framework. Method overloading allows adding parameters in future releases. ![]() Such reserved parameters can be expressed as enums with a single default value. ![]() ❌ AVOID publicly exposing enums with only one value.Ī common practice for ensuring future extensibility of C APIs is to add reserved parameters to method signatures. Reserved values just pollute the set of real values and tend to lead to user errors. See Adding Values to Enums for more details on adding values to enums. ![]() You can always simply add values to the existing enum at a later stage. ❌ DO NOT provide reserved enum values that are intended for future use. ❌ DO NOT use an enum for open sets (such as the operating system version, names of your friends, etc.). ✔️ DO favor using an enum instead of static constants. ✔️ DO use an enum to strongly type parameters, properties, and return values that represent sets of values. A common example of the flags enum is a list of options. A common example of the simple enum is a set of colors.įlag enums are designed to support bitwise operations on the enum values. Simple enums represent small closed sets of choices. There are two kinds of enums: simple enums and flag enums. The only requirement on these values is that they be correctly ordered and unique within each enum type.Enums are a special kind of value type. But members added later might be given negative or fractional values of enumsortorder. When an enum type is created, its members are assigned sort-order positions 1. The routines that create and alter enum types attempt to assign even OIDs to enum values whenever possible. This rule allows the enum comparison routines to avoid catalog lookups in many common cases. Odd-numbered OID values need bear no relationship to the sort order. That is, if two even OIDs belong to the same enum type, the smaller OID must have the smaller enumsortorder value. The OIDs for pg_enum rows follow a special rule: even-numbered OIDs are guaranteed to be ordered in the same way as the sort ordering of their enum type. The sort position of this enum value within its enum type The OID of the pg_type entry owning this enum value
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |