Monday, January 5, 2026

Keep Code Clean 2

Make Assignment Operator a cleaner way using this method

if A = 'positive' then
{
    num = 1 + 1;
    num2 = 2 - 2;
    num3 = 2 - 2 + 3;
}
else
{
    num = 1 - 1;
    num2 = 2 + 2;
    num3 = 2 + 2 - 3;
}

At least 8-12 lines of codes including braces

You can write this way below to achieve the same result!

int adjustment = A == 'position' ? 1 : -1;
num = 1 + (1 * adjustment);
num2 = 2 - (2 * adjustment);
num3 = 2 + (2 * adjustment) - (3 * adjustment);

4 lines of code only :D