Beatiful WTF



  • It's later than 4AM a I just want express my frustration with some less-than-optimized code from a colleague :-/

        private ArrayList<String> m_DisabledCells = new ArrayList<String>();

        (...) 

        @Override
        public boolean isCellEditable(int p_row, int p_column)
        {
            for (Iterator it = m_DisabledCells.iterator(); it.hasNext();)
            {
                String v_Address = (String)it.next();
                String[] v_Coordenate = v_Address.split(",");
                if (v_Coordinate[0].equals(p_row + "")
                    && v_Coordinate[1].equals(p_column + ""))
                {
                    return false;
                }
            }
            return true;
        }

        public void setCellDisabled(int row, int column)
        {
            m_DisabledCells.add(row + "," + column);
        }

        (...)


    Never mind there are only two columns, the first one can never be edited :-/



  • couldn't this be reduced to one line if a hashtable was used?



  • Has this guy ever heard of a 2D array? That whole method could be reduced to { return CellStates[row][column] } if CellStates was a rows x column array of booleans.



  • It can already. return !m_DisabledCells.contains(row + "," + column);



  • The real WTF is that its not enterprisy enough:

    return getCellRow(Integer.valueOf(new Integer(row).toString())).getCell(column).getEditibleFlag().getFlagValue()) == true;



  • [quote user="channer"]couldn't this be reduced to one line if a hashtable was used?
    [/quote]

    Indeed, and it would increase performance by a factor n. Using a 2d array would do so as well, but nevertheless it is a wtf-solution in some cases. Think of an 10.000x10.000 array with only a few  disabled cells. Quite a waste of storage space eh?

    Another wtf is of course the use of a String to encode coordinates. Another unnecessary performance hit, especially because there even is a predefined class for it, Point...



  • [quote user="channer"]couldn't this be reduced to one line if a hashtable was used?
    [/quote]

    [quote user="djork"]Has this guy ever heard of a 2D array? That whole method could be reduced to { return CellStates[row][column] } if CellStates was a rows x column array of booleans.[/quote]

    Hasn't this guy ever heard of getting a job serving ribs at "Pigs R us" and staing th f**k away from computers?


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.