mIRC Home    About    Download    Register    News    Help

Print Thread
$bvar(&nonexist,1-).text should return null string #266612 04/01/20 04:22 PM
Joined: Feb 2003
Posts: 2,681
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,681
When passing a non-existent &binvar to $bvar().text, mIRC throws an error.
I believe it should return null empty text instead, since the parameters are not invalid.

//echo -a $bvar(&nonexist,1-).text
> * Invalid parameters: $bvar

To prove that the parameters are indeed not invalid, this similar command works.

//echo -a $bvar(&nonexist,0)
> 0


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: $bvar(&nonexist,1-).text should return null string [Re: Raccoon] #266616 04/01/20 08:53 PM
Joined: Dec 2002
Posts: 4,655
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,655
Thanks for your bug report. This is intentional. Ideally, $bvar(&nonexist,0) should also return an error. That would be my preference. However, at the time this was implemented, scripters appeared to be happy with the behaviour, and now that it has been in place for so long, changing it would break existing scripts.

Re: $bvar(&nonexist,1-).text should return null string [Re: Khaled] #266617 04/01/20 11:40 PM
Joined: Apr 2010
Posts: 938
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 938
I perfer the current behavior of $bvar(&nonexist, 0) It reduces two checks to one

Code
if ($bvar(&nonexist, 0)) ...

if ($bvar(&nonexist) && $bvar(&nonexist, 0) > 0) ...


with $bvar(&nonexist, 1-).text or $bvar(&nonexist, 1, ...).text I wouldn't be against it returning an empty string

Last edited by FroggieDaFrog; 04/01/20 11:41 PM.

I am SReject
My Stuff
Re: $bvar(&nonexist,1-).text should return null string [Re: Khaled] #266619 05/01/20 12:36 AM
Joined: Feb 2003
Posts: 2,681
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,681
So how do we safely handle imaginary binvars without our scripts crashing all the time, if not with an if-condition checking that a $null string is returned?

Is this what $error /reseterror is for?

$urlget(%id).target sometimes makes up imaginary binvars for instance, so how is that correctly handled?

Last edited by Raccoon; 05/01/20 12:38 AM.

Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: $bvar(&nonexist,1-).text should return null string [Re: Raccoon] #266620 05/01/20 12:53 AM
Joined: Apr 2010
Posts: 938
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 938
(Currently) to check if a bvar exists without throwing an error you use $bvar(&bvar) then if the check passes use $bvar(&bvar, 1-).text to get the text

With that said, returning $null/an-empty string is more consistent with other identifiers than throwing an error; case in point: hashtables
Code
echo -a >> $hget(nonexist, item)

hmake exists 1
echo -a >> $hget(exists, nonexist)
hfree exists

Last edited by FroggieDaFrog; 05/01/20 01:00 AM.

I am SReject
My Stuff
Re: $bvar(&nonexist,1-).text should return null string [Re: FroggieDaFrog] #266630 06/01/20 06:31 PM
Joined: Dec 2002
Posts: 4,655
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,655
Quote
With that said, returning $null/an-empty string is more consistent with other identifiers than throwing an error; case in point: hashtables

Alas, this does vary across commands/identifiers, probably because every time I add a new feature, a different user is requesting it, and some users ask for an error to be reported in some situations, while others ask for a default value to be returned in place of an error, to make coding easier so that they do not have to check for errors.

In this case, the purpose of the error is to indicate to the scripter that they have typed a variable name incorrectly in their script. If an error wasn't reported, they may not notice it in a large script without a lot of debugging.

And we would then probably end up with the opposite bug report, ie. it should report an error.