BG = Ben Giddings
JJ = John Johnson
Is there a good way to get what type checking does for you? Maybe some
catching typos, like calling the class variable @my_var, but ending up
using it as @myvar.
Test First Design?
Ok, but compare:
“Test 473 failed: expecting 17, got 18”
with
“warning: on line 765 of myfile.rb: @myvar may not have been initialized”
I think the second one is more useful, and it is a typical type
of output from compilers for compiled languages. It is much quicker and
zeroes in on the actual problem faster than a test failing. I’m of course
not advocating that Ruby become a compiled language, but it would be nice
if there were a way to do the kind of checks that a compiler does.
Well, Ruby is a compiled language; it’s just not compiled all
the way to a persistent standalone executable. It’s certainly
possible to do those sorts of checks in the compilation phase of
a language like Ruby; a good example is the ‘use strict’ pragma
in Perl, which requires that variables be declared before use.
Ruby could similarly have an option that, when enabled, would
require variables to be initialized before being referenced.
Of course, as regards @my_var vs @myvar vs @myVar, the best approach
would be to pick a naming style and stick with it.
-Mark