Re: Goto considered dramafull

Thomas Shinnick <[email protected]>
Newsgroups gmane.comp.fonts.fontforge.devel
Message-ID <CAEfS-piTq7qjLbBN+fQ=M0Trj+NcTedk_q+K4mwvvU6=YjD9Pw@mail.gmail.com>
Oh yes, my intent would be to only use goto for truly exceptional
situations as in error cleanup, and in order to make *clearer* what is
going on.

A goto to end of routine to label e.g. "InputError:" with obvious return
ending that cleanup stanza - we aren't doing anything else here but
cleaning up and leaving.


On Sat, Aug 30, 2014 at 12:48 PM, Jose Da Silva <[email protected]> wrote:

> On August 30, 2014 06:46:17 AM Frank Trampe wrote:
> > I've never liked gotos because they break the nesting model and make
> > tiered clean-up difficult.
>
> You need to pay attention to nesting when you use goto.
>
> This is a very good example with nesting, look at this function:
> fontforgeexe/lookupui.c:SFDTrimUndoOldToNew
>
> error3SFDTrimUndoOldToNew: fclose(of);
> error2SFDTrimUndoOldToNew: fclose(nf);
> error1SFDTrimUndoOldToNew: fclose(retf);
> error0SFDTrimUndoOldToNew:
>     return 0;
> }
>
>
> This one is less complicated:
> gutils/gimagereadtiff.c:GImage *GImageReadTiff(char *filename) {
>
> errorGImageReadTiff:
>     fprintf(stderr,"Bad input file \"%s\"\n",filename );
> errorGImageReadTiffMem:
>     free(raster); free(ret);
>     TIFFClose(tif);
>     return( NULL );
> }
>
> > There are plenty of ways to avoid using them. One is to have each block
> > check for success or non-failure of the preceding block before doing its
> > thing. This also allows for more localized clean-up of block-specific
> > data.
>
> Agreed, other ways can be done, such as case statements or even nested
> while (0) loops, or something else:
>
> http://cvs.savannah.gnu.org/viewvc/aspell/prog/prezip.c?revision=1.10&root=aspell&view=markup
>
> example:
>   while (0) {
>     error_mem_c: retVal = 6; break;     /* memory alloc error */
>     error_out_c: retVal = 5; break;     /* output data error  */
>     /*           retVal = 3;               corrupt input      */
>   }
>
>
> ...however, having a goto pointing to the bottom of a function seems a bit
> cleaner and straight to the point.
>
> You shouldn't fear goto statements, just understand them.
>
> If you do gcc and output assembler source for any of the C files, you'll
> see
> a lot of goto statements for all sorts of statements, such as:
> if/then/else, case, while, etc...
>
>
>
>
>
> ------------------------------------------------------------------------------
> Slashdot TV.
> Video for Nerds.  Stuff that matters.
> http://tv.slashdot.org/
> _______________________________________________
> fontforge-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/fontforge-devel
> http://fontforge.10959.n7.nabble.com/Developer-f3.html
>

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/

_______________________________________________
fontforge-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fontforge-devel
http://fontforge.10959.n7.nabble.com/Developer-f3.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.