Skip to main content
added 19 characters in body
Source Link
Tim
  • 2.1k
  • 2
  • 14
  • 19

A co-worker and myself are having a debate on whats best. Both concepts work and work well but is there a general consensus on not making a call to exit?

Whats better?

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;

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;

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?

A co-worker and myself are having a debate on whats best. Both concepts work and work well but is there a general consensus on not making a call to exit?

Whats better?

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?

A co-worker and myself are having a debate on whats best. Both concepts work and work well but is there a general consensus on not making a call to exit?

Whats better?

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?

added 111 characters in body
Source Link
user8
user8

A co-worker and myself are having a debate on whats best. Both concepts work and work well but is there a general consensus on not making a call to exit?

Whats better?

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?

A co-worker and myself are having a debate on whats best. Both concepts work and work well but is there a general consensus on not making a call to exit?

Whats better?

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;

I prefer to use the exit statement since it results in fewer lines of code and looks cleaner to me

A co-worker and myself are having a debate on whats best. Both concepts work and work well but is there a general consensus on not making a call to exit?

Whats better?

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?

Post Merged (destination) from programmers.stackexchange.com/questions/77965/…
Source Link
Tim
  • 2.1k
  • 2
  • 14
  • 19

Best practices concerning exit in Delphi

A co-worker and myself are having a debate on whats best. Both concepts work and work well but is there a general consensus on not making a call to exit?

Whats better?

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;

I prefer to use the exit statement since it results in fewer lines of code and looks cleaner to me