= operator overloaded in VB6 or VB.NET

T

Tom Shelton

steve said:
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
 
J

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.
 
H

Herfried K. Wagner

Hello,

John Davis said:
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
 
J

Jeff Johnson [MVP: VB]

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....)
 
R

Russ Bishop

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
 
S

steve

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>
 
C

Cor

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
 
T

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
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
 
C

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
 
C

Cor

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
 
T

Tom Spink

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
([email protected])

"Go down with your server"

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

Please respond to the newsgroup,
so all can benefit
 
T

Tony Proctor

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

Charles Law said:
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


Tony Proctor said:
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

John Davis said:
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.
 
K

Ken Halter

steve said:
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.
 
S

steve

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.

:)
 
C

Cor

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
 
C

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
 
H

Herfried K. Wagner

Hello,

Cor said:
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).
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
 
T

Tony Proctor

I actually used the word "beginnings" Cor, not "beginners", and this is a
real UK-English word in the Oxford English dictionary. :)

Tony
 
C

Cor

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top