[Gambas-user] MoveFirst MoveNext etc

Doriano Blengino doriano.blengino at ...1909...
Thu Apr 9 22:38:56 CEST 2009


Ron_1st ha scritto:
> On Thursday 09 April 2009, Jeff wrote:
>   
>> What is the thinking behind a Result.MoveFirst() and MoveNext()
>> returning a false if a record is there?
>>
>> So, to read round a result set I end up using a Boolean with a double
>> negative:
>>
>> noMoreRows = myResult.MoveFirst()
>> WHILE NOT noMoreRows
>>   PRINT myResult!id
>>   noMoreRows = myResult.MoveNext()
>> WEND 
>>
>> I would have expected the MoveFirst() and MoveNext() return true if a
>> record found, so I'm wondering why it's that way round.
>> Or, is there a better loop structure to use so that it reads better?
>>
>>
>>     
>
> The only logic I see is the way it is done in C/C++
>   
I think it could be pretty the same, but I like it this way; I think 
that the normal flow of code is when normal things happen, and when 
something exceptional happens, branches are taken. So, the code above 
could be written:

    if myResult.MoveFirst() then
      print "No records"
      return
    endif

    repeat
      print myresult!id
    until myresult.MoveNext()

...no "NOT" used. I agree that "if MoveNext()" could signify "if 
MoveNext succeeded", but if the functions worked this way, one should write:

    if not movefirst then
      ...
    endif

    print myresult.id
    while movenext
      printd ...!id
    wend

or, even worse,

    if movefirst then
      print ..!id
      while ...
      wend
    else
      print "no records"
    endif

It is a matter of taste.

Regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list