Barry’s first problem with the code was the use of magic numbers. If the application state variable held “127”, it then certain buttons would be enabled, but if it were “54”, then they should be disabled.

This led to all sorts of rules about combinations of magic numbers, some of which were more obscure than others. A huge library of methods arose to parse them out and derive simple true/false expressions based on combinations of magic numbers.

Barry found this one, deep in the code.

bool[,] set = {
    {T,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,},
    {x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,T,T,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,T,x,},
    {x,x,x,x,x,x,x,x,x,T,T,T,T,T,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,},
    {x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,T,T,T,T,x,},
    {x,x,x,x,T,T,T,T,T,T,T,T,T,T,x,x,x,x,x,x,x,x,x,x,x,x,x,T,x,x,x,x,x,x,},
    {x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,},
    {x,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,},
    {x,x,x,x,x,x,x,x,x,x,T,T,T,T,T,T,T,T,T,T,x,x,x,x,x,x,x,x,x,x,x,x,x,x,},
    {x,x,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,x,x,x,x,x,x,x,},
    {x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,},
    {x,T,x,T,x,T,x,T,x,T,x,T,x,T,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,},}

By indexing the array, it would return either T or x (constants defined elsewhere as true or false), and hence, tell the application what the pair of magic numbers meant.

Barry replaced it with a few basic rules and boolean operations, but not before playing a game of Battleship with it.