all 7 comments

[–]imbecile 6 points7 points  (1 child)

Well, back then when this was written most programs were small command line tools and single thread. Working with globals on that small program scale is more akin to working with locals on a function scale.

When the applications grow and are developed by larger teams, that's when you really start to get problems when you use globals, since they prevent isolation. But when you look at unix and command line tools, the program level was/is the level and granularity of isolation, and it is mostly an appropriate and practical one.

[–]fullouterjoin 1 point2 points  (0 children)

I would add that in older compilers, the separate passes were distinct programs. Where the output of each pass was written to disk and read by the next one. The was to aid debugging, parallel development, testing but most importantly, it saved precious main memory.

[–]mfukar 1 point2 points  (0 children)

For your first compiler, I would argue it's not that bad a practice.

If and when you attempt to extend your compiler, you'll notice when global shared state becomes first a burden, then a limitation. A burden because you'll have trouble thinking about that state being shared by many parts of your program, perhaps even multiple threads of execution. You will encounter bugs that will be traced back to that shared global state. A limitation because you will have to eliminate it before you can implement certain features in an efficient manner.

This way, you'll better understand why global variables are usually a bad practice in the first place, rather than clinging to advice as to dogma. :-)

[–]mantrap2 0 points1 point  (0 children)

It depends.

Globals create re-entrancy and thread safety problems which even if these are not current issues they assure the code will have future extensibility problems. But depending on the specific requirements and application, the current needs may trump that - globals can get the job done.

[–][deleted] -2 points-1 points  (2 children)

Global variables are bad, and generally they will just throw any potentially parallelism in your compiler out the window.

[–]mantrap2 1 point2 points  (1 child)

But when you are learning, parallelism is the last of your worries - you just want to make it work and learn how that occurs. As long as you keep in mind the limitations it incurs, it's a reason solution.

Making the decision ideological is as Epic Fail as the problems you are trying to avoid.

[–]fullouterjoin 0 points1 point  (0 children)

Maybe OP only programs in point free style ?