How to DuckType, or a case study of when lack of static typing bites.

J

John Carter

***********************
No virus was detected in the attachment no filename

Your mail has been scanned by InterScan MSS.
***********************


So the lack of static typing just bit me.

I had a bug, somehow the wrong value crept into an object, and somewhere
much later, my program died. This is _the_ nightmare scenario that grips
any static typer when he lets go of his static types.

Curiously enough in the year or so of slowly adding to this program, this was
the first time it really bit me. But then I tend to have fairly good Unit
Tests, so mostly such things get caught early.

But this one was evil, I had know idea at what level I had gone wrong. I
just had an error message "false::FalseClass does not respond to match".

So I found where that variable was set (in the constructor) and added...
raise "varX must respond to match" unless
@varX.respond_to? :match

And re-ran the program. It bombed out much sooner and the stack trace
showed me where it was called from. I then traced where that high level
variable was set (again a constructor) and added exactly the same line of
code.

Ran again and immediate found the bug. (I had added a parameter to a
constructor, and forgot to add it to the calling routing.)

I'm going to leave those "raise" statements in my code. I am still
the same stupid me, so I will probably make the same stupid mistake again
someday...


John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand

The universe is absolutely plastered with the dashed lines exactly one
space long.
 
J

Jim Freeze

So the lack of static typing just bit me.

I had a bug, somehow the wrong value crept into an object, and somewhere
much later, my program died. This is _the_ nightmare scenario that grips
any static typer when he lets go of his static types.

Curiously enough in the year or so of slowly adding to this program, this was
the first time it really bit me. But then I tend to have fairly good Unit
Tests, so mostly such things get caught early.

But this one was evil, I had know idea at what level I had gone wrong. I
just had an error message "false::FalseClass does not respond to match".

Hmm, one bug in a year, and it sounds like you found the source fairly
quickly. That's not too bad if you ask me. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top