On Nov 19, 2007 2:00 PM, Aaron Griffin <aaronmgriffin@gmail.com> wrote:
On Nov 19, 2007 12:59 PM, Dan McGee <dpmcgee@gmail.com> wrote:
On Nov 19, 2007 12:34 PM, Xavier <shiningxc@gmail.com> wrote:
On Mon, Nov 19, 2007 at 12:13:14PM -0600, Aaron Griffin wrote:
On Nov 18, 2007 8:06 PM, Dan McGee <dpmcgee@gmail.com> wrote:
== 0 is much clearer, so I'm going to change this back if I pull the patch. Let's not take shortcuts in C just because they work- lets make the code readable for everyone. It will all get compiled the same way anyway. As a general rule, I always want to see an == or != used with strcmp- it is just easier to digest.
This is also in the pacman coding guidelines somewhere, for the record.
Thank you for bringing this up again, I already forgot. That's exactly what I wanted to say : if patches are going to be rejected for a code style reason, then all these reasons should be written somewhere. I don't see what other places to look at, all other coding guidelines are in HACKING, and I can't find any mention of strcmp.
Also, this rule only applies to strcmp? Because it returns 0 in case of success? And I just grepped the source for strcmp, it seems like it isn't used with == or != in the majority of the cases. Even though there are also many cases where it is.
Note that I don't have any problem with coding guidelines, as long as they are clear and written. I'm all for a consistent style.
OK, I will put this on my TODO list and get it into the GIT repo- I think it makes more sense and we can all refer to it there. I will also add some of these "unwritten rules". I'll even post it here first to see if their are any objections.
I thought there was a better version of this somewhere.
Either way, the pseudo-rule was something to the effect of:
if(!strcmp(a,b)) { /* success case */ }
This is bad because it just doesn't read right. You're using a negative to check for a success case. The compiler is going to do the same thing regardless, so why not make this readable:
if(strcmp(a,b) == 0) { /* success case */ }
Dan, feel free to disagree with me on this one
Dude, you quoted me agreeing, thats how the whole debate started. :)
On Nov 18, 2007 8:06 PM, Dan McGee <dpmcgee@gmail.com> wrote:
== 0 is much clearer, so I'm going to change this back if I pull the patch. Let's not take shortcuts in C just because they work- lets make the code readable for everyone. It will all get compiled the same way anyway. As a general rule, I always want to see an == or != used with strcmp- it is just easier to digest.
-Dan