[Tutor] Slightly OT: public/private class members

Erik Price eprice@ptc.com
Fri Feb 14 11:40:04 2003


alan.gauld@bt.com wrote:
>>>And what does strict (Perlicism?) do?
>>
>>strict enforces declaration of variables before usage. So 
>>
>>use strict;
>>
>>makes you issue a
>>
>>my $variableName;
>>
>>statement so the if you accidentally type $myVar or 
>>$myvariable later on, an error will occur, rather than a 
>>new variable being created. 
> 
> 
> Ah, I see. OK that is a nice feature that VB can turn on too.
> For production code it would be nice, for short scripts overkill.
> A 'use strict' equivalent might be a good idea.

Another feature of "use strict" in Perl is that it restricts the scope 
of variables to the file that they are declared within, so that if you 
include multiple files, you don't have namespaces getting trodden over. 
  This is something that Python handles quite nicely by default -- you 
can only import other names into the current namespace explicitly.

So, while Python doesn't require you to declare all your variables ahead 
of time (though you are always welcome to do so by intializing them to 
some dummy value like null or an empty string), the namespace 
preservation feature of "use strict" is built right into the language.

NB I use "use strict" in every Perl script I write (except the 
occasional oneliner).  It is good practice, even for short scripts.


Erik