My brain has easier time if it compares a variable with a constant (meaning
the constant is on the right side of the operator) than other way around.
I have come across many programmers that do this than compare a constant
with a variable.

I always thought that programmers doing the "constant on left" are just
trying to trick me! :-) Kidding aside what benefits does it have other than
compiler having an easier time detecting your mistakes?

Regards, Malahal.

On Thu, Jun 29, 2017 at 6:42 AM, William Allen Simpson <
william.allen.simp...@gmail.com> wrote:

> On 6/28/17 8:41 PM, William Allen Simpson wrote:
>
>> This is a good programming practice of long-standing value.
>>
>> Why of why do these evil commit tests keep creeping in?
>>
>> bill@simpson91:~/rdma/nfs-ganesha$ git commit --amend -a
>> WARNING: Comparisons should place the constant on the right side of the
>> test
>> #17: FILE: src/MainNFSD/nfs_rpc_dispatcher_thread.c:1777:
>> +    if (XPRT_DONE <= stat) {
>>
>>
> Yep, it's another Joe Perches idiocy.  The bane of programmers since he
> changed all the if && || tests in 2009 in the Linux network stack to
> trailing form.  He tried to put that into checkpatch, and there was a
> general uprising -- as there's a lot in kernel NFS code.
>
> Thousands of annoying changes that made it impossible to rebase.
>
> Because of course this is so much more readable:
>
> if (something
> #ifdef TEST
>               &&
>     morestuff
> #endif
>     ) {
>
>
> I've been teaching leading constants in C for almost 40 years.  Leading
> constants are preferred in many cases, not least because they yield
> better compiler error warnings and better code readability.
>
> As do leading && || ....
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Nfs-ganesha-devel mailing list
> Nfs-ganesha-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nfs-ganesha-devel
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Nfs-ganesha-devel mailing list
Nfs-ganesha-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs-ganesha-devel

Reply via email to