Re: Last Element Reference

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message ----- 
From: "Juergen Luethje" <j.lue at gmx.de>
To: "EUforum" <EUforum at topica.com>
Subject: Re: Last Element Reference


> 
> 
> Lucius wrote:
> 
> > I don't want negative indexing. I use to like the idea.  But it is too
> > easy for certain bugs to creep in and certain errors to go
> > undetected for a long time.
> 
> At the moment, I can't imagine a piece of code where something like that
> happens. Can you give an example, please?
> 

    -- Build list.
    for i = 1 to length(s) do
        rid = routine_id(funcA(s[i]))
        if rid > length(ridlist) then
            ridlist &= repeat(-1, rid - length(ridlist))
        end if
        ridlist[rid] = DefaultValues
    end for

    . . . then later in program

    rid =  routine_id(funcA(x))
    ridlist[rid] = UpdatedValues
    . . .

Okay, so here we have a program that stores some parameter values that are
indexed via the Routine_ID that they apply to. This works fine until we supply
the funcA() routine an unknown routine name. In that case it returns a -1. Now if
negative indexing were allowed, this would update the LAST parameter set rather
than causing an exception. Yes, its a bug and poor programming practice, but it
might take awhile to detect and to find.

Although this is contrived, it is a realistic scenario.

A similar situation could be set up for file handles returned by open() as that
uses -1 to signal an error too.

-- 
Derek


        
Ok, so here is a piece of code that is supposed to do something with a element
of a sequence, but we don't know where abouts that portion starts until run time.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu