2006-08-14

and or not

I was looking at some of my code the other day with a co-worker. He noticed that I wasn't using the && or || operators and rarely the ! operator. Instead I was using "and," "or," and "not."

I pointed out that I find them much clearer and easier to understand. Since programming for clarity is one of my top goals, it is a no brainer for me to use English words in place of more cryptic symbols.

He agreed and asked what header he had to include to use this symbols and was surpised when I told him that no header is needed. These are not gasp! macros. All of these are reserved words and part of the core language for Standard C++.

You can start using this words right now. And I encourage you to do so.

2 comments:

Blogger Sumant said...

You might compromise portability of your code. But again, you can add a custom header that defines them for compilers that have no knowledge of "and" like keywords.

4:39 PM  
Blogger Russell said...

I strongly disagree. Anybody who knows C or C++ reads "&&" or "||" with ease. It's a fundamental part of the language. Virtually nobody uses "and". For 99% of the people reading your code, when they see "and" or "or", it'll stop them cold and they'll waste time asking "is that part of the language? What does it do -- does it guarantee sequencing like '&&'?" The diligent or paranoid will go look it up, and in any case it will slow them down greatly.

In short, it is an exercise of personal preference; it will not make your code clearer or easier to read by others.

8:37 AM  

Post a Comment

links to this post:

Create a Link

<< home