Discussion:
= operator overloaded in VB6 or VB.NET
(too old to reply)
John Davis
2003-07-16 01:08:42 UTC
Permalink
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.

Case 1: relational operator. In other languages, usually use == instead.
If a = b Then statement

Case 2: assignment operator
a = b

Just my observation. Please discuss.
Herfried K. Wagner
2003-07-16 01:22:52 UTC
Permalink
Hello,
Post by John Davis
One interesting observation I found is VB6 or
VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
That's right. It's one of the main reasons why I use VB Classic/VB
.NET.

Notice that an X-post to microsoft.public.vb.controls doesn't make any
sense.

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Vincent Wiegel
2003-07-16 01:47:13 UTC
Permalink
huh??
Post by John Davis
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
Case 1: relational operator. In other languages, usually use == instead.
If a = b Then statement
Case 2: assignment operator
a = b
Just my observation. Please discuss.
Tom Esh
2003-07-16 02:48:12 UTC
Permalink
On Tue, 15 Jul 2003 18:08:42 -0700, "John Davis"
Post by John Davis
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
...
I too thought it odd at first, but with VB I've never spent hours
debugging only to find the cause to be a some difficult-to-spot
transposition of the two. IMO it's a lot easier to see the contextual
difference. Besides, you can't verbalize "==" without stuttering. <g>


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Jeff Johnson [MVP: VB]
2003-07-16 03:29:37 UTC
Permalink
Post by John Davis
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
For reference, from the very beginnings of BASIC the = operator has
performed double-duty, although in the Bad Old Days, the Let statement was
required (ick!) for assignments. Fortunately that went away quickly.

(Not that this has anything to do with controls, but I WILL admit that it IS
relevant to both .NET and non-.NET groups, a rarity there....)
steve
2003-07-16 05:12:03 UTC
Permalink
On Tue, 15 Jul 2003 23:29:37 -0400, "Jeff Johnson [MVP: VB]"
Post by Jeff Johnson [MVP: VB]
Post by John Davis
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
For reference, from the very beginnings of BASIC the = operator has
performed double-duty, although in the Bad Old Days, the Let statement was
required (ick!) for assignments. Fortunately that went away quickly.
(Not that this has anything to do with controls, but I WILL admit that it IS
relevant to both .NET and non-.NET groups, a rarity there....)
but probably not vb groups. Most vb developers would probably think
overloading meant pushing a program to hard <g>
Ken Halter
2003-07-16 14:39:49 UTC
Permalink
Post by steve
On Tue, 15 Jul 2003 23:29:37 -0400, "Jeff Johnson [MVP: VB]"
Post by Jeff Johnson [MVP: VB]
Post by John Davis
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
For reference, from the very beginnings of BASIC the = operator has
performed double-duty, although in the Bad Old Days, the Let statement was
required (ick!) for assignments. Fortunately that went away quickly.
(Not that this has anything to do with controls, but I WILL admit that it IS
relevant to both .NET and non-.NET groups, a rarity there....)
but probably not vb groups. Most vb developers would probably think
overloading meant pushing a program to hard <g>
hyuck hyuck... that was a belly roller there steve... I see John was able to spot the
obvious very quickly as well. Now if y'all could just keep this thread in relevant groups,
us VB Classic idiots would be much obliged.
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep it in the groups..
steve
2003-07-16 18:06:24 UTC
Permalink
On Wed, 16 Jul 2003 07:39:49 -0700, "Ken Halter"
Post by Ken Halter
Post by steve
On Tue, 15 Jul 2003 23:29:37 -0400, "Jeff Johnson [MVP: VB]"
Post by Jeff Johnson [MVP: VB]
Post by John Davis
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
For reference, from the very beginnings of BASIC the = operator has
performed double-duty, although in the Bad Old Days, the Let statement was
required (ick!) for assignments. Fortunately that went away quickly.
(Not that this has anything to do with controls, but I WILL admit that it IS
relevant to both .NET and non-.NET groups, a rarity there....)
but probably not vb groups. Most vb developers would probably think
overloading meant pushing a program to hard <g>
hyuck hyuck... that was a belly roller there steve... I see John was able to spot the
obvious very quickly as well. Now if y'all could just keep this thread in relevant groups,
us VB Classic idiots would be much obliged.
Sorry Ken, pretty lame attempt at humour I know but it sounded funny
to me at the time due to sleep deprivation.

