14

Calling all Devs 🤙:

What's the _best_ worst code you've seen in the wild in your corporate codebases?

Include a snippet of the traumatic lines in your comments!

I'll start with a classic:
$send = $enabled ? true : false;

Comments
  • 6
    ($enabled was a Boolean)
  • 5
    Or:

    $shitGodObject->toArray()->toArray();

    .
  • 13
    .AsEnumerable just after table name. Which will... load the whole damn 35 millions record table. Just because dev couldn't make "trim" work inside LinQ query.

    And on the "good" side :

    A while loop which changes direction automaticlly based on some criteria and allows 3 directions. (Forward, backward, "best in slot")
  • 5
    @NoToJavaScript omg I’m getting aroused tell me more about that while loop pls
  • 1
    What does that even mean
  • 1
    I don't think send = enabled ? true: false is that bad

    super readable/understandable. it's not like it obscured anything.
  • 2
    @iceb it's just that it is totally redundant, you can check directly if ( $enabled ), rather than assigning new var of the same val ;)
  • 0
    I had to make a txt file with pearls... but in the hurry of covering their asses ( or mine ) I usually just fix it and continue on the next one... and lately I haven't seen WTFs so I can't bring something from the cache...
  • 3
    Example from our legacy PHP app:

    if (isset($_GET['data'])) {
    $data = $_GET['data'];
    } else (isset($_POST['data'])) {
    $data = $_POST['data'];
    }

    It is a spaghetti nightmare: written like it's 1999. Not even MVC, just, duplicated code everywhere.

    Code, like the example above, is in the top section of almost every file. There is no router btw, just raw dogging .php-files. And forget classes: there are no models. Just pure SQL, directly persisting state changes. Manual testing only btw.

    This thing was (!) vulnerable to SQL injections and XSS and CSRF. Took us at least half a year fixing it, now that I'm thinking about it. Lucky, we are in the midst of rewriting it (greenfield!) 🥰.
  • 1
    @SuspiciousBug am in similar position - we have MVC and automated tests now (just not enough)
  • 6
    A single line can't be that bad since it's just a single line. The real horror are global variables that are touched here and there and affect this and that.
  • 4
    return "ok";

    And that return value gets discarded every time...
  • 2
    More than SIX THOUSAND LINES OF PYTHON CODE IN A SINGLE FILE, that did EXACTLY the same thing, because the script kiddie that crapped it was afraid of defining functions.
    Also, as he told me in as many words, was "too lazy to use for/while loops, so just copy/pasted the same thing many many times"
    That shit was like a fucking megabyte of a single code file.
  • 0
    @JsonBoa I think we have a winner...
Add Comment