Feature #5977

Remove $, and avoid perlish global variables

Added by Eregon (Benoit Daloze) about 6 years ago. Updated about 6 years ago.

Target version:



As I mentioned at RubyConf, I would like the $, global variable to be removed for 2.0.

I would like to avoid "perlish" global variables in general, but I think many can't be removed for compatibility, and a few are actually useful shortcuts (mostly to the pattern matching variables). They are nice for golfing and small scripts, but I believe they hurt bigger scripts/code.

$, is used as the default separator for Array#join (and Kernel#print), and I think it causes more harm than good:

  • I believe many ruby codes would fail (different and unexpected output) when setting $, , because it means a simple ary.join is not deterministic: you need ary.join('') which is long and quite unexpected for a "default" behavior.
  • The behavior would be much clearer (a simple method with a sensible default) and so the documentation.
  • It's mostly unused, and except for trivial scripts it will just be complicated to manage as it impacts globally the output.

What do you think?

Related issues

Related to Ruby trunk - Bug #14240: warn four special variables: $; $, $/ $\Open


#1 [ruby-core:42577] Updated by rogerdpack (Roger Pack) about 6 years ago

+1 those are incomprehensible for beginners.

#2 [ruby-core:42589] Updated by trans (Thomas Sawyer) about 6 years ago

Yes, but is is serious incompatibility and would have to wait for after 2.0, according to Matz' plans.

#3 [ruby-core:42598] Updated by Eregon (Benoit Daloze) about 6 years ago

It is some kind of incompatibility, but I think most code does not use $, at all, thus only some rare small scripts would be affected.

However, if this is unacceptable for compatibility, please change the target.

#4 [ruby-core:42601] Updated by matz (Yukihiro Matsumoto) about 6 years ago

  • Status changed from Open to Rejected

As Thomas mentioned, Ruby 2.0 would not introduce serious incompatibility. Reopen in the future (3.0?).


#5 Updated by Eregon (Benoit Daloze) 4 months ago

  • Related to Bug #14240: warn four special variables: $; $, $/ $\ added

Also available in: Atom PDF