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

rempas rempas at tutanota.com
Thu Jan 27 08:37:18 UTC 2022

On Wednesday, 26 January 2022 at 23:13:56 UTC, MrJay wrote:
> a lot of code practices people recommend such as not using 
> macros is because of team environments' because many convenient 
> code practices can easily cause confusion for your peers. but I 
> still dont understand why people see it as a sin of coding to 
> use global variables, it depends on the code base and the 
> project.

Yeah, I thought the same hence why I made this question. Tho from 
what I've seen, most of people (at least in the D community) use 
whatever does the job best so global variables can be useful IF 
used with caution. But I realized that in my case, wrapping my 
variables in a struct is a better choice cause not only it's more 
convenient but I will also have a problem when I implement 
mult-therading support!

> In some of my code there is only global variables because one 
> of the languages I use only uses global variables so if 
> something is broken it takes a hot minute, I dont know what 
> function is causing the error, just have to go through them all.

Yeah, that's very very bad indeed!

Thanks a lot for your time! Really appreciate it!

More information about the Digitalmars-d mailing list