Really platform-independent code...



  • I found this java code on my home forums:

    String s = (new StringBuilder()).append(Path).append(".bat").toString();
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec((new StringBuilder()).append("cmd /c start ").append(Path).append(".bat").toString());
    textfield.insert("JarFile SUCCESS DONE!!!...\r\n\r\n", 0);

     
    And what does the whole program do? The same thing jar -cf does. The author thought this would be "to complicated" for the "helpless users" out there.


  • There seems to be a WTF.GetInnerWTF() in the code; the carefully constructed string variable s is not used, but instead the command string re-constructed in runtime.exec function call.



  • A lot of WTFs are the result of someone trying to make an "easier" version of a basic function.

    Other WTFs:

    • Using StringBuilder because a 12-year-old book told him it's faster than the + operator.
    • Exclamation points. Maybe he was excited because his computer just told him "You have mail."
    • No process.waitFor() call, so the operation almost certainly is not done when the textfield is updated.

    Normally I might feel bad about critiquing a novice's code, but attempts to replace a tool in widespread use often get passively approved by managers, and suddenly all developers are ordered to use it. Imagine if everyone had to use that WTF when they wished to make a jar file. I once worked with someone who made his own "special" ant build file. A full build had been taking about 5 minutes; after his "improvements" the same build took 48 minutes.


Log in to reply