Slashdot Mirror


Beautiful Code Interview

An anonymous reader writes "Safari Books Online has just posted an interview with Andy Oram and Greg Wilson, the two editors who put together the recent O'Reilly book, Beautiful Code. "Beautiful Code" features 33 different case studies about challenging coding scenarios from some of today's most high-profile developers and OS project leaders. There's also a new Beautiful Code web site based on the book where many of the authors are blogging about their work and coding practices."

3 of 286 comments (clear)

  1. The OpenBSD code is studly. by Anonymous Coward · · Score: 3, Informative

    If you haven't looked at it already, you should glance through the OpenBSD source code. It's truly remarkable how well-written it is. But I wouldn't consider it "beautiful". I think studly is a better word. It's rugged, strong, and built to handle the toughest of the tough.

    1. Re:The OpenBSD code is studly. by Anonymous Coward · · Score: 3, Informative
      You know.. I've run across a particular bug in the OpenBSD source code on at least two occasions. Specifically, NULL is being treated as a null character.

      Now, there's some bit of wiggle room for OpenBSD, since NULL can be either:

      #define NULL 0
      or

      #define NULL ((void*)0)
      (or something equivalent, like 0L, etc).

      Anyway, I presume OpenBSD uses the first definition, because otherwise a diagnostic is required when void* is assigned to a char. If NULL is defined as 0, an unfortunate coincidence allows it to be assigned to chars, since 0 is the null byte.

      However, it's still bad code. It's not portable (which OpenBSD might not care about), but it represents an ignorance of the language. There's really no reason to do something in a non-portable manner when it's just as easy to do it portably; who knows, perhaps in the future OpenBSD's C library maintainer will realize that defining NULL to be (void*)0 has advantages and the application will not build; or at least not build without diagnostics.

      If the OpenBSD developers like using a macro instead of an unadorned zero, it's easy enough to make one yourself. Though many people find '\0' to be sufficiently self-documenting, much in the way that writing NULL is self-documenting, when you compare it with writing a zero.

      In short:

      char *pointer = NULL; /* Portable, self-documenting */
      char *pointer = 0; /* Portable, perhaps not as self-documenting */
      char character = '\0'; /* Portable, self-documenting */
      char character = 0; /* Portable, perhaps not as self-documenting */
      char character = NULL; /* NOT portable! Try with GNU C library 2.5 (probably other versions too) */
      (the comments would line up nicely if I knew anything about HTML)

      gcc will whine about a conversion without a cast on the last one; that doesn't mean a cast is the way to fix it, though! Odds are it will work but there's no guarantee and it's just not pretty, especially when both of the examples above it are legal.

      If you want to see this bug in OpenBSD, check src/usr.bin/cvs/history.c.

      I have no desire to report the bug to OpenBSD, because there appears to be a much better than even chance that the reply will be hostile and childish.
  2. Re:People hate my gotos by ben_rh · · Score: 3, Informative

    That's still better as a for { } loop. Apart from it's concise variable initialisation and post-loop statement, for is while.

    for (i = 0; not bail_condition; i++) {
        for (j = 0; not bail_condition; j++) {
            inner loop
        }
        outer loop
    }