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

rempas rempas at tutanota.com
Wed Jan 26 09:27:28 UTC 2022

On Tuesday, 25 January 2022 at 14:44:01 UTC, bachmeier wrote:
> I don't think it's common that you need global variables in D. 
> If you want to share a variable among several functions, use a 
> struct. But if a global is the best solution, use the global.

Yeah, it turns out that for most of my variables, I should use a 
struct instead. But there are some variables that I will keep 
global because I want almost everything to be able to access them 
and they will be immutable. These variables will also have one 
instance and this will never change so it makes more sense for 
them to be global.

> If you've ever had the joy of working with FORTRAN 77 or 
> earlier versions of FORTRAN (back when it was in all caps) you 
> understand why working with globals can be a traumatic 
> experience. For instance, multiple functions in multiple files 
> will sometimes change the same global variable.

I started getting interested in programing in 2020 (even tho I 
had some prior experience with Python in school but this doesn't 
count) so I didn't had the joy to work with any version of 
FORTRAN. Fun fact: I thought that FORTRAN (do we really need to 
write it in capital letters?) is an ancient language but I made a 
research and found out that it is still updated!!!

More information about the Digitalmars-d mailing list