Чудеснов
молодой динамично развивающийся

Other People’s Code

These aren’t RULES or anything. It’s just my own annoyances when looking at other people’s code.

Functions

NO THANKS:

void DoSomething(){
DoSomethingElse();
}

YES PLEASE:

void DoSomething()
{
DoSomethingElse();
}

NO THANKS:

void DoSomething()
{
if ( !m_something )
DoThisFirst();
DoSomethingElse();
}

YES PLEASE:

void DoSomething()
{
if ( !m_something )
DoThisFirst();

DoSomethingElse();
}

NO THANKS:

void DoSomething(int x,int y,bool b)
{
DoSomethingElse(x,y,b);
}

YES PLEASE:

void DoSomething( int x, int y, bool b )
{
DoSomethingElse( x, y, b );
}

Return Nesting

NO THANKS:

void DoSomething( int x, int y, bool b )
{
if ( x > 10 )
{
x = x - 10;
y = y + y;
DoSomethingElse( x, y, b );
}
}

YES PLEASE:

void DoSomething( int x, int y, bool b )
{
if ( x <= 10 ) return;

x = x - 10;
y = y + y;
DoSomethingElse( x, y, b );
}

Inline Coder

Are you in inline coder? Do you manually write out the same bits of logic over and over again?

NO THANKS:

if ( amount > 1 ) amount = 1;
else if ( amount < 0 ) amount = 0;

YES PLEASE:

amount = Clamp( amount, 0, 1 );

NO THANKS:

if ( amount < 100 )
{
amount += 12;
if ( amount > 100 ) amount = 100;
}
else if ( amount > 0 )
{
amount -= 12;
if ( amount < 100 ) amount = 100;
}

YES PLEASE:

amount = Approach( amount, 100, 12 );