Now that you spell it out like that I think I have a strong preference for option 2
because any bugs down in findFirstmatch to do with the two returned items being out of 
sync will appear as bugs in the caller

e.g. return false but populate the returned item or return true with a nil pointer.

In option 2, the contract between the caller and callee is cleaner. The findFirstMatch 
has the responsibility for finding the firstMatch and nothing else. The caller is 
responsible for thinking about whether no match is an error or not. Furthermore as 
part of the contract, the caller is responsible for passing a valid list and if it 
doesn't 
then the function can throw an exception.

So my version would be:

functionFindFirstMatch (List: TItemList; Status: TItemStatus):TListItem;
var
   i : Integer;
begin
   if not assigned(List) then raise exception.create('No list assigned for 
findFirstMatch()');
   if not assigned(Status) then raise exception.create('No status assigned for 
findFirstMatch()');
   Result := nil;
   for i:= 0 to list.count-1 do
     if list[i].status = status then
     begin
         result := list[i];
         exit;
     end;
end;

>From a personal perspective, I like this because it increases the chances of 
>seperation between error handling and application logic. If also attempts to stop a 
>bug 
jumping the stack from caller to callee or back up.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to