Re: [PATCH] Change "refs/" references to symbolic constants

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 2007 February 20 11:37, Johannes Schindelin wrote:

> Actually, it's not even ternary, but to the return value should only be
> handled in terms of >0, ==0, <0.

Apologies, I'm not using ternary in the sense of the number 0, 1 and 2; I'm 
using it in the sense of there being three possible outcomes - which there 
are.  This is similar to how operators are categorised into unary, binary and 
ternary categories.  I use ternary to mean "having three states or elements", 
rather than "having the value 0, 1 or 2".

> Ah, and if "!" implies a boolean, then why is "!!" a common construct?
> Because "!" really does not imply a boolean.

Boolean expressions are those that have two possible states - "true" 
or "false".  There are no real booleans in C, so they are faked.  The two 
boolean states in C are represented by

 False = Equal to zero
 True = Not equal to zero

Now, the !! construction you suggest is perfectly in keeping with this 
definition.  Ironically, the only reason you need the !! construction is 
because of this integer-as-boolean trait of C.

So, to get a boolean in C you use a standard integer (say).  My contention is 
that to improve clarity you should not mix integer-as-boolean and 
integer-as-integer, even though C will accept it when you do.

 i = 10;
 while( i )
   i--;

This is bad, it abuses the fact that C will let you treat an integer as a 
boolean.  while() takes a boolean expression as it's argument, so I think 
that you should always hand it something that would be a boolean output (even 
though C doesn't care if you don't).

 i = 10;
 while( i > 0 )
  i--;

This makes it clear to the reader that i is not boolean.  Obviously this is a 
trivial example; no one would have any trouble understanding either of the 
two examples.  When things start to get bigger and more complicated though, 
more clarity is always better than less clarity.  The principle I try to 
follow is that code is write-once-read-many.  If you save yourself two 
keystrokes at the expense of the clarity you gain for the 100 times you read 
that code, then you have made a false economy.

In the end - I don't care - I was only countering Junio's "I prefer !strcmp", 
with my reasons why I don't like it.  I do not expect git to change to my 
preferred coding style, and I do try to keep to the coding style that the git 
project uses.  To my mind, inconsistency is a worse offence than anything 
else in a project, so it's always better to go with what is established.



Andy

-- 
Dr Andy Parkins, M Eng (hons), MIEE
andyparkins@xxxxxxxxx
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]