From: Nick Woolley Date: 2005-05-04T08:07:49+09:00 Subject: Re: Typo-checking instead of static typing Ben Giddings wrote: > My open question is then: how do you find typos and brainos in seldom-run > code in a dynamic language like Ruby? At the risk of being jeered: I have found perl's 'use strict' with 'my' declarations have helped keep my feet unshot in the past. It won't get everything, but misspelt variables won't pop into existance behind your back. Conversely, javascript has always spent me to deadline hell with just this sort diabolical mischief (grr). I've always wondered why ruby doesn't have somthing similar. Presumably there's some flaw/objection to the idea of having this? But! surely this is exactly what Ben is asking for? Also, conceivably, couldn't (optional) implicit run-time checks be added which match the declared 'type' of an assignee variable to the current type of the assigned object? No type inference, just a little extra runtime overhead (which could be switched off). And/or similar optional preconditions on method arguments? e.g. Fruit var1 = Banana.new # ok Flesh var2 = Sausage.new # ok Object var3 = Hamster.new # no checks on this var var3 = var2 # so, Sausages are okay here var3 = var1 # so are Bananas var1 = var2 # but not here, cos Sausages aren't Fruit - bang! var4 = 0 # var4 isn't predeclared - bang! Um, this seems so obvious I am expecting someone to reveal my cluelessness imminently. Nick