tact-lang / tact

Tact compiler main repository
https://tact-lang.org
MIT License
275 stars 56 forks source link

`Enum` type instead of define multiple constant variable #431

Closed ZigBalthazar closed 1 week ago

ZigBalthazar commented 1 week ago

regarding to Tact book constants documentation, it defined a non-friendly way to use the Enum concepts in Tact. developers should define multiple constants instead of an enum, this way has some problem:

  1. the defined constants to use instead of enums do not have a group: it means if we have to define an enum for the status of a user we should do this for now:

    const activeUser: Int = 0;
    const blockUser: Int = 1;
    const deletedUser: Int = 2;

    there is no consistency in naming and grouping. maybe it be better to do this like it(just syntax sample):

    enum user_status {
    ACTIVE = 0,
    BLOCK = 1,
    DELETED = 2
    }

    or

    const (
    userActive = 0
    userBlock = 1
    userDeleted = 2
    )
  2. type consistency: based on the above example from the tact book it is a mistake potential to use constant instead of enum for types, for example:

    const activeUser: Int = 0;
    const blockUser: string = "1";
    const deletedUser: Int = 2;

Let's consider a solution for the mentioned problem by defining an enum type for tact and the tact compiler to make the tact language more developer-friendly. We can take inspiration from other languages, such as TypeScript, which changed the syntax and defined the enum type, while Golang used const in a grouping manner. There are various ways to implement this, and we should have a detailed discussion about the implementation of this feature in this issue.

anton-trunov commented 1 week ago

Duplicate of #17