[Done] Boolean simple empty string

All bugs related to new C backend
User avatar
mk-soft
Addict
Addict
Posts: 3299
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

[Done] Boolean simple empty string

Post by mk-soft »

Simple empty string validation not longer work

Code: Select all

s1.s = ""
r1 = Bool(s1)
Debug r1
ASM = false
C = true
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
User avatar
skywalk
Addict
Addict
Posts: 3563
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Boolean simple empty string

Post by skywalk »

I never liked this shorthand.
What is the logic?
String has length or exists?
Just use Len(s$).
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Little John
Addict
Addict
Posts: 4021
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Boolean simple empty string

Post by Little John »

skywalk wrote: Sun Jun 20, 2021 4:01 pm I never liked this shorthand.
Me too. A string isn't a Boolean expression.
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
User avatar
STARGÅTE
Addict
Addict
Posts: 1658
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Boolean simple empty string

Post by STARGÅTE »

Little John wrote: Sun Jun 20, 2021 5:12 pm
skywalk wrote: Sun Jun 20, 2021 4:01 pm I never liked this shorthand.
Me too. A string isn't a Boolean expression.
Of course not, but Bool() generates a boolean value from any expression.
And because "If expression" is the same like "Bool(expression)", it should also evaluated the same.

Code: Select all

s1.s = ""
If s1
	Debug 1
Else
	Debug 0
EndIf
Debug Bool(s1)
PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 5.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Little John
Addict
Addict
Posts: 4021
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Boolean simple empty string

Post by Little John »

Yes, of course it should be evaluated the same.
But I didn't write about that. I just wrote that I don't like it.

Code: Select all

Bool(s$)
doesn't make sense, and s$ isn't a Boolean expression.
Something like

Code: Select all

Bool(s$ <> "")
does make sense, though.
Same when using If.

Technically speaking,

Code: Select all

Bool(s$)
works (in the ASM backend of PureBasic). But that's not what I mean.

There are different kinds of "objects" in programming languages:
Numbers, strings, arrays, Boolean expressions etc.
Mixing them up will prevent beginners from learning clean logical thinking.
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
AZJIO
Enthusiast
Enthusiast
Posts: 246
Joined: Sun May 14, 2017 1:48 am

Re: Boolean simple empty string

Post by AZJIO »

Little John wrote: Sun Jun 20, 2021 6:31 pm Something like

Code: Select all

Bool(s$ <> "")

Code: Select all

If i<>0
an unnecessary number comparison operation is performed here. The number itself is the answer to the question.
It's the same with strings. It is necessary to accept as an axiom that there is a lie and not to make an unnecessary comparison.
A beginner can compare, but this should not be the rule.
If this leads to incompatibility between programming languages, then I do not know what to do. Either change the rule or convert the code correctly.

mk-soft
I did a translation to a boolean expression

Code: Select all

If Bool(s$)
but it works slower than this:

Code: Select all

If s$
this is also slow:

Code: Select all

If len(s$)
You need to check for a single character. In the other case, you need to run through all the characters.
User avatar
Keya
Addict
Addict
Posts: 1866
Joined: Thu Jun 04, 2015 7:10 am

Re: Boolean simple empty string

Post by Keya »

Code: Select all

If PeekA(@s$)     ;check if first byte is <> 0
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Boolean simple empty string

Post by Saki »

This has its pitfalls @Keya
It is easy to overlook.

So it is OK

Code: Select all

x$="Ȁ"
Debug x$
Debug Bool(PeekA(@x$)) ; Not OK
Debug Bool(PeekW(@x$)) ; OK
地球上の平和
Little John
Addict
Addict
Posts: 4021
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Boolean simple empty string

Post by Little John »

Empty string validation can be simply, quickly and safely done like this:

Code: Select all

If Asc(s$) = 0
or

Code: Select all

If Asc(s$) = ''
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
User avatar
DoubleDutch
Addict
Addict
Posts: 3206
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Boolean simple empty string

Post by DoubleDutch »

Using if to see if a string is empty or not is used all the time in the examples and other code. It should work imho.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Fred
Administrator
Administrator
Posts: 14423
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Boolean simple empty string

Post by Fred »

Fixed.
Post Reply