From: dietmar_kuehl AT yahoo DOT com (Dietmar Kuehl) Newsgroups: comp.lang.c++,comp.os.msdos.djgpp Subject: Re: Making C++ little easier to beginners... Date: 19 Oct 2001 04:33:57 -0700 Organization: http://groups.google.com/ Lines: 85 Message-ID: <5b15f8fd.0110190333.616e0908@posting.google.com> References: <9qmkrh$581$1 AT tron DOT sci DOT fi> NNTP-Posting-Host: 212.149.48.44 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1003491237 12033 127.0.0.1 (19 Oct 2001 11:33:57 GMT) X-Complaints-To: groups-abuse AT google DOT com NNTP-Posting-Date: 19 Oct 2001 11:33:57 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hi, "Traveler" wrote: > int x = 10, > y = 10; > > if(x == 10 && x == 10) // Does this look scary or weird > to you ? It looks wrong because you are doing the same comparison twice. > wouldn?t this be nicer ? > if(x EQUAL 10 AND y EQUAL 10) You would probably confuse many experienced C++ programmers with this because they are used to specific idioms and these "keywords" are non of those. It is correct that a newcome might indeed consider these to be easier but then, the typical computer notation is not that far off from typical mathematical notation. > #define AND & > #define EQUAL == > As you can see the things "AND" & "OR" defined here are "bit" operators > not "logical" operators. > However, there really is no difference becourse you can use these two > just as easily in "if" statement?s as in bit manipulation. Nope, you cannot: if (ptr == 0 || ptr->something()) ; will work correctly when being passed a corresponding null pointer while if (ptr == 0 | ptr->something()) ; will not: It will "crash" (ie. invoke "undefined behavior") when applying the '->' operator. > All calculations done in computer, from the simplest addition to the > most complex 3rd grade (or greater) root solving uses these operator?s > and their compinations inside the microprocessor. This set of operations is enriched by additional operations like "jumps" which conditionally transfer operation to a different position. The logical operator are basically equivalent to multiple 'if' statements: if (cond1 && cond2) action(); is equivalent to if (cond1) if (cond2) action(); Likewise, if (cond1 || cond2) action(); is equivalent to if (cond1) action(); else if (cond2) action(); (don't take this equivalence to literally: to deal correctly with "else" branches, things become pretty fast pretty ugly). The semantics of the corresponding bitwise operations do not involve anything like this. In general, you should follow the idioms used in a specific language, be it a programming language or a natural language: You will have a hard time to transfer idioms from one language to another like "he is heavy on wire" is completely meaningless in English because it is just a literal translation of a German idiom ("Er ist schwer auf Draht"; it was more in fashion a few years back). Although it may be easy to use literal translations (actually, I can't come up with a good English idiom although I'm sure there is one) these don't make sense. The same applies to computer languages! -- Phaidros eaSE - Easy Software Engineering: