[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why are people so afraid of globals?
- From: Louis-Philippe <default@...>
- Date: Fri, 9 Jul 2010 12:40:15 -0400
indeed, Ruby's use of special formats for defining variable scope could be seen as rather perlish or ugly but it is in practice an assurance in clear scoping and easily readable code. Perl uses symbol to specify variable type, Ruby uses almost the same symbols for scoping like:
$var # is global
@var # is instance var
@@var # is class var
var # is local
2010/7/9 Mark Hamburg
<mark@grubmah.com>
On Jul 9, 2010, at 7:00 AM, Roberto Ierusalimschy wrote:
> The problem that concerns me is assignment to globals meant to be
> locals, either because someone only forgot to add 'local' or because he
> knows no better. This kind of bug is easy to write and hard to find.
The Smalltalk and Ruby fix for that: Variable name formatting determines the namespace in which to look.
This causes a certain amount of shuddering when I think about it, but it does mean that globals look like globals and locals look like locals. I think it also has precedence in Common LISP's format for naming dynamically scoped variables.
But it also fights with the various environment switching techniques like module(). That, however, gets us back to the observation that the 5.2work3 change to use the _ENV variable makes it clearer in the code what code is working at chunk scope and what code is working in some other environment.
Mark