jeudi 12 août 2021

Is 'if statement' with negation more readable than the straight one? [closed]

During Merge Request, often my colleagues ask me to change such a code:

for (int i = 0; i < 10; i++)
{
    if (SomeMethod())
    {
        // do some logic...
    }
}

into such a code:

for (int i = 0; i < 10; i++)
{
    if (SomeMethod() == false)
    {
        continue;
    }

    // do some logic...
}

Their argument is that this is more readable... but for me this is less readable.

For me this is one useless step in reasoning:

if something is not true 
then continue
otherwise do some logic

instead:

if something is true
then do some logic

which is for me more readable. But how I should discuss this with my colleagues? Does anybody have opinion or better - may someone point to some informations provided by cognitive science?

Aucun commentaire:

Enregistrer un commentaire