My first discovery of the value of this principle was in FORTRAN. In the old days people just started integer variables with I-N and float variables with other letters. But when I started using "IMPLICIT NONE" and found the power of compile-time typo-catching I never looked back.
Python and Ruby claim to be better-designed rivals to Perl, but neither of them has static checking for variable-name typos with the same power as Perl's. Variables on the left-hand side of assignments are particularly vulnerable to error. Python at least has PyChecker; Ruby has nothing.
Ruby users claim that everything can be caught by unit testing. That is a very poor idea because obscure paths through the code may be missed, and then a crash will happen during some crucial run later on. IMHO, unless Ruby comes up with a "strict" variant that allows some minimal static checking it will never be a serious rival for Perl for large projects.
Languages can do even more static checking without getting in the way. For example, OCaml does type inferencing based on the functions being applied to the variables. Explicit declarations are seldom needed for full compile-time type checking. The drawback is that operators have to be distinct by type: for example, "+." is used for floating-point addition and "+" for integer addition.
For me, Perl with "use strict" has a good balance between typo-catching power and simplicity of use. Additional optional "use stricter" checks might be worth looking into, for example doing the same sort of limitations on package-level variables.
This might produce an error or warning about creating a new package variable in code outside the package, instead of silently failing as it does now.use stricter; use Data::Dumper; # typo: should be $Data::Dumper::Maxdepth $Data::Dumper::MaxDepth = 3;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: The power of strict typo-checking
by davido (Cardinal) on Nov 06, 2004 at 16:37 UTC | |
by ihb (Deacon) on Nov 24, 2004 at 01:20 UTC | |
Re: The power of strict typo-checking
by tmoertel (Chaplain) on Nov 06, 2004 at 16:56 UTC |