tact icon indicating copy to clipboard operation
tact copied to clipboard

`const` as an alternative for `let`

Open Gusarich opened this issue 1 year ago • 3 comments

There are already static constants in Tact that can be declared outside of functions and receivers, but what about the possibility of defining constants within function bodies to enhance code?

These const definitions would work almost identically to let statements, with the only difference being that such variables would be protected from overwriting and changing.

Gusarich avatar Jul 31 '24 11:07 Gusarich

I like the idea

anton-trunov avatar Jul 31 '24 11:07 anton-trunov

Same can probably be applied to function arguments. Example:

fun someFunction(x: Int, const y: Int) {
    // x here is changable, y is not
    x += y; // works
    y += 1; // doesn't
}

Gusarich avatar Jul 31 '24 12:07 Gusarich

The readOnlyVariables lint in Misti could advice developers to replace let with const if the variable is never written.

byakuren-hijiri avatar Aug 04 '24 01:08 byakuren-hijiri