not the first or last. the middle maybe a bit, but I don't think it would be that hard to parse out a math expression and simplify/optimize the expression (ie (1+2)+3 -> 1+2+3 -> 6). I'm actually doing something similar in python at the moment.
Err, no. Middle is hard. That was only the example. Other exampes:
list<int> data((istream_iterator<int>(dataFile)), istream_iterator<int>0);
Second set of braces is not redundand, as removing it will change program meaning.
But there it is redundand: void print((ostream_iterator<int>(data, ", ")));
Braces around a && (b && c) might or might not change the meaning depending on operator&& overloads.
Is that set of braces redundand or not:
1 2 3 4 5 6 7 8 9
int func()
{
foo x;
{ //←——
bar y;
//...
} //←——
//...
}
+x might or might not change program behavior. Only realistic way to implement that is to check if removing particular token changes program AST. You would need IDE deeply integrated with compiler like Eclipse/Java
The best solution I've found is to take a chill pill and not worry about it. The danger of removing a token (or 700) that changes the meaning of the program is far too high. Do you really want to have this conversation:
Boss: Helios!! What the hell happened to the code, it's broken
You: I ran a program to beautify it. Trust me, it's better now.
Boss: Better?!?!? Since when is broken "better"????
You: Umm...
If a particular style really offends you. change it with an editor by hand, after examining each case individually.
This is just to improve the output of a code generator. To make the generator simpler, braces and parentheses are added generously. This ensures correct programs, but makes eyeball inspection more difficult.
Obviously, manual simplification is pointless in generated code.
If manually fixing it is pointless, why is automatically fixing it not pointless? If you're willing to fix it in the first place, why not adjust the generator?
But if it's automatically generated code then why care about the parens and braces? Why look at the generated code at all (except perhaps in a debugger)? Isn't this sort of like beautifying the assembly that the C++ compiler can generate?