share
Stack OverflowIn Delphi is there any reason not to use exit?
[+16] [0] Tim
[2011-05-19 14:16:39]
[ delphi coding-guidelines ]
[ http://stackoverflow.com/questions/6060088] [DELETED]

A co-worker and myself are concerned with whats best.

To call exit within a procedure to avoid doing the rest of the code as in ...

if Staging.Current = nil then
  Exit;

DoSomethingA(FileNameA);  
DoSomethingB(FileNameB);  
Staging.DeleteCurrent;

or to not call exit and instead wrap it in a begin and end

if Staging.Current <> nil then  
  begin   
    DoSomethingA(FileNameA);  
    DoSomethingB(FileNameB);  
    Staging.DeleteCurrent; 
  end;

Both work. I prefer to use the exit statement since it results in fewer lines of code and looks cleaner to me, but is there any reason or any consensus among programmers to avoid using exit to leave a procedure?

(3) There will never be a consensus among programmers as long as you ask enough of them. - Uwe Raabe
@uwe Consensus is often taken to mean a majority. So there's no reason why a consensus could not be reached. - David Heffernan