TG mentioned binary compares such as IF X THEN ... I developed a hatred of that because what was regarded as true or false varied from system to system. In fact it probably still does some require a precise 0 or 1 others regard 0 as false and anything else true until one hits the dreaded null - null because it was set or null because it was never initialised. In fact Turing defined zero as true.
The important point here is that the multivalue Basic language defines that anything that returns true or false returns one and zero respectively and further broadens the definition to say that using a value as a Boolean treats zero and a null string as false, everything else as true (let’s leave the SQL style null out of this for now). There is no room for disagreement. This is how the language says it works. Yes, other languages may define true/false differently (VB uses -1 for true) but they define lots of other differences too and we accept that.
Of course, complications can arise. When we did the data collections development for QM, we needed to be able to parse a JSON string into a collection and then rebuild it later. JSON defines a Boolean data type and it would be totally unacceptable for true/false to be translated to 1/0 in Basic only to end up as numeric values if we rebuild the JSON representation. To get around this, we implemented an internal Boolean data type but, for compatibility with the way the language definition says things must work, this is completely interchangeable with the numeric style in program expressions. Just about the only place this is visible is in the debugger where the data type may appear as Boolean.
Booleans are fine (my opinion and feel free to disagree). On the other hand, I have a strong hate of
IF X ELSE ….
instead of
IF NOT(X) THEN …..
I suspect that the language only supports this because the THEN/ELSE clause attaches to so many other statements such as
READ VAR FROM FVAR, ID ELSE …
Ultimately this is just a matter of style and, possibly, coding standards. If someone who has never seen the program before can understand what it is doing, that sounds good to me.
Martin Phillips
Ladybridge Systems Ltd
17b Coldstream Lane, Hardingstone, Northampton NN4 6DB, England
+44 (0)1604-709200
--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
The important point here is that the multivalue Basic language defines that anything that returns true or false returns one and zero respectively and further broadens the definition to say that using a value as a Boolean treats zero and a null string as false, everything else as true (let’s leave the SQL style null out of this for now). There is no room for disagreement. This is how the language says it works. Yes, other languages may define true/false differently (VB uses -1 for true) but they define lots of other differences too and we accept that.
Booleans are fine (my opinion and feel free to disagree). On the other hand, I have a strong hate of
IF X ELSE ….
instead of
IF NOT(X) THEN …..
Hi
Oh Dear TG I did say that your example was good and the manual was not.
Traditionally, the result of a logical or Boolean expression is considered true if it evaluates to 1 and false if it evaluates to 0.
In the D3 system, expressions that depend on a result of true or false also evaluate other values as true or false. This tends to vary somewhat between implementations. In generic D3, any nonzero integer that is positive or negative, evaluates to true. For example:
x = 5 if x then stop |
Because x is a nonzero integer, the program takes the then branch and stops. In generic D3, any zero or null value evaluates to false. For instance:
y = "" if y then stop else print "yup" |
This prints yup because y is evaluated as false. Some D3 implementations additionally evaluate any negative numbers as false, and positive numbers as true. This also holds true for +, -, ., +., and -..
This means that you must test your system to determine how it handles true and false. This program does it:
loop print "value to test " : input value until value = "quit" do if value then print "true" else print "false" repeat |
Test it with negative numbers, null (Enter), positive numbers, letters, and so on.
A relational expression evaluates to 1 if the relation is true, and evaluates to 0 if the relation is false.
Well, here's another fine thread gone down the rabbit hole.
My conclusions as I attempt to retire this thread:
-
Booleans in BASIC are fine, just not used much by people who only use
MV BASIC. For their usefulness, and yes clarity, I will continue to use
them, though I'll try to adopt the technique of assigning
TRUE=(1=1);FALSE=NOT(TRUE) and then using Flag=True rather than Flag=1.
(That said I wrote some code today with a devilish grin:
DONE=LINES>=TOTAL.LINES, of course to be used later with UNTIL DONE.)
-
It seems to be an unsupportable rumor that in BASIC 0 and 1 are not
universally false and true, respectively. The syntax above should work
on any system running today.
- In this thread I've not seen a single valid argument against this concept, outside of personal preference for whatever reason - which I actually do consider to be valid as long as it's not disguised as something technical.
- If we stick to IF Flag THEN, the code is considered readable. IF NOT(Flag) THEN (common in other languages as if !Flag) is preferable to IF Flag ELSE (not even available in most other languages), but IF Flag THEN DoNothing ELSE DoSomething might be as welcome.And about Locate (at least in D3), see the ARS, DRS sorting option for numerics.
I thank everyone once again for participating.
T
I shall allow the current D3 manual the last word on this please note the statement "This tends to vary somewhat between implementations" I rest my case use it and get burned avoid and all will be well "...In the D3 system, expressions that depend on a result of true or false also evaluate other values as true or false. This tends to vary somewhat between implementations. In generic D3, any nonzero integer that is positive or negative, evaluates to true."
Actually ePick came out in October 1992. However the place where a person learns Pick is the manual or bitter experience - such as the change in NOT usage in ENGLISH/ACCESS where programs that worked well for years suddenly fell over and unreliable implementations of Boolean commands..
The fact that this topic has caused such confusion, as evidenced in another thread and here, is surely evidence enough that constructs such as IF NOT(x) ELSE ...should be totally avoided and even ones with apparent clarity such as IF DAYLIGHT... should be used with extreme care, particularly when programmers with other backgrounds where the rules are different are involved.
I tried to pass a Boolean once - it was really painful. Then I took a conditional, and I felt much better.
--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms