News for hackers. Stuff that matters.
Re:Ask HN: What's the largest amount of bad code you have ev... by pengo on Tuesday November 13, 2018 @01:43PM (#18443548)
Ten years ago I was called in to remediate a new web application which had been subcontracted to an Indian development company. The PHP developers who'd put it together evidently didn't know about classes, and each page in the application was hundreds, sometimes thousands, of lines of spaghetti code, most containing the same duplicated (but subtly changed) blocks providing database connectivity etc. Security had not been a concern either; passwords and credit card details were stored unencrypted in database text fields.

I was called in because, while most of the application worked, some of the requested features were not yet complete. When I made my initial recommendation (scrap the whole thing and start again) I was told the client's board would not agree to that because of the money already invested and the fact that the board had seen a demonstration proving that "most of it worked".

It took two developers eighteen months to beat this sorry mess into a maintainable state while ensuring it remained "usable". It would have taken one third of that time to rewrite it from scratch.

Re:Ask HN: What's the largest amount of bad code you have ev... by joeax on Tuesday November 13, 2018 @11:01PM (#18447368)
> most containing the same duplicated (but subtly changed) blocks

I had a similar experience with an offshore company. This was during the early-mid 2000s, at the height of the offshoring era when $10/hour programmers in India were aplenty and everyone felt their job was soon to be outsourced. Turns out, no joke, they were being paid per line of code.

Despite having to maintain the heap of crap, I was amazed at the brilliance of their maniacal dark-art ability to implement as little functionality with as many lines of code possible. It was like code golf in reverse.

Re:Ask HN: What's the largest amount of bad code you have ev... by exikyut on Wednesday November 14, 2018 @05:52AM (#18448959)
What sorts of techniques did they use? I'm very curious to see/hear examples.
Re:Ask HN: What's the largest amount of bad code you have ev... by brianpgordon on Wednesday November 14, 2018 @07:53AM (#18449463)

    function isTrue(v) {
      var result;
      result = v;
      if (!isFalse(result == true)) {
        return result;
      } else {
        return isFalse(result);
      }
    }

    function isFalse(v) {
      var result;
      result = v;
      if (!isTrue(result == true)) {
        return isFalse(result); // Tail recursion so this is fine.
      } else {
        return result;
      }
    }

    if (isTrue(myBool) == true) { // TODO: Could this be refactored to isTrue(isTrue(myBool))? 
      return true;
    } else if (isTrue(isFalse(myBool))) {
      return false;
    } else if (isFalse(isTrue(myBool))) {
      return false;
    } else {
      return isFalse(isFalse(myBool));
    }
Re:Ask HN: What's the largest amount of bad code you have ev... by strikelaserclaw on Wednesday November 14, 2018 @10:46AM (#18450707)
i hope to god that this is just code you made up to be facetious.
Re:Ask HN: What's the largest amount of bad code you have ev... by brianpgordon on Wednesday November 14, 2018 @11:06AM (#18450884)
Haha, yes I made it up. The infinite recursion should have been a dead giveaway :P

There's also a bug on line 7 that I didn't notice - it should be isTrue rather than isFalse. I can't edit the comment anymore to fix it.

Re:Ask HN: What's the largest amount of bad code you have ev... by tomazio on Wednesday November 14, 2018 @10:22AM (#18450479)
This is literally insane.
Re:Ask HN: What's the largest amount of bad code you have ev... by aussieguy1234 on Wednesday November 14, 2018 @05:44AM (#18448919)
10 years ago PHP didn't have classes
Re:Ask HN: What's the largest amount of bad code you have ev... by cpburns2009 on Wednesday November 14, 2018 @10:42AM (#18450673)
PHP 5 was released 14 years ago in July, 2004. One of its new features was OOP. Classes were supported at that time. In fact, a comment from 14 years ago shows an example class [1].

[1]: http://php.net/manual/en/language.oop5.php#46290

Re:Ask HN: What's the largest amount of bad code you have ev... by rpeden on Wednesday November 14, 2018 @11:42AM (#18451203)
Sure it did. Classes in PHP showed up in version 4.0 18 years ago.
Re:Ask HN: What's the largest amount of bad code you have ev... by abledon on Wednesday November 14, 2018 @09:09AM (#18449898)
Why didn’t you rewrite it from scratch and then just replace the codebase in 1 giant commit ? Seems doable if you have the balls
Re:Ask HN: What's the largest amount of bad code you have ev... by edoo on Wednesday November 14, 2018 @02:29AM (#18448190)
I had a very very similar experience. I saw the craziest code in my entire career while debugging performance issues. Even though they were using a PHP MVC framework, they were pulling every record from a db table to iterate over to find the record using PHP string compare functions. I still can't believe it. The dev shop I worked for back then was even in the habit of hiring multiple teams for the same project in the hopes one actually completed it and it was still cheaper.
Re:Ask HN: What's the largest amount of bad code you have ev... by Rjevski on Wednesday November 14, 2018 @02:51AM (#18448276)
> pulling every record from a db table to iterate over to find the record using PHP string compare functions

As horrible as this sounds, this is actually good from a refactoring point of view because it should be straightforward to rewrite it to use actual queries.

Re:Ask HN: What's the largest amount of bad code you have ev... by edoo on Wednesday November 14, 2018 @03:42PM (#18453711)
Perhaps technically true, but the entire point of the MVC is you can do simple record retrievals with a single line of code using auto generated active record models. One line vs a monstrous dirty function isn't acceptable.
Re:Ask HN: What's the largest amount of bad code you have ev... by exikyut on Wednesday November 14, 2018 @05:53AM (#18448961)
D':