Martin von Zweigbergk <> writes:

> I was recently confused by the yoda condition in this block of code from [1]
> + for (i = 0; i <; i++)
> + if (&bases->item->object == &revs.commit[i]->object)
> + break; /* found */
> + if ( <= i)
> I think I was particularly surprised because it came so soon after the
> "i <". I didn't bother commenting because it seemed too
> subjective and the code base has tons of these.

That follows "visual/textual order should follow the actual
ordering" principle.  Think of a number-line you learn in elementary
school arithmetic class, and try to place and i on it.

I agree that there is no justification to write "if 0 == something",
when "if something == 0" suffices.  The latter reads better and that
is why the phrase "yoda condition" was invented.

But the situation is different when both sides are not constants,
and especially when "<" and "<=" are involved..
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to