From: Ian Jackson Subject: Re: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen Date: Wed, 9 Apr 2014 15:59:16 +0100 Message-ID: <21317.24644.65911.653586@mariner.uk.xensource.com> References: <1396451496-5716-1-git-send-email-paul.durrant@citrix.com> <1396451496-5716-9-git-send-email-paul.durrant@citrix.com> <5345686F0200007800007313@nat28.tlf.novell.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02D3DA4@AMSPEX01CL01.citrite.net> <53456D060200007800007389@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <53456D060200007800007389@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: Paul Durrant , Stefano Stabellini , Ian Campbell , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org Jan Beulich writes ("RE: [PATCH v4 8/8] ioreq-server: bring the PCI hotplug controller implementation into Xen"): > On 09.04.14 at 15:42, wrote: > > Personally I find using forward jumps to fail labels the most > > readable form of error exit - I wish they were used more widely. > > Interesting - almost everyone/-thing involved in educating me in > programming skills recommended to try to get away without goto > altogether, unless programming Fortran, Basic or some such. I think the hatred of goto is a "lie to children". It is easy to misuse goto and make spaghetti. My view is that use of goto should normally be restricted to certain very specific patterns. Examples: * Providing a uniform cleanup path (eg error exit) from a function * "goto continue_foobar" or "goto break_foobar" for emulating "continue" or "break" on an outer loop from within an inner loop * Usages embedded in structural macros Certainly goto should not be used if another control construct can do the job (without excessive circumlocution or repetition). In libxl we have a few "goto retry_transaction" which I think should be abolished. IME goto should not be used to construct loops. But goto _should_ be used to avoid repetition. The exit path pattern is a particularly good example. In functions which use this pattern: - all variables which refer to resources are initialised to "unallocated" (0, -1, whatever) at declaration - there is only one use of "return" - the return is preceded by a single copy of the cleanup for all the allocated resources The result is that it is difficult to accidentally leak or double-free resources. Failure to initialise one of the resource variables to "empty" is normally detected by the compiler. In this pattern the label should have a conventional name. In libxl we use "out". Ian.