Is it really tempting for people? They’ve given me too many headaches when I’ve had to reformat or add functionality to files.
Unless it’s a simple single use script that fit on the computer screen, I don’t feel like global variables would ever be tempting, unless it’s for constants.
They’ve given me too many headaches…
I.e. you did use them, but learned the hard way why you shouldn’t.
Very likely OP is a student, or entry-level programmer, and is avoiding them because they were told to, and just haven’t done enough refactoring & debugging or worked on large enough code bases to ‘get’ it yet.
This community makes more sense when you realize the majority of users are CS students.
“But what if I put the whole program into a class and then made it a class wide variable?”
Sounds like the piece of legacy software I have do deal with.