Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping help
#21
one thing is using global variables (not recommended, but acceptable) and other thing - to update the underlying dict using globals() to get reference to it. Or vars() to that matter.

Simple is better than complex.
Complex is better than complicated.

And in this case it's a complicated, instead of simple, yet better than eval()
Reply
#22
Well, we also say that modules are good, and doing from some_package import * is bad, but that's the only way you CAN do things in C. Python is supposed to be better. Just because we can do things this way, doesn't mean that they should be done that way.

There are obviously some cases (though not very many) where eval and globals make sense, just like there's some cases goto makes sense. This is not one of those cases, and I don't think most people will encounter them.

I do agree that immutable globals aren't that bad. The main issue I have with them, is that any part of your code can be reading/changing the values, so if something doesn't work as expected, it's incredibly difficult to hunt down why a variable has a certain value. In addition to that, one of the best things a fragment of code can be, is clear. If you can't immediately tell what a function is doing, because it's using values that are defined/modified *anywhere*, then that function is NOT clear.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020