:)
Tom Shelton
2003-07-15 19:43:49 UTC
Permalink
Post by Tom Esh
On Tue, 15 Jul 2003 18:08:42 -0700, "John Davis"
Post by John Davis
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
Case 1: relational operator. In other languages, usually use == instead.
If a = b Then statement
Case 2: assignment operator
a = b
Just my observation. Please discuss.
vb is pretty cool huh! == has always wound me up, leads to annoying
errors that don't show up when compiling and are often difficult to
track down when debugging. Its like the f puzzle. The brain doesn't
automatically distinguish == from = when looking at code because we
are used to just = in everyday life.
Not relavent in Java/C#. Compiler catches this because expressions in
if statements must evaluate to a boolean :)

Tom Shelton
Post by Tom Esh
But is this relevant in non dotnet groups?
Russ Bishop
2003-07-16 04:03:56 UTC
Permalink
a = b is short for Let a = b

If a = b is just what it implies - if a.equals(b) = true

The operator can do double duty because its use is non-ambiguous in either
situation. In other cases, + could be ambiguous, so the string concat
operator & was added to provide a non-ambiguous addition method for adding
strings together.

-- russ
Post by John Davis
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
Case 1: relational operator. In other languages, usually use == instead.
If a = b Then statement
Case 2: assignment operator
a = b
Just my observation. Please discuss.
Cor
2003-07-16 06:23:05 UTC
Permalink
John,
I don't know how many natural languages you speak, but for people who are
familiar with more languages, it is normal that in every language one word
can have more than one meaning.

The place of the word in the full sentence makes is very easy for the human
brain to understand the meaning for the meaning of the word. So that is
possible with the computer too.

Therefore I never understand why they made the ==, &&, || operators.

The "If" word says everything over the meaning and you can use the () if
there is a real problem.

I think the == and things like that are designed by mathematica people with
a very small knowledge natural languages.
A computer language is not anymore only a string of formules.
For that there was Algol and Fortran (And to say that that where languages
is the same as saying HTML and XML are languages).

What I don't understand is why the "then" is still necessary in VB.
But maybe is that for what Herfried says, "VB is so nice readable".

Cor
Cor
2003-07-16 08:49:43 UTC
Permalink
Hello Rainer,
I do not agree with you.

You speak more than one language. So that is not discussable. But lets bring
it back to natural language.

When you say: a is b you means a is equal to b.
Sometimes you mean a is the sum of a and b.
That is natural language.
I did not know that the sentence a=b=3 exist in VB and I agree that when it
is there it should give back a 1 and not an integer result of False or True

You speak German (me too but I cannot write it) and you know that you have
some words that don't exist in English. We can communicate in that
language.

An == operator is not necassery and I hate it in JavaScript that I often
use.
In VB you say.
If b=1 then
a = 1
b = a
end if
It is a nice sentence and you have to be very stupid not to understand it.

Of course we mis for years a=b=c=d and c++ --c but that will change in
future I supose.

When there would be an operator in this sentence I would choise for
a=b?b=c then we should use normal European 2500 years old characters quick
to understand to everybody that knows those characters.

Cor
Tom Spink
2003-07-16 09:58:46 UTC
Permalink
Post by Cor
I did not know that the sentence a=b=3 exist in VB and I agree that when it
is there it should give back a 1 and not an integer result of False or True
Why should it give a one? A = B = 3 is "A becomes equal to the comparison of
(B = 3)". B = 3, in this instance, results in a boolean expression.

