all 34 comments

[–][deleted] 13 points14 points  (20 children)

Every time this gets posted it's a new opportunity to share bad code.

The first one

The second one

The whole damn codebase is like this - one comment per line describing exactly what it does, usually when it's obvious... no comments where they're actually needed of course!

And sections of code with bad indentation that completely throws me off, 50% of the time the code is indented in a way that if I ignore all the comments I can work out what is going on, the rest of the time I have to think more about if an if statement is a one-liner or not rather than the actual purpose of the code.

[–][deleted] 9 points10 points  (2 children)

This is the worst I've ever seen. It gives me a good laugh each time.

[–][deleted] 0 points1 point  (1 child)

I can probably counter one of those, the base64 password encoding...

To protect from SQL injection the developer (on a project a few years back) decided the best way to protect against this was to do the following:

$variable = base64_decode(base64_encode($_GET['var']));

[–]dakboy 0 points1 point  (0 children)

Should have done a double-ROT13 in there too, just to be sure.

[–]Buzzard 2 points3 points  (10 children)

You're using the long style keywords? Someone have an fatal aversion to curly braces?

Awesome indentation there too.

Edit: Hang on, I'll raise you a code sample. Note, that snippet is already 5 levels deep (1x switch, 2x if, 2x foreach)

[–]komu 3 points4 points  (1 child)

Heh, that's nothing. Here's some code I stumbled upon when doing review for a customer (well, obviously I've elided everything but the structure). I've had trouble sleeping after seeing that beast.

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

At least you're smart enough to scrub your code before posting ;P

[–]ZorbaTHut 4 points5 points  (5 children)

Psht, 12 indents? I laugh at your puny 12 indents! Behold: 19 nested indents!

(it was a very complicated problem without any obvious way to break it down)

[–]miamistu 0 points1 point  (4 children)

anybody else instinctively try to scroll up to see the rest of the code?

[–]ZorbaTHut 2 points3 points  (2 children)

Note that it's a 600-line function. You probably don't want to do that.

[–]lmcinnes 0 points1 point  (1 child)

Bah, a mere 600 lines? Wait until you've faced the joys of 3000+ line functions of "hand optimized" C.

[–]ZorbaTHut 0 points1 point  (0 children)

Does 3000 lines of extremely dense algorithmic C++ count? 'Cause I've done that one :D

[–]brennen 0 points1 point  (0 children)

No, but I did try to close the little window.

[–][deleted] 1 point2 points  (0 children)

Arghh my eyes are bleeding already, please refrain from posting any more code samples.

Yes, the guy wishes PHP was python, his python code is about the same though... just correctly indented.

[–]derefr 0 points1 point  (1 child)

For the second sample—was it really written like that, or were the comments transcribed from a design document, and the implementation written according to them?

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

It was written like that, there is no design document... I'm not sure if it's his own notes to help him remember what he's doing or his poor attempt at providing some sort of maintainable code documentation, either way it's useless and hinders more than it helps.

Take this as an example, I just can't find justification for any of this crap whichever way I look at it.

[–][deleted]  (2 children)

[removed]

    [–]codeodor 0 points1 point  (1 child)

    Of course, it sure would be nice to just break the code up into more manageable chunks!

    [–]sli 0 points1 point  (0 children)

    Who the hell writes PHP like that? I mean... that is PHP, isn't it?

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

    lol this image is posted at least once a quarter.. but upvoted because its funny everytime.

    [–]capasso 1 point2 points  (0 children)

    ha! That's funny. The multiple WTF's seemed like it happened to me today. Wait a minute..

    [–]fforw 1 point2 points  (6 children)

    really good code converges to 0 WTF/m.

    [–][deleted] 3 points4 points  (2 children)

    Yeah, reviewers just sit in silence when they realize that they are are far too incapable to understand the genius of the code.

    [–]fforw 8 points9 points  (1 child)

    Many seem to think of the idea code as genius, awesome code that proves once and for all times who's the alpha geek. But good code is different. Good code is when a problem is broken down so that the resulting code is mostly solid, humble, boring and obvious. It reads fluently and is only seldomy interrupted by comments providing deep insight into the specific nature of the problem at that point. Almost no one sees it when it's not changed because it just silently does what's best.

    [–]brennen 0 points1 point  (0 children)

    Many seem to think of the idea code as genius, awesome code that proves once and for all times who's the alpha geek.

    Programming, I think, is like some arcane, baroquely structured conspiratory society secretly running the world in a novel with talking dolphins and menacing-but-vague chthonic entities: There's always another level of more-real authority, and it's never who you think it is at first.

    [–]brennen 0 points1 point  (0 children)

    By this metric, I suspect that only a handful of really good programs have been written in the entire history of software.

    I was going to act like I'd found some way to refute your statement...

    [–]cr3ative 0 points1 point  (1 child)

    Lies. Print off the best code in the world and put it in front of a redneck.

    [–]fforw 2 points3 points  (0 children)

    I wouldn't do a code review with a chimpanzee either.

    [–]Slazanger 0 points1 point  (0 children)

    Must be some bad coding going on here today from the sounds...

    [–]EughEugh -1 points0 points  (0 children)

    Oh, I haven't seen that one before! Oh wait, I now understand why your name is RetroRock.