Thursday, May 25, 2006

If in doubt, test, test and test again

Thanks to Rob Baillie for the following example...


I was glancing through some legacy code today, and came across this.

It's funny how barnacles can accumulate when code changes over time.

            if r2.status_id = 3 then
                 v_gp := r2.rate;
            elsif r2.status_id in (11, 12) then
                if r2.type_id = 3 then
                    v_gp := r2.rate;
                else
                    v_gp := r2.rate;
                end if;
            else
                v_gp := r2.rate;
            end if;

Skip over the record being called r2 and work out what it actually does...

2 comments:

Noons said...

That v_gp WILL be equal to r2.rate, if it's the last thing I do!!!

FuzzyPig said...

It's one of the statements that just makes your world stop spinning for a few minutes and you feel this overwhelming need to re-code it at the expense of all else in the universe!