Re: [PATCH 16/16] add: avoid yoda conditions
- From
Felipe Contreras <felipe.contreras@gmail.com>
- Date
- Oct 31, 2013, 20:42 UTC
- Message-ID
- <CAMP44s3CnoLAUu=R4FCFWGyJpn58oTZgzQKgF7wE1hUnutv84w@mail.gmail.com>
- In-Reply-To
- <xmqqmwlp41xd.fsf@gitster.dls.corp.google.com>
On Thu, Oct 31, 2013 at 2:31 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
> 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 me revs.nr is virtually a constant, I'm comparing i to revs.nr, not the other way around.
I believe I explained this already, but here it goes again:
if (1.60 < john.size)
This makes no sense, "if 1.69 is smaller than john"?
The situation doesn't change when you use a variable:
if (size_limit < john.size)
Translates to "if size limit is smaller than john", and still makes no sense.
-- Felipe Contreras