5 ms·
> A variable created at file scope How does one declare a variable to be of file scope in Go? An ordinary "var x int" has package scope, visible from any file
by everybodyknows 4y ago
> A variable created at file scope
How does one declare a variable to be of file scope in Go? An ordinary "var x int" has package scope, visible from any file in the directory (aside from the special cases around _test.go files).
Scope of package import declarations is narrowed to a single .go file, but these of course are not variables.
- avianlyric 4y agoI think you’re reading this too literally. They likely just mean file scope from a purely usage perspective. I.E. you only use the variable in one file, it doesn’t matter how the language processes it into a computational scope
- everybodyknows 4y agoIt absolutely does matter. If I'm editing the file in which the package-scope variable (or type, or const) is declared (and also referenced) and decide on the fly to subtly change its semantics, forgetting that the same is also referenced from some other file within the package, I have likely just created a bug. Worse, the bug will likely manifest itself only at run time.
- chrsig 4y agoYou're still taking things too literally. A human typed in something less precise than you'd like in a style guide. Find a bug tracker to request a verbiage change. It's not that big of a deal. No one is asserting that variables are in fact file scoped.