gotos was: open source awareness [was Re: [FoRK] Fwd:
[Processing] download the new beta release!)
jm at jmason.org
Fri May 20 14:33:58 PDT 2005
-----BEGIN PGP SIGNED MESSAGE-----
Joe Barrera writes:
> So what do you think about gotos?
> A lot of people say they're bad, but I say they're good.
> Just trying to start a stimulating and original technical discussion,
> I once wrote this program that NEEDED a goto, otherwise
> it would have been too slow for the customer.
excellent! I can tie in both topics -- open sores and gotos,
with this link:
Raymond Chen (of MS) discusses the hazards of exceptions, and
somewhere in the comments Christoph Hellwig (linux kernel hacker)
crops up with this:
re: Cleaner, more elegant, and harder to recognize
Monday, January 17, 2005 8:08 AM by Christoph Hellwig
I'm a bit suprised no one brought the goto cleanup style used e.g. about
everywhere in the Linux kernel up. I'd look something like (hope the
pasting doesn't screw up the indentation):
BOOL ComputeChecksum(LPCTSTR pszFile, DWORD* pdwResult)
BOOL fRc = FALSE;
HANDLE h, hfm;
h = CreateFile(pszFile, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE)
hfm = CreateFileMapping(h, NULL, PAGE_READ, 0, 0, NULL);
/* XXX(hch): why are we not checking for INVALID_HANDLE_VALUE here? */
pv = MapViewOfFile(hfm, FILE_MAP_READ, 0, 0, 0);
if (!CheckSumMappedFile(pv, GetFileSize(h, NULL),
fRc = TRUE;
In my opinion this is a lot better to read than any of the variants
above, OTOH religious goto-haters will probably try to kill me now..
FWIW, I agree with him, and commonly use this goto pattern.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Exmh CVS
-----END PGP SIGNATURE-----
More information about the FoRK