News for hackers. Stuff that matters.
Re:Ask HN: what is the most stupid line of code you saw? by fzfzqfz on Wednesday February 20, 2013 @06:23AM (#5249853)
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.

Re:Ask HN: what is the most stupid line of code you saw? by krapp on Wednesday February 20, 2013 @10:35AM (#5250964)
I've seen this done with SQL queries all the time but... ouch.
Re:Ask HN: what is the most stupid line of code you saw? by pyfap on Tuesday February 19, 2013 @10:36PM (#5248794)
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.
Re:Ask HN: what is the most stupid line of code you saw? by tdubbed on Tuesday February 19, 2013 @11:19PM (#5248915)
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

Re:Ask HN: what is the most stupid line of code you saw? by eb0la on Wednesday February 20, 2013 @08:05AM (#5250179)
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.
Re:Ask HN: what is the most stupid line of code you saw? by DanielN on Wednesday February 20, 2013 @10:47PM (#5255246)
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.
Re:Ask HN: what is the most stupid line of code you saw? by whalesalad on Tuesday February 19, 2013 @08:54PM (#5248483)
I do that sometimes during debugging. It stands out and I know to change it later. If 1 == 0, etc...
Re:Ask HN: what is the most stupid line of code you saw? by krapp on Tuesday February 19, 2013 @11:38PM (#5248992)

   <?php /* Start the Loop */ ?>
Followed by more php.
Re:Ask HN: what is the most stupid line of code you saw? by dangrossman on Wednesday February 20, 2013 @01:50AM (#5249309)
That's not bad code, it's just WordPress lingo you're unfamiliar with. http://codex.wordpress.org/The_Loop
Re:Ask HN: what is the most stupid line of code you saw? by krapp on Wednesday February 20, 2013 @10:33AM (#5250934)
I wish I were unfamiliar with it....

I think it is bad practice at least then, if not explicitly bad code, because it's needlessly overcomplicated. Why use the end tag when you're not switching contexts between php and html? After this line there's just another open tag and more code... it's a pointless way of writing php that makes it aggravating to read and edit.

Re:Ask HN: what is the most stupid line of code you saw? by vsync on Wednesday February 20, 2013 @05:51AM (#5249781)
> That's not bad code, it's just WordPress

Contradiction.

Re:Ask HN: what is the most stupid line of code you saw? by chrisdevereux on Thursday February 21, 2013 @12:06AM (#5255515)
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
  };
Re:Ask HN: what is the most stupid line of code you saw? by AbhishekBiswal on Saturday February 23, 2013 @03:31AM (#5269015)
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

Re:Ask HN: what is the most stupid line of code you saw? by orangethirty on Wednesday February 20, 2013 @12:11AM (#5249088)
Mine. From a long time ago, in a Galaxy far, far away.

    #python SQL injection paradise.
    sql = 'SELECT * FROM %s' % table
Re:Ask HN: what is the most stupid line of code you saw? by kschua on Tuesday February 19, 2013 @11:06PM (#5248871)
Java code

if (obj instanceof java.lang.Object)

Re:Ask HN: what is the most stupid line of code you saw? by eduardordm on Wednesday February 20, 2013 @07:52PM (#5254588)
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);
Re:Ask HN: what is the most stupid line of code you saw? by _yields on Wednesday February 20, 2013 @04:38AM (#5249621)
ha! this is gold
Re:Ask HN: what is the most stupid line of code you saw? by codeonfire on Wednesday February 20, 2013 @11:03PM (#5255290)
saw this a while back:

if (failed) { return SUCCESS; }

Re:Ask HN: what is the most stupid line of code you saw? by graycat on Sunday February 24, 2013 @03:59PM (#5275888)
i = j+++++k