Page 1 of 1

BlindWatchMaker1 require

PostPosted: Tue Feb 12, 2008 8:40 am
by dennis
In these two snippets:

def runSingleStepSelection(goal as String, alphabet as String) as float
require
goal.length
alphabet.length


def randomString(length as int, alphabet as String) as String
require
length > 0
alphabet <> ''


are alphabet.length and alphabet <> '' equivalent?

Re: BlindWatchMaker1 require

PostPosted: Tue Feb 12, 2008 9:39 am
by AlGonzalez
Logically yes, but of course you would have to look at the IL code to know if it is implemented the same.

As for Cobra, if you look at the generated C# code, it tests this for the first one:
Code: Select all
if (!(0!=(alphabet.Length)))
and this for the second
Code: Select all
if (!(alphabet!=""))

Re: BlindWatchMaker1 require

PostPosted: Tue Feb 12, 2008 11:28 am
by Charles
When the type is non-nil ("String" instead of "String?"), they're equivalent boolean expressions and you can use either one.
I still haven't decided which one I like best.

If the type is nilable ("String?") then you would want to guard the .length access with "arg and arg.length" which is equivalent to saying "arg is not nil and arg.length".