-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop globals, make all variables starting with $ pseudo globals aka magic variables #1395
Comments
I'm in favor (somewhere less than "strongly in favor") of dropping globals, but can you go into the motivations for the things in the bulleted list? |
It's essentially the behaviour of the pseudo globals, I just listed it out. Since we want to keep this my proposal is to make all |
I would drop globals and just keep the few special variables. As their name imply, they are "special" and I wouldn't like having more of those. On the other hand, globals are pretty useful for counting global things in a program, for example how many times a method was invoked, or benchmarking a single method across a whole program, by writing to a global. These are not "serious" use cases, but practical. They could still be done with a class variable, but you need to write a bit more. |
We can also add things like module MyLib
class_property! foo
end |
I think this can be closed. We don't have globals anymore. We have some magic vars like |
Let's say it: we don't need globals. There are plentiful alternatives to global state and all of them are to prefer. Let's list a few:
Now we would want to keep
$?
,$~
and so on, as previously discussed. Let's call them magic variables. But now we got all names starting with$
free, let's allow to define magic variables with any name.Magic variables...
$foo = $foo
. This fails if there wasn't a call defining$foo
prior.The name magic variable suggest that this is still something to be used with care, not as go to tool over multiple return using a tuple or returning a nice struct. It just replaces the, in a object oriented language, useless concept of global variables with something more useful, while removing inconsistency from the language between pseudo globals (
$~
,$?
etc) and global variables.The text was updated successfully, but these errors were encountered: