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

Discussion in 'Ruby' started by John Carter, May 24, 2004.

  1. John Carter

    John Carter Guest

    ***********************
    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 :
    New Zealand

    The universe is absolutely plastered with the dashed lines exactly one
    space long.
     
    John Carter, May 24, 2004
    #1
    1. Advertising

  2. John Carter

    Jim Freeze Guest

    On Monday, 24 May 2004 at 9:05:44 +0900, John Carter wrote:
    >
    > 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. :)

    --
    Jim Freeze
    "I know the answer! The answer lies within the heart of all mankind!
    The answer is twelve? I think I'm in the wrong building."
    -- Charles Schulz
     
    Jim Freeze, May 24, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JimLad
    Replies:
    0
    Views:
    501
    JimLad
    Jan 26, 2010
  2. Mills Thomas (app1tam)

    Ducktype, right?

    Mills Thomas (app1tam), Aug 7, 2003, in forum: Ruby
    Replies:
    2
    Views:
    90
    Florian Frank
    Aug 8, 2003
  3. Sean O'Dell

    How to ducktype a Hash?

    Sean O'Dell, Jun 5, 2004, in forum: Ruby
    Replies:
    127
    Views:
    939
    Uwe Kubosch
    Jun 13, 2004
  4. Charles Oliver Nutter
    Replies:
    4
    Views:
    144
    Rick DeNatale
    Oct 2, 2007
  5. Russ P.

    A Pragmatic Case for Static Typing

    Russ P., Sep 2, 2013, in forum: Python
    Replies:
    9
    Views:
    127
    Joel Goldstick
    Sep 3, 2013
Loading...

Share This Page