Live data from Hacker News

Ifs and &&s and Plan 9's Source Code

computationallyendowed.com

1–10 of 150 posts

Re: Ifs and &&s and Plan 9's Source Code

#4
This also provides an advantage when debugging. It will become immediately obvious which condition fails when stepping through the code. That isn't always the case with a long string of &&s.

Re: Ifs and &&s and Plan 9's Source Code

#5
If not for the need to get and later free the

    Dir *b;
, and print the message, this condition would get a lot simpler. I'd find it more readable to write a function

    bool samefile(Dir *a, Dir *b)
, have it consist of a single-line return statement, and then have the caller just do if (samefile(a, b)) { ... }.

Re: Ifs and &&s and Plan 9's Source Code

#6

C++ has "and"/"or"/"not" etc., so you can do if(not A and B) but I'm not sure I've ever seen anyone do it. http://en.cppreference.com/w/cpp/language/operator_alternati... To get them in C, see the note about iso646.h in the link.

I don't think it really improves readability. All the programmers are familiar with && and ||, and using something else will just confuse people.

Also, it's not really that hard to #define it yourself, instead of using includes.

Re: Ifs and &&s and Plan 9's Source Code

#8

C++ has "and"/"or"/"not" etc., so you can do if(not A and B) but I'm not sure I've ever seen anyone do it. http://en.cppreference.com/w/cpp/language/operator_alternati... To get them in C, see the note about iso646.h in the link.

I don't think it really improves readability. All the programmers are familiar with && and ||, and using something else will just confuse people. Also, it's not really that hard to #define it yourself, instead of using includes.

I definitely wouldn't use them because they are unfamiliar. However, in my head I pronounce "&&" as "and" and "&" as "bitand", so using and/bitand over &&/& would reduce a depressingly not-uncommon typo for me. However, on balance, not worth it to me.

Note that in C++ they are keywords which is superior to macros.

Post reply on HN