Forums

BlindWatchMaker1 require

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

BlindWatchMaker1 require

Postby dennis » Tue Feb 12, 2008 8:40 am

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?
dennis
 
Posts: 21

Re: BlindWatchMaker1 require

Postby AlGonzalez » Tue Feb 12, 2008 9:39 am

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!=""))
AlGonzalez
 
Posts: 13
Location: Greenville, SC - USA

Re: BlindWatchMaker1 require

Postby Charles » Tue Feb 12, 2008 11:28 am

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".
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 26 guests