Steve Lacey. Get yours at flagrantdisregard.com/flickr

Who Knew?

| | Comments (1) | TrackBacks (0)

Today I discovered that C++ standard defines support for using ‘and’ in place of ‘&&’, ‘or’ instead of ‘||’, ‘bitand’ for ‘&’ and a few others. Who knew?

I must say that I’m not particularly sold on the idea - it makes code kinda unreadable. Consider the following code snippets which are equivalent:

if ((num_things and (num_other_things > 0)) or is_one_more_thing)
{
    DoBlah();
}

if ((num_things && (num_other_things > 0)) || is_one_more_thing)
{
    DoBlah();
}

Personally, I think the second is more readable as the logical operators break up the alphanumeric expressions - the problem could get really bad with complex expressions and highly readable variable names.

But maybe it’s just me…

0 TrackBacks

Listed below are links to blogs that reference this entry: Who Knew?.

TrackBack URL for this entry: http://www.steve-lacey.com/cgi-bin/mt/mt-bar.cgi/904

1 Comments

kim said:

I agree with you. Also could lead to 'accidental slippage' into reading context in the wrong way.

If one read something like "If FEET and INCHES...", they might assume "and" meant addition. Rather the context might be "if this thing has any size at all, then...

Kind of reminds me of when programmers first discover operator overloading. There's a short period of temptation to coerce the language into some very funky but dangerous behavior! :-)
K

Leave a comment

About Me

Steve Lacey, software developer at Google, British, married to the lurvely Nabila, dad to the wonderful Julian and Jasmine. Living in Kirkland (near Seattle), WA.


A brief professional bio.


steve@steve-lacey.com
+1 425 466 9305

About this Entry

This page contains a single entry by Steve published on October 20, 2006 9:05 PM.

Roundup was the previous entry in this blog.

Should Kids Get A Vote By Proxy? is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Statsorama

  • 1004 posts
  • 1160 comments

Music