"Dennis Yurichev" <De*************@gmail.comwrote in message
news:11**********************@r56g2000hsd.googlegr oups.com...
Hi.
How can I find some ready tool or how can I find a proper way to
develope tool which will convert such code:
if (a>b+2+2)
{
f1();
f2(a*3*2);
} else
{
f1();
f3(a);
}
To something like that:
f1();
if (a>b+4)
f2(a*6)
else
f3(a);
In another words, this is what is done by modern compiler at
optimization phase, right? But I need to have C-source at the input
and C-source at the output.
Could please anyone point me to any ideas or ready works.
The first refactoring makes sene, moving f1() out of the if...else bodies
into mainline.
Changing b+2+2 to b+4 and a*3*2 to a*6 may or may not make sense.depending
on what those magic numbers mean. That is, b+2+2 may be clearer what is
going on than b+4. Better yet would make them: b+Rows+Space or whatever
those 2's meant. Without context it's impossible to tell, which is why
magic numbers are generally considered bad.
And a*3*2 maybe that means a 3x2 array? I don't know. They are magic
numbers. Better would be to track down the magic numbers and fix them.
But, hey, I think most of us are guilty of using magic numbers.
Looking at some of my own code at random I come across:
JVEC3 BitToRight = jGet_Position_Around_Center(
Client.Camera.X_Degrees - 90, 0.050f, -0.012f, Client.Camera.Position );
JVEC3 TempPosition = jGet_Position_Around_Center(
Client.Camera.Y_Degrees , 0.175f, -0.0f, jVec3(BitToRight.y, 0.0f, 0.0f));
BitToRight.y = TempPosition.x;
Client.RightGunPosition = jGet_Position_Around_Center(
Client.Camera.X_Degrees < 180.0f ? Client.Camera.X_Degrees + 180.0f :
Client.Camera.X_Degrees - 180.0f, cos(Client.Camera.Y_Degrees * radindeg) *
0.18f, -0.0f, BitToRight);
with the magic numbers 90, 0.050f, -0.012f, 0.175f, -0.0 (negative none the
less O.o), 180.0f 0.18f
Now the problem becomes, when I want to maintain this code, I have to figure
out what all those numbers mean. Which means I"m going to have to look up
the function calls themselves and see what their parameters are.
Just be careful when working with magic numbers.