On Jan 31, 2008 11:25 PM, Tim C. [email protected] wrote:
harder than they should be bugs I’ve had to trace.
Yes, though this may be due to me not having learned when to apply
this and not - I’ve only tested it out for fairly small projects.
Probably the core problem in how I used it was that I added checks
“all over the place”. This got in the way of refactoring; in quite a
bit of code, things are passed through that are used elsewhere, and
when I added more checks for this, it was no longer trivial to change
the type of the pass-through parameter.
For instance, I was working on a firewall maintenance application, and
at some point I wanted to change from an IP address to a rule number
(or vice versa, I don’t remember) as an identifier for what to
manipulate. Without checks, it was a three line change - change at
the original originator of the ID, change at the two consumers. With
type checks, I ended up needing to modify things all over the place.
The mistake, of course, was that I’d been using more concrete types
than I should at the point where I declared the checks - but - this is
a thinking shortcut that I think we all do at times. I was thinking
of that IP address as an IP address, not as an identifier for
something that could be identified another way, and it was natural to
check for what I was actually dealing with.
It is possible that conservative application of the type checking
library could be useful. I have, for instance, used it to add checks
to a hash to enforce that only Integers were inserted/indexed into it,
because I was processing data that both came from a database and from
text files, and wanted to make sure that the same kind identifier was
used (ie, that I didn’t get a string “1234” from the text file and
tried to use it as an identifier, checking to find the record 1234).
Adding this check to the hash was useful - it was part of debugging
process, and meant that I could be sure that the bugs I was seeing at
least didn’t come from that particular error.
Apart from that, I wonder if it might be useful to add checks at the
“edges of libraries” - the public APIs that people consume. This
would both function as very formal documentation and trap errors in
cases where they are more likely to occur.