bait-lang / bait

Simple yet powerful programming language for building reliable software. Work in progress.
MIT License
19 stars 5 forks source link

Don't allow `global` anymore, use static variables at package level instead #249

Closed StunxFS closed 10 minutes ago

StunxFS commented 5 days ago

Describe the feature

From the documentation:

image

If the use of global is discouraged, then it is preferable to remove it completely from the language and use static variables at the package level.

Proposed Solution

Static variables at the package level are safer to use, plus they are declared in a package scope, so there is no collision with other symbols with similar names.

package main

static my_var := 1

fun main() {
    my_var += 1
}

Additional Information

No response

serkonda7 commented 5 days ago

To reduce issues with globals, they already behave like static variables. The keyword should indeed be changed to static plus update of the docs and syntax design document.