3 ms·
Perl 6 carries 2 pieces of baggage from its predecessor - prefixing variables with "my" to create lexical scope and the obligatory "use v6;" at the top of every
by cutler 9y ago
Perl 6 carries 2 pieces of baggage from its predecessor - prefixing variables with "my" to create lexical scope and the obligatory "use v6;" at the top of every script. Why can't an advanced language like Perl 6 scope variables without littering "my" everywhere? You don't see it in any other mainstream language I can think of.
- kbenson 9y ago> prefixing variables with "my" to create lexical scope Some people (such as me), prefer designating variable scope and easily identifying where a variable was defined. By the way, that isn't required by Perl 5. It was decided by the community that it was beneficial in that it solved far more problems debugging than the small bit of extra effort required, so the common refrain to "use strict;" was adopted because with that pragma it then is required. > Why can't an advanced language like Perl 6 scope variables without littering "my" everywhere? It could, but the community has decided it's not really beneficial. Have you actually examined why you think it's better? > obligatory "use v6;" at the top of every script That's not obligatory. You can omit at your leisure. If you do in include it and your script is accidentally called from a Perl 5 interpreter, you will either get an error, or if supported it will try to load a Perl 6 interpreter to parse the code.
- cygx 9y agoprefixing variables with "my" to create lexical scope I strongly disagree: From a languge design perspective, block-level lexical scoping with explicit declarations is superior to all alternatives I'm aware of.
- petre 9y agoHow is this different than prefixing variables with var in JavaScript?
- dugword 9y agoJust to be pedantic ;) var creates variables that are function scoped. my creates variables that are block scoped. let in JavaScript would be pretty much the same as my. Both are good things as they prevent typos from being new variables.