3 ms·
> It's because Ruby scopes sigil-less variables locally by default. I'm pretty sure autarch knows that. I come from the Python world (and have done quite a bi
by masklinn 15y ago
> It's because Ruby scopes sigil-less variables locally by default.
I'm pretty sure autarch knows that.
I come from the Python world (and have done quite a bit of Ruby as well as a few other languages) and have come to dislike all implicit scoping, it is less readable and always ends up leading to annoying (and hard to track) bugs. This is magnified in Python due to scoping being historically wonky (there used to be no lexical scoping at all, only function-local and module-global) and leading to `global` and (in Python 3) `nonlocal` (yay two crappy keywords and statements instead of having a single clear one)
Whatever the case, these will trip people up and really provide little to no gain, explicit lexical scoping is clearer and leads to less bugs, both from shadowing an existing variable and from hooking into (and overwriting) the same. It's also pretty easy to statically check, in a statically (lexically) scoped language.
Interestingly, that (along with first-class blocks, keyword messages and the cascading operator) is one of the very nice things Ruby threw away from its (limited) Smalltalk ancestry.
> Ruby gives you the safe, local
and often wrong
> thing by default.
- jfb 15y agoI suppose it's stuff like this that leads to the dozens of abandoned language implementations that litter the world of software like balled up hamburger wrappers outside a truck stop. It's enough to drive a man back to Scheme. Why do all of these sh++ languages get so much right and so much wrong? My personal preference from the list is Python, but it's full of irritants as well.
- viraptor 15y agoAt least there are tools for python which will catch misnamed variables: $ pychecker a.py Processing module a (a.py)... Warnings... a.py:3: Local variable (somevar) not used a.py:4: Local variable (someothervar) shadows global defined on line 1 a.py:5: Local variable (someothervar) shadows global defined on line 1 a.py:5: No global (some_func) found not every problem with scoping can be caught that way, but hey... can't have everything.