Joel VanderWerf
11/29/2003 1:24:00 AM
David A. Black wrote:
> Hi --
>
> An open question for Matz:
>
> Is anything disappearing from Ruby in 2.0? Not that I have a very big
> list of things I want removed :-) but I'm wondering, for example,
> about the Perl-like special variables. And just wondering generally
> if there's anything in that category.
If the perlish globals are going away, then that suggests another
possibility that would make the remaining globals more regular. I often
have to look up which globals are per-thread (and this was especially
true when I was starting out with ruby). What if the name of the global
determined in a very simple way whether is was per-thread or not?
For example, the rule could be: all globals matching /\$_\w*/ are
per-thread. All others are per-process. That's consistent with the
current use of $_, which is per-thread.
What breaks? Well, if you take out all the perlish variables from the
list in the Pickaxe (pp.216-218), the only variable whose behavior would
change is $SAFE. So that would have to be replaced with $_SAFE, or left
as a special case (perhaps with a warning, and expiring after a while).
I'd rather remember one special case than two pages of them. The
standard library is unaffected, aside from any use of $SAFE, since there
are no variables in it that match /\$_\w+/. Same goes for all the RAA
projects that I've downloaded.
This change would also make it easy to work with user-defined thread
local variables. Instead of
Thread.new {
Thread.current[:foo] = 3
}
you could simply do
Thread.new {
$_foo = 3
}
I guess that's probably more efficient, too, since it saves a method call.