Is here someone who like & |

BlitzMax Forums/BlitzMax Beginners Area/Is here someone who like & |

MrCredo(Posted 2005) [#1]
I dislike that AND was changed to & and OR was changed to | and the old keywords now used for bool operations...

I think, this should changed to:

AND=bitwise AND (=old BB-style)
OR=bitwise OR (=old BB-style)
XOR=old XOR in BB

BAND = bool AND
BOR = bool OR


skn3(Posted 2005) [#2]
I disagree, the new way is much better. The two different types, logic and bitwise are compeltely different. Having AND and & is great :).

if (flags & 1 AND flags & 2 AND flags & 4) OR flags & 8


Much better than..
if ((flags AND 1) AND (flags AND 2) AND (flags AND 4)) OR (flags AND 8)



Michael Reitzenstein(Posted 2005) [#3]
I also disagree.


Clyde(Posted 2005) [#4]
To be honest I dont understand the difference between bitwise and logical. But the new way of using mathmatical operators just takes a bit of getting used to thats all.


Damien Sturdy(Posted 2005) [#5]
I agree, but i will disagree oce i get used to it.


ImaginaryHuman(Posted 2005) [#6]
When you're talking about bitwize `and`, you're talking about performing a binary operation on each individual bit in the information - you're modifying the value, content or data. Each individual `bit` in the value, when represented in binary notation, is `and'ed` with the bits in the mask you provide. There must be a 1 set in the mask and a 1 set in the value in order for that 1 to remain in the value, otherwise it is set to 0. This `masks in or out` different bits of the value. This is `bitwize and` - to do with the bits in the value.

A logical and is to do with boolean expressions where you're talking about `this expression is true` and also `that expression is true`. It's the logical combination of more than one expression. In that case the total value of one expression has to be true AND the total value of the other expression(s) has to be true, in order for the *overall* total expression to be true. It's more a matter of boolean logic than what the actual content of each expression is.

Bitwize AND ("&") works on the individual bits in a the value of a single expression.

Logical AND ("and") works on comparing more than one expression to each other.

Consider them micro and macro levels. Bitwize is the micro level, logical is the macro level.

You use bitwize and to mask one value against another, typically to set certain bits in the value to 0 so that you can isolate only the part you want to screen out unwanted data from within a value. You use logical and to then decide whether to go ahead with a *condition* based on all the parts of an expression being true (where true means nonzero, right?)

So it's handy to distinguish between the two types. You need to know whether you are working on the bits within an expression or comparing more than one expression.

They could have it so that both use the "and" keyword and for some people that is sufficient clarity. For others it's nice to distinguish the subtle difference between the two.

Same goes for `or` - bitwize OR ("|") means if the bits in one value are set OR the bits in the other value are set, they remain set, otherwise they become 0 - on a binary leve. The logical OR means you are comparing the result of two or more individual expressions/values and if ANY of those expressions are true in boolean terms then the overall expression is true.

If you had only an "and" and "or" keyword, code would look like this:

If ((a and b) and (c and d)) or (f or (g and m))

rather than

If ((a & b) and (c & d)) or (f | (g & m))

or

If ((a=true and b=true) & (c=true and d=true)) | (f=true or (g=true and m=true)

See how there can be lots of different interpretations, you don't really know whether you are talking about `anding` the values together or treating them as boolean logic. There are two distinct functionalities here - modifying the value and checking whether the value is true. I think it's good to have two distinguishing keywords cus then you know exactly what is happening.


Floyd(Posted 2005) [#7]
MrCredo is complaining is about the notation, not the fact that two different And operators exist.
To some extent I agree, although it is easy enough to get used to the names.

I am used to the following styles:

In C we have symbols &, &&

& is bitwise
&& is logical

We have the mnemonic device that the wider symbol operates on wider data.

The Basic style is to use names instead of symbols

AND is logical
BAND is bitwise

The mnemonic is the letter B built into the keyword BAND.

I would have preferred that BlitzMax use one of these styles rather than mixing elements of both.


sswift(Posted 2005) [#8]

I disagree, the new way is much better. The two different types, logic and bitwise are compeltely different. Having AND and & is great :).

if (flags & 1 AND flags & 2 AND flags & 4) OR flags & 8




Much better than..

if ((flags AND 1) AND (flags AND 2) AND (flags AND 4)) OR (flags AND 8)




Well I'm going to have to disagree with you there. If I didn't see your two examples side by side, I wouldn't have any idea that the & operator takes precedence over the AND operator. And if I was coming from another language and looked at your code, I would just think you were crazy and using different ands for the hell of it.

It should be intutively obvious what order things go in. I have been translating a bunch of code in C the last few days, and seeing stuff like this:

A + B - C + D - E

And I'm like "Oh my god... What order of operations does C use? And what order of operations does Blitz use? I seem to remember from my math classes that + comes before -, or was it that they were both equal in stature, and the equation should be evaluated right to left?"

That in my opinion is stupid. With a few parentheses seperating options the order of operations could be made completely clear. The only time I don't use parentheses to seperate operations in my program is when I'm combining multiplication with addition or something, in which case I know multiplay ALWAYS comes before add.

"A*D - C"

I can be pretty sure will evaluate the same in any language, or by any mathematician, and if you notice, I don't put a space between the operators when they are multiplied to give that extra hint that they are grouped together.

...

Oh and I'm not saying Mark should change the behavior of the operators. I'm saying you coding like that because you can avoid using parentheses is bad.


Shambler(Posted 2005) [#9]
Coming from C++ I prefer the & and | to an alternative of BAND and BOR.

I agree with sswift that you should use brackets though, purely for the sake of clarity.


Floyd(Posted 2005) [#10]
I find the precedence in Blitz to be the single most annoying 'feature' of operators.

By long tradition multiplication has higher precedence than addition. AND,OR are the logical analogs of Multiplication,Addition. In fact, they are often called logical product and logical sum.

Here is one obvious correspondence. Write out the multiplication table for the values 0,1. Then do the same for AND. You will notice the tables are identical.

This is why the C-style rules are consistent and reasonable:

Multiplication has higher precedence than Addition.
Logical And has higher precedence than Logical Or.
Bitwise And has higher precedence than Bitwise Or.


The Blitz approach, giving AND/OR the same precedence, is just wrong.


ImaginaryHuman(Posted 2005) [#11]
Floyd, I was reponding to the confusion expressed by Thumbz.

I prefer at least AND and OR to be used. I would not like BAND and BOR at all. Getting used to & and | is a bit odd to me personally but it makes sense.


MrCredo(Posted 2005) [#12]
hm... i don't like & | - this symbols don't exist in BASIC... ok & was a shortcut for integers (QB-style)

z&=x&+y&

PB use & and | and i hate this
a don't like this all symbols and shortcuts... this is not readable...

my problem is, that AND in old BlitzBasic's was a bitwise operator... and i don't understand why this was changed...

i would love to see a readable keyword for & and | and ~
if mark add new keywords for this, i will never use this crazy symbols...

ok C++ use this symbols... i don't like this... but you can define your own replacements for this in C++


skn3(Posted 2005) [#13]
Oh and I'm not saying Mark should change the behavior of the operators. I'm saying you coding like that because you can avoid using parentheses is bad.


Id say using excessive parentheses is worse. It is just a matter of personal preference. Having used blitz and php at the same time, for a long time, merging the two styles is great for me.