| Store | Cart

Re: [TCLCORE] engineering standard for early exit

From: Donal K. Fellows <dona...@manchester.ac.uk>
Wed, 02 Apr 2014 15:57:54 +0100
On 02/04/2014 00:03, Jeff Rogers wrote:
> Is there a standard for writing C code with early exits?  I didn't see> anything relevant in the Tcl Engineering Manual (TIP 247); I was> wondering if there is something elsewhere.>> I have a piece of code that needs to make several calls, and if any of> them fail, the function should stop and whole thing fail.  But> regardless of whether the whole operation succeeds or fails, cleanup> code needs to run.

A reasonable question.

> A random survey of core code suggests that "goto cleanup" is preferred,> but is that a requirement or coincidence?

Coincidence really in my case. If the resource management (or the inner
"business" code) is complex enough, and the resource management clean
enough, I'd use an inner function instead. But when there's several
stages of resource management and things are complicated, I'd use goto
and nested ifs. (Were I using C++ or Java or even Tcl now that we have
[try], I'd be stricter. C just isn't great at doing neat cleanup code.)

Donal.


begin:vcard
fn:Donal K. Fellows
n:Fellows;Donal
org:The University of Manchester;School of Computer Science
adr:;;Oxford Road;Manchester;;M13 9PL;United Kingdom
email;internet:dona...@manchester.ac.uk
version:2.1
end:vcard

------------------------------------------------------------------------------

_______________________________________________
Tcl-Core mailing list
Tcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-core

Recent Messages in this Thread
Jeff Rogers Apr 01, 2014 11:03 pm
Brian Griffin Apr 02, 2014 12:26 am
Alexandre Ferrieux Apr 02, 2014 06:16 am
Donal K. Fellows Apr 02, 2014 02:57 pm
Messages in this thread