cashscript
cashscript copied to clipboard
considering enums as a language feature
I mainly envision usage for byte-enums, which can provide byte values with clear semantic value:
enum identifiers {
BaseContract = 0x00,
SidecarContract = 0x01,
DaoContract = 0x02,
AuctionContract = 0x03,
}
enum capabilities {
none = 0x00,
mutable= 0x01,
minting= 0x02
}
we could also wait and see if we see the need for this when introducing global constants
byte BaseContract = 0x00;
byte SidecarContract = 0x01;
byte DaoContract = 0x02;
byte AuctionContract = 0x03;
The benefits of enums might only become clear over global constants once we have module functionality so the same enum could be used across contract files
solidity also supports enums but in a different way
Enums are one way to create a user-defined type in Solidity. They are explicitly convertible to and from all integer types but implicit conversion is not allowed. The explicit conversion from integer checks at runtime that the value lies inside the range of the enum and causes a Panic error otherwise. Enums require at least one member, and its default value when declared is the first member. Enums cannot have more than 256 members.
The data representation is the same as for enums in C: The options are represented by subsequent unsigned integer values starting from 0.
https://docs.soliditylang.org/en/latest/types.html#enums