4 ms·
I prefer no collisions to be the default. So foo = 12 No need to worry there's some global "foo" I overwrote (since it means knowing the entire program 1
by tokyodude 8y ago
I prefer no collisions to be the default.
So
foo = 12
No need to worry there's some global "foo" I overwrote (since it means knowing the entire program 10 lines or a million). That's actually one thing I think python got right over C/C++/C#/Java in that "foo=12" is always a local variable. It's never a member of the class. That's explicit as in "self.foo = 12". No ambiguity. JavaScript got that part right "this.foo = 12" but it got the other part wrong "foo=12" could be the global scope and there's no warning, just "you just crapped on the global namespace, good luck finding your bug" :( Fortunately modern tools like eslint catch that bug for me in JS
- mst 8y agoIn perl5 $foo is never a class member either. Also, you can use 'our' to restrict access to a global to a specific scope. Also, javascript now has 'use strict' (stolen from perl5) which prevents that problem there too. I fear you have been misinformed about both languages.
- tokyodude 8y agoThe problem with both is it's not the default. I shouldn't have to know some special syntax that makes my code safe (having to put $ in front or use `var` or `let`. It should be hard to mess up, not hard to not mess up. You can see the progression of perl from bad to tacked on workarounds. First "local" was added to manually copy values to some stack. Then "my" was added. But all the old problems are still there. Then there's all the massive mess of $foo vs %foo vs @foo vs &foo. That's super cryptic and leads to really hard to parse code (IMO obviously). And all the ridiculous cryptic globals https://www.perlmonks.org/?node_id=353259 https://www.perlmonks.org/?node_id=353259 No thank you
- lizmat 8y ago> The problem with both is it's not the default. In Perl 6 declaration of any variable is obligatory by default. > Then there's all the massive mess of $foo vs %foo vs @foo vs &foo In Perl 6 that has all been made more systematic. Check out https://opensource.com/article/18/9/using-sigils-perl-6 https://opensource.com/article/18/9/using-sigils-perl-6 if you want to know how Perl 6 differs from Perl 5 in that respect, and how you can actually have sigilless variables in Perl 6. > And all the ridiculous cryptic globals Perl 6 basically only has `$_` (the topic), `$/` (the current match result) and `$!` (the last error) as "cryptic" lexicals. See https://docs.perl6.org/language/5to6-perlvar https://docs.perl6.org/language/5to6-perlvar for a list of Perl 5 variables -> Perl 6 functionality