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

max haughton maxhaton at gmail.com
Tue Jan 25 12:56:00 UTC 2022


On Tuesday, 25 January 2022 at 11:43:56 UTC, rempas wrote:
> On Tuesday, 25 January 2022 at 10:22:59 UTC, max haughton wrote:
>> Passing state down a huge chain is also a code-smell. Writing 
>> code that uses a "global" variable is only slightly better 
>> than using a global variable.
>>
>> What is the rough outline of these functions?
>
> What "rough outline" of a function means? Sorry if that sounds 
> but I need to learn.

What I mean by outline (where global is the thing you don't like 
passing around) :

     ```d
     int foo(ref int global)
     {
         bar(global);
     }
     int bar(ref int global);
     ```
     the "outline" (a reduced call graph if you will) would be 
something like

     ```
     foo(ref int global)
       bar(global);
     ```
     if the code is small enough just post the code, I want to 
illuminate that if you have a bunch of parameters everywhere you 
might want to make it a member function instead.


More information about the Digitalmars-d mailing list