tact-lang / tact

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

`const` as an alternative for `let` #643

Open Gusarich opened 1 month ago

Gusarich commented 1 month ago

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.

anton-trunov commented 1 month ago

I like the idea

Gusarich commented 1 month ago

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
}
byakuren-hijiri commented 1 month ago

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