views:

862

answers:

7
+4  Q: 

Ugly C++ code

I'm working on a C++ prettyprinter and would like to show the results of the prettyprinter by comparing code before and after running it. Does anyone know where I can find some ugly C++ code to run through the prettypretty? Ideally the code would come from some open source software.

+4  A: 

Try doing a search for 'C++ obfuscation' and you should be able to find C++ code that is hard to read.

BoltBait
+2  A: 

Another good test is to take normal C++ code and see how well it can reformat it to a different code formatting standard.

Ferruccio
+2  A: 

Not C++ but have you checked out The International Obfuscated C Code Contest?

Check out some of the winners code

John Nolan
+2  A: 

Here is a list of bugs filed against the eclipse C/C++ tools project. Many of the bugs are about code that wasn't formatted correctly, so you can see how they did things and even look at the fixes if they are resolved.

AdamC
+5  A: 

If you can't find a good corpus of ugly code, you could always write a "code uglifier" and then run it on some average code.

For example:

  • Remove all insignificant spaces
  • Remove/Insert random spaces
  • Replaces tabs with different number of spaces.
Tim Stewart
+1 for "code uglifier" :P
Davy8
+5  A: 

Anything coded to the GNU coding standards will give you a shitty indentation style to practise on. Verbatim example:

 if (x < foo (y, z))
   haha = bar[4] + 5;
 else
   {
     while (z)
       {
         haha += foo (z, z);
         z--;
       }
     return ++x + bar ();
   }
fizzer
Wait...WTF is that? That's probably the worst coding standard ever.
Thomas Owens
That's just emacs default style.
Paul Nathan
+1  A: 

Your prettyprinter is presumably configurable? Then it will be able to generate ugly code for suitable inputs.

fizzer