Useful?



  • There is sooo much that I could post, but I don't want to flood this forum with it, so here's a random one:

    public class ArrayConverter {

        public BaseCourse[] convBaseCourse(Collection list) {
            BaseCourse[] basecourselist = null;
            int x = list.size();
            basecourselist = new BaseCourse[x];
            Iterator iter = list.iterator();
            int counter = 0;
            while(iter.hasNext()) {
                basecourselist[counter] = (BaseCourse) iter.next();
                counter++;
            }
            return basecourselist;
        }

        public Array[] convertCollectionToArray(Collection collection) {
            Array[] array = null;
            int x = collection.size();
            array = new Array[x];
            Iterator iter = collection.iterator();
            int counter = 0;
            while(iter.hasNext()) {
                array[counter] = (Array) iter.next();
                counter++;
            }
            return array;
        }

    ...snip...

        public SearchAttribute[] convSearchAttr(Collection list) {
            SearchAttribute[] attrlist = null;
            int x = list.size();
            attrlist = new SearchAttribute[x];
            Iterator iter = list.iterator();
            int counter = 0;
            while(iter.hasNext()) {
                attrlist[counter] = (SearchAttribute) iter.next();
                counter++;
            }
            return attrlist;
        }

        public Array[] listConverter(List list) {
            Array[] array = null;
            int x = list.size();
            array = new Array[x];
            Iterator iter = list.iterator();
            int counter = 0;
            while(iter.hasNext()) {
                array[counter] = (Array) iter.next();
                counter++;
            }
            return array;
        }

    }

    I guess they never bothered to check the API for Collection's toArray(Object[] a) method, which completely replaces this whole class.  Not only that, but some of the methods take a Collection and some take a List. 

    Some other fun facts about this specific wtf:

    -All these methods could have been static and the whole thing used as a utility class.

    -When they do use this class, a separate instance is instantiated for each method they use instead of just using one instance for them all like so:

                ArrayConverter feearray = new ArrayConverter();
                ArrayConverter gradmtharray = new ArrayConverter();
                ArrayConverter coursemssgarray = new ArrayConverter();
                ArrayConverter labarray = new ArrayConverter();
                ArrayConverter lecturearray = new ArrayConverter();
                Fee[] fees1 = new Fee[feelist.size()];
                fees1 = feearray.convFees(feelist);
                GradeMethod[] grdmthd = new GradeMethod[gradmthlist.size()];
                grdmthd = gradmtharray.convGradeMethods(gradmthlist);
                 etc...

    -The dev who created this thing is still creating green field code

    I have some better WTFs, but this one was easiest to write up.  I might post some more later. 



  • I wish I had a pound for every time someone re-implemented a Java API class / method and made it worse in the process.

    This is quite a bad one, though! 



  • @nucleoid said:

    -All these methods could have been static and the whole thing used as a utility class.

    -When they do use this class, a separate instance is instantiated for each method they use instead of just using one instance for them all like so:

    GAH! That's absolutely terrible! I've only been using C# for about a year or so now, but I knew about making static utility classes long ago. Ouch!



  • @PhillS said:

    I wish I had a pound for every time someone re-implemented a Java API class / method and made it worse in the process.

    You'd weigh a tonne! 


Log in to reply
 

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