Java "loop unrolling"



  • i like to supplement tdwtf with java forums. here is a gem i found today:

    [url]http://forum.java.sun.com/thread.jspa?threadID=785512[/url]

    First of all, the request is a WTF, but then if you scroll down in the code, you can see what i can only call 'loop unrolling' wtf

     

     

     



  • Oh My God.

    No wonder he can't figure out how to combine some multicast chat client with his game; looks like a monkey punched away on a typewriter!  Surely this is a first-year Java class he is doing this "game" for (especially considering the GPA references).  Not only does he use the classic "hundred-and-one case statements", he uses nearly as many numbered functions!  And I'm assuming the coordinates array is the coordinates of spaces on a game board or something.  The comments (or lack thereof) are hardly a surprise either.  I feel like I'm looking at one of those "spot the 7 problems with this picture" games.

    And yet, it never ceases to amaze me how many students (or even "developers") will paste several screenfulls of code and say, "What's wrong with this?"  No explanation of the problem, nor of what they have done to troubleshoot it so far.  Hell, half of the time they specifically say, "How do I do this?"  Where 'this' is really there entire project.  These sound like the kinds of sheltered kids who can't even do their own damn laundry.  Hell, daddy probably bought this kid a BMW for his 16th birthday, which he promptly totalled off.
     

    Absolutely outrageous. 



  • I was going to post a reply here complaining that you linked to another forum page rather than just copying and pasting the WTF snippet here. Then I read the page and realised just how much you would have to copy and paste......

    Please all you young idiot devs out there, working on your games and what-not, please, when you read about how unrolling loops can sometimes be advantageous for developing games, please, please, don't do it like this. It makes me want to cry and puke at the same time.

    Design, people.



  • [quote user="RevEng"]

    Oh My God.

    No wonder he can't figure out how to combine some multicast chat client with his game; looks like a monkey punched away on a typewriter!

    [/quote]

    I see no need to gratuitously insult monkeys.
     



  • Those devs should have been taken to some place forced to write procedural code so that they come back and design a sh*tload of OO games.



  • The real WTF is the manually centered help text... and the case statements... and the use of Java, oh wait...

    The real WTF is this: "After the chat program is added to the java game, we can't see the chat GUI" and then later on in the replies "I haven't done anything. I just want someone to tell me how to put the chat code into the game code" and then one minute later "I've tried a number of things I just need suggestions on other options i can do."

    If you're going to pawn your learning experience off onto random forum-goers, at least get your damn story straight!!



  • Wow.  I can understand people who started programming with
    punchcards having no interest in OO design or javadoc, but who is
    teaching kids to program like this?  My instinctive response is,
    "Anything without javadoc is a waste of your time.  And our time."



  • I read somewhere that compilers do "loop unrolling" as an optimization, so loop unrolling must make your program go faster.

    I'm writing a game and games have to go fast.  So I'm going to unroll all my loops and have the fastest game ever!

    Oh, and my password is "HOUSE*MAGNET" because CompuServe says that's the most unguessable password.

     



  • [quote user="VGR"]Wow.  I can understand people who started programming with
    punchcards having no interest in OO design or javadoc, but who is
    teaching kids to program like this?  My instinctive response is,
    "Anything without javadoc is a waste of your time.  And our time."
    [/quote]

    JavaDoc is great for API documentation, but comments are often just deoderant for smelly code.

    If you name things in a way that conveys your intention, then your wasting time with comments.  If you're not naming things that way, then your wasting time everywhere else.

     



  • [quote user="danielpitts"]

    JavaDoc is great for API documentation, but comments are often just deoderant for smelly code.

    If
    you name things in a way that conveys your intention, then your wasting
    time with comments.  If you're not naming things that way, then
    your wasting time everywhere else.

    [/quote]

    Sensible naming
    is important, but it's no replacement for stating preconditions,
    stating postconditions, listing potential exceptions, and in a pre-1.5
    code base, specifying the contents of any Map or Collection parameters
    or return values.

    Naming a method, say, getServerURLsAsListOfNonNullStrings() is likely to elicit a lecture from me in a code review.



  • Excuse my ignorance if I'm wrong, as it's been a while since I did anything with GUIs in Java, but isn't he just not calling .show() on the chat JFrame?

    Also, I'd have to admit that the first code I ever wrote most likely looked something like that... in fact, one of the very first exercises we did as part of my programming classes was to implement a somewhat simple card game using absolutely no loops. This was just as a starter exercise... most of us had no concept of the loop that early in the course, although most of us did discover recursion as a result :P
     



  • [quote user="VGR"]My instinctive response is,
    "Anything without javadoc is a waste of your time.  And our time."[/quote]

    Now there's a WTF to be proud of. Javadoc might be helpful, but decent source code doesn't need it to be useful. Apart from the obvious snide aside that you seem to be calling everything non-Java a waste of time, Javadoc is only necessary for the public interface to a widely-used (dare I say it? ... enterprisey) module.


Log in to reply
 

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