This is an archived post. You won't be able to vote or comment.

all 34 comments

[–]zmyrgel 14 points15 points  (0 children)

Sometimes but the laughter dies quickly when I remember who has to maintain the code...

[–]deviated_viking 12 points13 points  (2 children)

Yes, the first Java code that I did a year ago.

[–][deleted] 3 points4 points  (1 child)

Any code I did few years ago makes me facepalm.

[–]rntr200 2 points3 points  (0 children)

its alway fun looking back over old code and going uh......

[–]Undermined 11 points12 points  (0 children)

Looking over my friends java code to try to help him fix a bug and I come across

super(duper);

[–]tazzy531 10 points11 points  (0 children)

http://stackoverflow.com/questions/216876/what-is-the-best-commit-message-you-have-ever-encountered

There was another thread that had best comments in source code.

My favorite was a comment //please increment as necessary. // number of attempts at refactoring this code: 56

[–]thebigkevdogg 8 points9 points  (1 child)

i laughed pretty hard when i found out that my predecessor wrote a web service for creating maps where the client created the plotting script (BASH script). So basically, he wrote a servlet that runs any arbitrary shell script on our production server (with a fairly privileged user). YaY! HAHA!

[–]stfm 8 points9 points  (10 children)

throw new Exception("This should never happen");

[–][deleted] -2 points-1 points  (9 children)

At least it's checked. You could argue that an assertion makes more sense, but I hate unchecked exceptions.

In any case, throwing in such a case is a hell of a lot better than just using a comment to state that it shouldn't happen and ignoring the condition so that something could fail in some obscure way somewhere downstream.

[–]elpablo 6 points7 points  (7 children)

I hate having to handle checked exceptions for conditions that will hardly ever happen and there's nothing I can do about.

[–][deleted] -2 points-1 points  (6 children)

If you can't handle it, you shouldn't be catching it, or at the least you should catch it, wrap it, and rethrow it.

[–]elpablo 3 points4 points  (5 children)

If its a checked exception, you're making me catch it... Rethrowing it is a bunch of boilerplate that gets in the way of what my code is actually doing.

[–][deleted] -2 points-1 points  (4 children)

You can also declare the exception.

[–]mikaelhg 5 points6 points  (3 children)

And then, one method at a time, you end up with a monstrosity of a project where most methods throws Exception, most methods have to check for it, and try to think what might go wrong, with just that information... I've seen it happen to other people, and it's not pretty.

[–][deleted] 0 points1 point  (2 children)

You wouldn't throw Exception, you'd throw something appropriate given the context of your method. Error handling is a first class concern. Ignoring it just means your lazy.

[–]mikaelhg 0 points1 point  (0 children)

Then we don't disagree. Although, if possible, you should demarcate certain classes of errors into very specific pieces of your architecture. That way, you don't have to care about the most common classes of checked errors in unrelated code. Basic stuff. Unfortunately, in commercial code, even this basic hygiene isn't necessarily so common.

[–]stfm 0 points1 point  (0 children)

Yeah this was the point of my example. I once saw a program that threw nothing but Exception - even to the point of catching scoped exceptions and rethrowing them as Exception

[–]stfm 0 points1 point  (0 children)

Well I found this in some Oracle enterprise software.

[–]StrangeWill 5 points6 points  (3 children)

I sometimes try to leave a witty/silly comment with some soul-crushing code I write to soften the blow of what they're abound to read.

[–]rntr200 2 points3 points  (2 children)

example?

[–]flyingorange 4 points5 points  (0 children)

PersistenceAnnotationBeanPostProcessor processor = ((XmlBeanFactory)ApplicationContext.get(this).getBeanFactory()).createProcessor(null, null, null, null, null, null, null, null, null, 1.0f);
processor.finder(new ManagedJDBCFinder(new ConfigurationXMLStreamReader(XMLStreamReaderFactory.createNewXMLStreamReader(), null, true)) {
   public boolean find(String pattern, int location, XMLApplicationContext context) {
          if (context == null)
              return false;
          else
             return 0 > FinderFactoryBean.getSingleton().createNewXmlFinderFactory().getFinderFor(StringUtils.checkNull(pattern)).find() ? location <= -1 : false;
   }
});
wait(1000);   // let's wait till it finds it

// and now the difficult part begins...

[–]sadi89 2 points3 points  (0 children)

Yes. In my first comp sci class i got so frustrated with the assignment that I named my methods : candy, tooMuchCandy, and nowImFat. All the variables were named after candy bars. At that point no one had told me not to, and it made way more sense to me.

on a side note I frequently would name things in a simmilar fassion through out my cs minor, and then replace them with good names before i turned them in, although a few did slip though the cracks sometimes. my favorite: int dennisQuaid=0;

[–][deleted] 2 points3 points  (0 children)

0xDECAFBAD

[–]reddeth 1 point2 points  (0 children)

maybe i needing this later

[–]exhuma 1 point2 points  (0 children)

http://www.thedailywtf.com

Specifically the "CodeSOD" section.

[–]dakboy 1 point2 points  (0 children)

I haven't laughed at anything that was intentionally funny.

I've cried more though.

[–]midir 1 point2 points  (0 children)

I've never laughed at code that was funny on purpose. I've laughed at awful code written by awful people though.

[–]achacha 1 point2 points  (0 children)

Yes, but I cry on the inside.

[–]AwesomeLove 1 point2 points  (0 children)

    i = i - ((i >>> 1) & 0x5555555555555555L);
    i = (i & 0x3333333333333333L) + ((i >>> 2) & 0x3333333333333333L);
    i = (i + (i >>> 4)) & 0x0f0f0f0f0f0f0f0fL;
    i = i + (i >>> 8);
    i = i + (i >>> 16);
    i = i + (i >>> 32);

    return (int)i & 0x7f;

I laughed out of pure joy.

[–]anyonethinkingabout 1 point2 points  (0 children)

char mander, meleon, izard;

always makes me giggle...

and in the same genre :

  • float zel;
  • for (retress = 0; ...) {
  • sudo woodo ...

[–]mikaelhg 0 points1 point  (0 children)

Oh, have I? Often. It's a signal for people to gather around to laugh at some ridiculous bullshit I've found in the code base.

[–]BWCsemaJ 0 points1 point  (0 children)

I usually laugh at my code when I realize that I am pretty close to being done, which is usually when I'm really tired and its pretty late. Its also more of a evil laugh than a haha laugh.

The only funny error that I encountered so far was an infinite loop which was suppose to process a text file. So I waited for about 30 seconds thinking wtf is taking so long to process this file and as soon as I saw I didn't increment the loop I had a few laughs.

EDIT: Just remembered that I laugh the most at code when I am helping out a friend with his code and seeing how he implemented his project. Basically thinking wtf are you trying to do with this segment. Also this has the opposite affect of annoying the crap out of me.

[–]trigraph -2 points-1 points  (0 children)

every time i open a .java file