delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/10/19/18:34:31

From: "Traveler" <traveler AT netti DOT fi>
Newsgroups: comp.lang.c++,comp.os.msdos.djgpp
Subject: Re: Making C++ little easier to beginners...
Date: Sat, 20 Oct 2001 01:27:56 +0300
Organization: SAUNALAHDEN asiakas
Lines: 195
Message-ID: <9qq97t$2df$1@tron.sci.fi>
References: <9qmkrh$581$1 AT tron DOT sci DOT fi>
NNTP-Posting-Host: mmmcmxcvii.hdyn.saunalahti.fi
Mime-Version: 1.0
X-Trace: tron.sci.fi 1003530302 2479 195.197.165.97 (19 Oct 2001 22:25:02 GMT)
X-Complaints-To: newsmaster AT saunalahti DOT fi
NNTP-Posting-Date: 19 Oct 2001 22:25:02 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id f9JMU3F13449
Reply-To: djgpp AT delorie DOT com

Let me make few things clear:
 
1)    I apologize the trouble that my typo "if(x == 10 && x == 10)" has caused (What we learn from this ? Never, ever send a message when you are tired ).
        Of course the last part should be "y == 10" and some of those with the sharp eye noticed it from the 
following text.
2)    Lot of criticism was that my little helper was not "correct" C/C++.
        Where is it said that the things I made were illegal ?
        Is it so that the so called "O mighty" standard of C++ prevents me to write this kind of code ?
        I dont thinks so...
        Also there were few of those that said these things made code look like COBOL. 
        So what !!!!????
        If you like the things that I sometimes offer then use it, if not then dont use it ! Itīs as easy as that !
        What I do is to offer ALTERNATIVES. Everybody should understand that even if there is a ready made             standard for something they don't need to follow it slavishly (And that is what you are doing when you say         something like "This code is wrong and non-standard. Donīt use it")
3)    Ray Fischer, you writed:
    "Where I work we're are complete uninterested in making C++ easier
    for beginners.  We don't hire beginners.  Your plan is as daft as
    proposing that knives be dulled to protect beginners."
 
    Well, that was a very encouraging !
    Frankly, I don't care where you work or what kind of projects you currently do.
    It keeps me wondering why you even cared to read my original message after reading the title of it ???
 
You also wrote:
"Well guess what:  "Boolean algebra" books don't count.  Not in the slightest.
What does count is the C++ standard.  When you learn something about C++ and
programming you'll realize as much yourself."

Take a look at the following part and think again...also read the part 2 again
 
BTW, German philosopher's have been out of style for a while...
 
4)    "Arnold Hendriks" wrote:
"logical AND/OR and bit AND/OR.
2 & 1 == 0      (evaluates to false)
2 AND 1 == 0    (your AND #define)
2 && 1 == true
 
Logical and bitwise AND/OR cannot be considered equivalent. You 
should reread or burn your book."
 
Yes, you are right about that but take a look at the following:
 
bool    a = false,
            b = false,
            c;
 
cout << "AND\n";
cout << "a\t0\t0\t1\t1\n";
cout << "b\t0\t0\t1\t1\n";
cout << "c\t" << (a & b);
b = true;
cout << '\t' << (a & b);
a = true;b = false;
cout << '\t' << (a & b);
b = true;
cout << '\t' << (a & b) << endl;
 
Result should be:
AND
a    0    0    1    1
b    0    1    0    1
c    0    0    0    1    
 
So the 'c' is true only when both 'a' & 'b' are true. Correct...
 
Now, change the '&&' for every '&'
 
Result is:
AND
a    0    0    1    1
b    0    1    0    1
c    0    0    0    1    

Exactly the same result. So in the light of this example '&' and '&&' are identical. So you can use both in 'if ' statements.
In bit manipulation you should use '&' and thatīs why I have made my 'AND' with '&' :) (It can handle both things)
 
However, DJ Delorie has an explanation why your example gives different results:
 
"The difference is whether the individual bits of the value are handled
independently, or if the whole value is treated as a single boolean
(zero vs non-zero). "

Thanks Delorie !
Itīs all much clearer now.

5)    Dietmar Kuehl wrote:

"Nope, you cannot:
 
  if (ptr == 0 || ptr->something())
    ;
 
will work correctly when being passed a corresponding null pointer while
 
  if (ptr == 0 | ptr->something())
    ;
"
 
Strange...it did not crash in my maschine....
 
class    A
{
public:
    int    something()const {return -1;}
};
 
A*    ptr = NULL;
if(ptr == 0 | ptr->something())
    cout << "Hello\n";
 
 
Speaking of "==" operator I remember time when I made an quite a big program. It worked quite well for a while but then it suddenly crashed. Let me tell you, I had a Hellish time trying to find the error from source.
Finally I found one part reading: "if(tmp = length)".
I have forgotten one  '='.
So, the 'if' statement was always true because what happened here was an assignment instead of comparing. With "if(tmp EQUAL length)" this would have never happened.
 
6)    And last but not least:
    "Hans-Bernhard Broeker" you replied to some of my message:
" 
> Yes, your right ! I shouldn't use C. I use C++ instead :)
 
Which doesn't change the issue in the slightest way --- C++ is exactly
the same as C, in this regard."
 
This shows that you don't understand sarcasm...
And then you reply....
 
" 
> Case is close...
 
If any thing is closed, that would be your view of the world,
shielding you from the apparently shocking perspective of learning
something new, once in a while.
 
Go away, troll.
"
 
You have an bad attitude problem...well of course itīs not my problem where you have get it (from childhood ? 
No matter...)
 
In the matter of fact, when I sometimes read the answers to my questions I recall that you have a replies that contain a very little of "meat" in it.  You have very little (nothing ?) to say...
You haven't even tried to offer improvement suggestion like others have...all that you do is an attempt to make ideas of the others ridiculous....I feel sorry for you.
 
Consider the following:
-    Does the things that I made make your program bigger ? No.
-    Does the things that I made make your program slower ? No.
-    Does the things that I made make your code easier to read ?    Hell, yes !
-    Is this "illegal" way of doing things ?         That depends on what you think is illegal...if you are a hardcore standard fanatic...meaning that everything that is not in the standard is not allowed...then this is illegal to you. To me, this is just one alternative way of doing things...
-    Are there any errors in this stuff ?    Yes, one. There indeed is a difference between logical "AND/OR" and their bit brothers.
 
Lastly I want to thank the following persons. Your replies were very informative and interesting (particularly Dietmarīs message):
 
Dietmar Kuehl    (have you done assembly programming ? Just asking....)
Jeremy Yallop        
 
"Traveler2001AD"
        


- Raw text -


  webmaster     delorie software   privacy  
  Copyright Đ 2019   by DJ Delorie     Updated Jul 2019