Why people dislike global variables so much while I find them so convenient?
rempas
rempas at tutanota.com
Thu Jan 27 06:35:50 UTC 2022
On Wednesday, 26 January 2022 at 11:38:51 UTC, forkit wrote:
> On Wednesday, 26 January 2022 at 11:29:31 UTC, forkit wrote:
>> so you asked for an example where you could slip up using a
>> global variable.
>> well, that was an example.
>> you have a local variable the same name as global variable..
>> you mistyped... and... boom!
> oh. what is actually going on in foo is irrelevant of course.
>
> foo does nothing of any relevance.
>
> the point I was making, was about having a global variable with
> the same name as as a local variable, could 'potentially' slip
> you up.
Thanks for the example! You are right but I personally would
never use global variables this way as it doesn't make sense. The
idea is that, the global should be shared across every (or most)
function in my project so there is no point to create a local
variable with the same name (which probably also means that it
does the same thing as your global one) as the global one. In
this case, it will be better to use a local variable. It also
makes a lot more sense.
More information about the Digitalmars-d
mailing list