top | item 5248473

Ask HN: what is the most stupid line of code you saw?

8 points| _yields | 13 years ago | reply

Believe it or not, i just saw this:

`if (true === true)`

^^ Old PHP site.

19 comments

order
[+] fzfzqfz|13 years ago|reply
Old php site from year 2000.

Each line of HTML is generated like that :

$html.='<html>';

$html.='<body>';

$html.='The content';

$html.='</body>';

$html.='</html>';

The dev used this in every file, each file contain thousands of lines like that. Worst project i have ever seen, and i must work alone on it. FML.

[+] krapp|13 years ago|reply
I've seen this done with SQL queries all the time but... ouch.
[+] pyfap|13 years ago|reply
Saw the title. Immediately thought of something I saw today at work. Not too different from yours. 'if ('True' == 'True')'. I should note that this is javascript generated by a template file.
[+] tdubbed|13 years ago|reply
I've actually used 1==2 and 1==1 to basically comment sections out or create an infinite while loop. Only really useful in C-style languages

Dumb mistakes I've seen include commented out error checking because of a reversed greater than sign and a SQL query that deletes the whole table before rebuilding the entire thing every day

[+] eb0la|13 years ago|reply
I remember in college, someone left his/hers C assignment source code in the lab (laptops were a luxury in that time).

The code was really awful, and that part hurt my eyes:

/* commented out code. <--- Yep. That was the actual comment.

  and here was the code
  seriously
 */
At least (s)he knew what a block comment was.
[+] DanielN|13 years ago|reply
My personal favorite:

  $array = array('z'=>12, 'o'=>43, 't'=>32, 'th'=>85, 'f'=>91, 'fi'=>42);
Take a minute look at that and tell me what the keys stand for. When you figure it out you'll realize why this is the worst piece of code you've ever seen.
[+] whalesalad|13 years ago|reply
I do that sometimes during debugging. It stands out and I know to change it later. If 1 == 0, etc...
[+] chrisdevereux|13 years ago|reply
This might make some sense if it wasn't for the comment at the end...

  enum BankID {
   ONE = 1,
   TWO = 2,
   THREE = 3,
   FOUR = 4
   // add more if needed
  };
[+] AbhishekBiswal|13 years ago|reply
My Teacher used this code to explain conditions in class :

if( 1 == 1 ) cout << "it's true" << endl; else cout << "false" << endl;

Haha, 1==1

[+] orangethirty|13 years ago|reply
Mine. From a long time ago, in a Galaxy far, far away.

    #python SQL injection paradise.
    sql = 'SELECT * FROM %s' % table
[+] kschua|13 years ago|reply
Java code

if (obj instanceof java.lang.Object)

[+] eduardordm|13 years ago|reply
First, your answer is why I almost never criticize people's code:

This is (was in Sun's time) an actual possible certification question and you are wrong, this CAN return false:

        Object obj = new Object() {{ System.out.println(false); System.exit(0); }};
        
        System.out.println(obj instanceof Object);
[+] codeonfire|13 years ago|reply
saw this a while back:

if (failed) { return SUCCESS; }