Test prettyprinter with poorly formatted C++ code [closed]
Asked Answered
A

8

5

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.

Arrivederci answered 22/10, 2008 at 17:49 Comment(2)
There's pretty C++ code? I'd consider any C++ code ugly ;-) SCNRMoll
Why are you working on a prettyprinter if you can't find some ugly code? :)Spiers
U
11

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 ();
   }
Unalloyed answered 22/10, 2008 at 19:14 Comment(3)
Wait...WTF is that? That's probably the worst coding standard ever.Pedersen
That's just emacs default style.Grabble
@Thomas: It looks ugly at first, but after a while it becomes much easier to read, especially if you do a lot of lisp programming.Coroner
S
7

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.
Saeger answered 22/10, 2008 at 18:59 Comment(0)
R
5

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

Ribbonwood answered 22/10, 2008 at 17:53 Comment(0)
W
2

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

Wennerholn answered 22/10, 2008 at 17:58 Comment(0)
I
2

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

Check out some of the winners code

Ietta answered 22/10, 2008 at 18:1 Comment(0)
B
2

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.

Blackberry answered 22/10, 2008 at 18:4 Comment(0)
U
1

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

Unalloyed answered 22/10, 2008 at 20:22 Comment(0)
B
0

Look at "golfed" C++ programs on the Code Golf Stack Exchange site. They are uglified in order to save space.

Ballyrag answered 1/10, 2011 at 23:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.