tact-lang / tact

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

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

Open Gusarich opened 4 months ago

Gusarich commented 4 months 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 4 months ago

I like the idea

Gusarich commented 4 months 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 4 months ago

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