Why people dislike global variables so much while I find them so convenient?

rempas rempas at tutanota.com
Wed Jan 26 11:24:34 UTC 2022


On Tuesday, 25 January 2022 at 23:28:36 UTC, forkit wrote:
> // ---
>
> module test;
> import std;
>
> int x = 0;
>
> void main()
> {
>     writeln(foo);
> }
>
> int foo()
> {
>     int x = 10;
>
>     if(x) // ooh. you sure this was your intention??
>         return x;
>     else
>         return .x;
> }
>
> // ---

What ".x" returns? Also this example is not very practical. You 
could do the same if you had passed "x" as a function parameter?


More information about the Digitalmars-d mailing list