True is usually -1, because Booleans are usually signed and true is All Bits
On (using two's complement we end up with -1). All bits off, obviously, is
0. => False.

--
Happy to help,
-- Tom Spink
(***@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
Post by Cor
Hello Rainer,
I do not agree with you.
You speak more than one language. So that is not discussable. But lets bring
it back to natural language.
When you say: a is b you means a is equal to b.
Sometimes you mean a is the sum of a and b.
That is natural language.
I did not know that the sentence a=b=3 exist in VB and I agree that when it
is there it should give back a 1 and not an integer result of False or True
You speak German (me too but I cannot write it) and you know that you have
some words that don't exist in English. We can communicate in that
language.
An == operator is not necassery and I hate it in JavaScript that I often
use.
In VB you say.
If b=1 then
a = 1
b = a
end if
It is a nice sentence and you have to be very stupid not to understand it.
Of course we mis for years a=b=c=d and c++ --c but that will change in
future I supose.
When there would be an operator in this sentence I would choise for
a=b?b=c then we should use normal European 2500 years old characters quick
to understand to everybody that knows those characters.
Cor
Chris Dunaway
2003-07-16 19:53:13 UTC
Permalink
Post by Tom Spink
True is usually -1, because Booleans are usually signed and true is
All Bits On (using two's complement we end up with -1). All bits off,
obviously, is 0. => False.
This may be true of the language, but in my opinion, it is poor coding
practice to use a boolean state and an integer value. The two should not
be mixed.

IMHO

Chris
--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail
Rainer Schwenkreis
2003-07-17 09:28:20 UTC
Permalink
Hello Chris,
Post by Chris Dunaway
...
This may be true of the language, but in my opinion, it is poor coding
practice to use a boolean state and an integer value. The two should not
be mixed.
The expression b=3 is of type boolean in VB if you convert TRUE to integer
you will get a value
of -1. In the ancient Versions of Basic there was no boolean so a boolean
operator returned an integer (0 or -1).

since the type of a is not stated explicit it is good coding style according
to you if a is dimed as boolean.
Tom Shelton
2003-07-16 20:04:22 UTC
Permalink
Post by Tom Spink
Post by Cor
I did not know that the sentence a=b=3 exist in VB and I agree that when
it
Post by Cor
is there it should give back a 1 and not an integer result of False or
True
Why should it give a one? A = B = 3 is "A becomes equal to the comparison of
(B = 3)". B = 3, in this instance, results in a boolean expression.
True is usually -1, because Booleans are usually signed and true is All Bits
On (using two's complement we end up with -1). All bits off, obviously, is
0. => False.
First, I totally agree with the respondent Chris, that boolean values should
never be treated as integers... But beyond that - VB was the only language
I ever used that defined true = -1 and false = 0. Most languages define it
as true <> 0, false = 0. Of course most if you do an integer conversion
define the actual value of true as 1.

Tom Shelton
Ken Halter
2003-07-16 20:33:26 UTC
Permalink
I know you've seen this before but... This outlines why True = -1 (because it's Not 0..
which is different than <> 0)

Microsoft Basic Logical Expression Evaluation
http://www.mvps.org/vb/index2.html?tips/truth.htm
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep it in the groups..
Post by Tom Shelton
First, I totally agree with the respondent Chris, that boolean values should
never be treated as integers... But beyond that - VB was the only language
I ever used that defined true = -1 and false = 0. Most languages define it
as true <> 0, false = 0. Of course most if you do an integer conversion
define the actual value of true as 1.
Tom Shelton
Cor
2003-07-16 21:08:01 UTC
Permalink
Tom,
Wrong,
Primarly we did use bit + bit = 0 both bits are equal
bit + bit = 1, bits are not equal.

I agree that -1 is stupid, but it has nothing to do with VB, it is a
behaviour of the object and in all languages that uses window objects the
same.

But I do not have a better sollution.

Cor
Tom Spink
2003-07-16 21:38:23 UTC
Permalink
Post by Tom Shelton
as true <> 0, false = 0.
And something defined as not equal to zero is not zero?

Hence, True = Not 0 => Not &H00, => &HFF => -1 (Signed)

--
Happy to help,
-- Tom Spink
(***@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
Post by Tom Shelton
Post by Tom Spink
Post by Cor
I did not know that the sentence a=b=3 exist in VB and I agree that when
it
Post by Cor
is there it should give back a 1 and not an integer result of False or
True
Why should it give a one? A = B = 3 is "A becomes equal to the
comparison
Post by Tom Shelton
of
Post by Tom Spink
(B = 3)". B = 3, in this instance, results in a boolean expression.
True is usually -1, because Booleans are usually signed and true is All
Bits
Post by Tom Spink
On (using two's complement we end up with -1). All bits off, obviously, is
0. => False.
First, I totally agree with the respondent Chris, that boolean values should
never be treated as integers... But beyond that - VB was the only language
I ever used that defined true = -1 and false = 0. Most languages define it
as true <> 0, false = 0. Of course most if you do an integer conversion
define the actual value of true as 1.
Tom Shelton
Rainer Schwenkreis
2003-07-17 09:35:16 UTC
Permalink
Hello Tom,
Post by Tom Shelton
...
First, I totally agree with the respondent Chris, that boolean values should
never be treated as integers... But beyond that - VB was the only language
I ever used that defined true = -1 and false = 0. Most languages define it
as true <> 0, false = 0. Of course most if you do an integer conversion
define the actual value of true as 1.
Thats true for C and it's relatives. Strong typed Languages define boolean
as either true or false and nothing else.

The reason for the -1 in Basic is that
1. like in C there is no boolean (in original Basic) the if expression tests
against <> 0
2. unlike C there is only one AND and one OR that is used for boolean
operations
and for bit masking operations. C has && and & for and.
Post by Tom Shelton
Tom Shelton
Cor
2003-07-16 18:18:45 UTC
Permalink
Tom,
I wrote somewhere else I am good in JavaScript, therefore I know that
instruction very well (and use it altough I always think it is not good
describing).
That instructions looks if it comes from visicalc, multiplan or lotus or
something.
The ones who made that where very inventieve but making program sentences
like those was not important in those days, nobody did use them.

I wish we had a natural language independent program language, so the
americans (and more counrtries including mine) would not have such an easy
way ahead at the rest of the world. But I am and idialist.
When I wrote the expresion I was thinking on a not existing expresion like
"make a = b if b = c" and I thought it would me more natural to express it
as a=b?b=c.
But it is just an idea.

(It would be a hell of a job to make all classes language independent and I
would not know how)

Cor
Tony Proctor
2003-07-16 08:32:18 UTC
Permalink
I suspect this is an inheritance from VB's humble beginnings.

As others have already pointed out in this thread, VB also overloads the
And, Or, Xor, and Not operators. They can each be used in a "bitwise"
context, e.g.
x = y And z
or a "logical" context, e.g.
If x<0 Or Y<0 Then

The reason is related to the overloading of the '=' operator. Very simple
languages (as Basic was), especially those that are interpreted, reduce
their complexity by handling conditional expressions using exactly the same
expression analyser as arithmetic expressions, and using a stack-based
evaluator for both [Huh?].

For instance, the above 'If' statement might be evaluated as follows:
push x ' push x on evaluation stack
push 0 ' push 0
test_lt ' compare top 2 elements, and replace by a boolean
push y
push 0
test_lt
or ' combine top 2 elements using bitwise 'Or'

Note that the evaluation uses only bitwise operations. The compiler (or
interpreter) doesn't need to worry about coding jumps, or short-circuiting
evaluation.

This is also the reason why 'True' in VB has the value -1, and not 1 as in
C/C++. Otherwise, the following would not be correct:
False = Not True

Tony Proctor
Post by John Davis
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
Case 1: relational operator. In other languages, usually use == instead.
If a = b Then statement
Case 2: assignment operator
a = b
Just my observation. Please discuss.
Cor
2003-07-16 09:18:19 UTC
Permalink
Tony,
Just a discussion and I don't known if it is often been, but I like the
topic.

When I started there was Basic Assembler and we had the same instructions
you use.
(I think yours are for the Intel 8086 serie because every processor has his
own).
The Or, And and Xor where very much used, because the register (not the
registry) was very small, just 8 bits and you had to add the overflow bit to
another register.
Computers where growing and we got registers in a size from about 1K.
There was no need more to use those time spending instructions........ till
the micro processor came and it started all over again..

With the big registers we had Algol, Fortran and Cobol.
Algol and Fortran where the winners in the beginning because all people did
programming in the 8 bit way.
It was based on mathametic code.
Cobol still exist and it was the winner for a long time..
It says COmmon Businness Oriented Language.
It true is a language, very good readable when well used, but programming
now is not only done for business.
And in my opinion it is not usable anymore for about 15 years.

Programs have to be readable to survive, therefore they have to be readable.
But all expirenced programmers know that, only the beginners still have to
learn.
Cor
Cor
2003-07-16 18:30:38 UTC
Permalink
Tony,
I am always triggered by people who said, this is from a beginner or
Americans who write "can you writ those in decent Englesh". (I never saw
this from English people, they know we are speaking Oxford English in our
country (and not the American Oxford)).

So you used the "beginners" word so I was triggered.

But I keep this in mind, programming language is not the real world.
Just inventions from guys like you and me.
I learned that it is a goal to use as much posible the natural language.

I really don't know what English is for people in other countries, maybe
Herfried can tell that, but it looks for me more dificult (of course not for
Herfried).

No hard fealing, just fun.

Cor
Herfried K. Wagner
2003-07-16 18:48:18 UTC
Permalink
Hello,
Post by Cor
But I keep this in mind, programming language is not
the real world.
Just inventions from guys like you and me.
I learned that it is a goal to use as much posible the
natural language.
Although I am a native German speaker, I liked BASIC because of its
natural character. I always/often think in natural language and using a
programming language that allows me to directly type if my thoughts
increases my productivity. Decoding of source code is easier too if the
code is written in a pseudo-natural programming language (and not ASCII
art).
Post by Cor
I really don't know what English is for people in other
countries, maybe Herfried can tell that, but it looks for
me more dificult (of course not for Herfried).
I am not sure if I understand what you mean, but from my point of view I
don't had/have problems in understanding source code because I am not a
native Engligh speaking person. I treat the keywords as abstract symbols
even if they have similarity to words of a natural language.

"Dim"
engl.: dimension
germ.: dimensionieren
"Stop"
engl.: stop
germ.: Stop, stoppen
"End"
engl.: end
germ.: Ende, beenden
"Function"
engl.: function
germ.: Funktion
"If...Then"
engl.: If...then...
germ.: Wenn..., dann...
...

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Cor
2003-07-16 19:39:40 UTC
Permalink
Herfried,
I am Dutch, I think you did know that already.
You know we deal very easy with the English language because our language is
quiet simular with that language even more than German. But English, German
and Duch are languages from the North sea and quiet simular(for who did not
know that).

I find it strange that you wrote that program sentences are abstracts for
you and in the same way wrote they are natural. (I think it is abstract for
most German people, that is normal because German is the major language in
Europe, but not for you).

But we agree and I have to say that my discussion is strange.
We both like VB.net because it is so natural (I hated VB till there was
VB.net, I did find the not anymore usable Cobol the best till now), and on
the other hand I want a language independent program language.
Cor
Herfried K. Wagner
2003-07-16 19:53:17 UTC
Permalink
Hello,
Post by Cor
I am Dutch, I think you did know that already.
I didn't know that.

;-)
Post by Cor
You know we deal very easy with the English language
because our language is quiet simular with that language
even more than German.
When learning English at school, it was sometimes really hard for me.
The teachers didn't show us the similarity of German and English.
Engligh words are often very similar to German dialects, so it's easy to
remember them.
Post by Cor
But English, German and Duch are languages from the North
sea and quiet simular(for who did not know that).
I already knew it.

;-)
Post by Cor
I find it strange that you wrote that program sentences
are abstracts for you and in the same way wrote they
are natural.
I knew you would "complain" about this sentence. As a German speakter I
do not have problems to understand the meaning of the words in the code.
Nevertheless, I think of the large number of people in the world who
speak languages that are not similar to the English language. These
people will have really big problems in understanding the basics of our
programming languages.
Post by Cor
(I think it is abstract for most German people, that is
normal because German is the major language in
Europe, but not for you).
You are right. I think the keywords are not "typical" Engligh, they are
often short or abbreviations, that's why I didn't say that its natural
language for me. There are similarities, I like them, but its not a
natural language.

;-)))
Post by Cor
But we agree and I have to say that my discussion is strange.
We both like VB.net because it is so natural (I hated VB till
there was VB.net, I did find the not anymore usable Cobol
the best till now), and on the other hand I want a language
independent program language.
I agree with you.

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Cor
2003-07-16 20:13:07 UTC
Permalink
Herfried,
Last sentence on this topic.
We agree. We know.
I did some studie about North Sea languages.
Just one word about it for you, once we had one language, so it are not
German Dialects, but the "basic" language LOL. (Till the bible was wroten by
Luther)
Cor
Tony Proctor
2003-07-16 19:17:54 UTC
Permalink
I actually used the word "beginnings" Cor, not "beginners", and this is a
real UK-English word in the Oxford English dictionary. :-)

