Why is it considered bad practice to use “global” reference inside functions? [duplicate]

I think a top reason for avoiding this is that it hides dependencies.

Your functions get_data and run_html do not advertise in any way that they share data, and yet they do, in a big way. And there is no way (short of reading the code) to know that run_html will be useless if get_data has not been called.

As the complexity of your codebase grows, this kind of lurking dependency will make your code fragile and hard to reason about.

Leave a Comment

tech