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.
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 ();
}
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.
Try doing a search for 'C++ obfuscation' and you should be able to find C++ code that is hard to read.
Another good test is to take normal C++ code and see how well it can reformat it to a different code formatting standard.
Not C++ but have you checked out The International Obfuscated C Code Contest?
Check out some of the winners code
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.
Your prettyprinter is presumably configurable? Then it will be able to generate ugly code for suitable inputs.
Look at "golfed" C++ programs on the Code Golf Stack Exchange site. They are uglified in order to save space.
© 2022 - 2024 — McMap. All rights reserved.