Tony
Post by Cor
Tony,
I am always triggered by people who said, this is from a beginner or
Americans who write "can you writ those in decent Englesh". (I never saw
this from English people, they know we are speaking Oxford English in our
country (and not the American Oxford)).
So you used the "beginners" word so I was triggered.
But I keep this in mind, programming language is not the real world.
Just inventions from guys like you and me.
I learned that it is a goal to use as much posible the natural language.
I really don't know what English is for people in other countries, maybe
Herfried can tell that, but it looks for me more dificult (of course not for
Herfried).
No hard fealing, just fun.
Cor
Cor
2003-07-16 19:44:08 UTC
Permalink
Tony,
You are right, when you are here I give you a nice Heineken.
Cor
Herfried K. Wagner
2003-07-16 19:54:02 UTC
Permalink
Hello,
Post by Cor
You are right, when you are here I give you a nice
Heineken.
LOL

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Tony Proctor
2003-07-16 10:20:05 UTC
Permalink
That's precisely the point Charles: That sort of approach doesn't
distinguish conditional expressions from arithmetic ones, or boolean values
from integer types. The x=y And z can be blindly evaluated using only
bitwise operations.

Tony
Hi Tony
It is interesting that you picked on the example
x = y And z
as this could also have the meaning (if it were allowed)
x = True, if y is True and z is True, otherwise x = False
which is a logical interpretation rather than a bitwise one.
Also, I wasn't clear whether you thought that True should be -1 (VB) or 1
(C/C++).
I would suggest that there is no justification for True to be defined as
1.
It should always be -1 since the definition of True is
True = Not False
where False is always defined as zero. Thus, by Not-ting 0, i.e. changing
all 1s to 0s and 0s to 1s, we get FFFFFFFF, or -1 in as many bits as we
care
to store the value.
Regards
Charles
Post by Tony Proctor
I suspect this is an inheritance from VB's humble beginnings.
As others have already pointed out in this thread, VB also overloads the
And, Or, Xor, and Not operators. They can each be used in a "bitwise"
context, e.g.
x = y And z
or a "logical" context, e.g.
If x<0 Or Y<0 Then
The reason is related to the overloading of the '=' operator. Very simple
languages (as Basic was), especially those that are interpreted, reduce
their complexity by handling conditional expressions using exactly the
same
Post by Tony Proctor
expression analyser as arithmetic expressions, and using a stack-based
evaluator for both [Huh?].
push x ' push x on evaluation stack
push 0 ' push 0
test_lt ' compare top 2 elements, and replace by a boolean
push y
push 0
test_lt
or ' combine top 2 elements using bitwise 'Or'
Note that the evaluation uses only bitwise operations. The compiler (or
interpreter) doesn't need to worry about coding jumps, or
short-circuiting
Post by Tony Proctor
evaluation.
This is also the reason why 'True' in VB has the value -1, and not 1 as in
False = Not True
Tony Proctor
Post by John Davis
One interesting observation I found is VB6 or VB.NET overloads =
opeartor.
Post by Tony Proctor
Post by John Davis
i.e. = operator has 2 meanings.
Case 1: relational operator. In other languages, usually use == instead.
If a = b Then statement
Case 2: assignment operator
a = b
Just my observation. Please discuss.
Chris Dunaway
2003-07-16 19:59:14 UTC
Permalink
I would suggest that there is no justification for True to be defined
as 1. It should always be -1 since the definition of True is
I would suggest that there is no justification for treating True or False
and integer values at all!

IMHO with Option Strict On, the following code should not compile (and I
haven't tested in VS to see if it does):

Dim a As Boolean = True
Dim b As Integer = 0
Dim y As Integer

y = a And b 'IMHO, this should generate an error.

IMHO, booleans and integers should not be type compatible.

There was a big argument when VB.Net was first released about whether True
should be 1 or -1. I say that True should be True and should have no
integer value at all. It makes no logical sense to me to convert a boolean
value to an integer.

Chris
--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail
Cor
2003-07-17 11:04:57 UTC
Permalink
Tony,
I did not deal in the discussion, till now but:
0 = False and not False = True.
This has always been in every language and every computer.
That is the basic of programming.

I don't know but I think that even -0 is True, but for me is that bullshit.
That discussion I had once, but I always have to cry when I think about such
a discussion.

Cor

Continue reading on narkive:
Loading...