Slashdot Mirror


Any "Pretty" Code Out There?

andhow writes "Practically any time I hear a large software system discussed I hear "X is a #%@!in mess," or "Y is unmanageable and really should be rewritten." Some of this I know is just fresh programmers seeing their first big hunk o' code and having the natural reaction. In other cases I've heard it from main developers, so I'll take their word for it. Over time, it paints a bleak picture, and I'd be really like to know of a counterexample. Getting to know a piece of software well enough to ascertain its quality takes a long time, so I submit to the experience of the readership: what projects have you worked on which you felt had admirable code, both high-level architecture and in-the-trenches implementation? In particular I am interested in large user applications using modern C++ libraries and techniques like exception handling and RAII."

14 of 658 comments (clear)

  1. Understanding != Writing Code by PepeGSay · · Score: 3, Interesting

    It is my experience that reading and understanding code is dramatically more difficult than writing code. It gets even more difficult if it isn't your own code. Commenting, design, layuot, good structure, documentation all reduce this fact but never remove it. I've seen plently of good programmers declare code "ugly" because it had a few warts but in reality they just couldn't understand it.

  2. Re:Firefox by fimbulvetr · · Score: 3, Interesting

    IMHO, postfix takes the cake for the most elegant and readable code I've ever looked at. At one point I found an screenshot of qmail vs. postfix code in similar areas for handling some condition. The qmail code was hardcoded, had nasty loops and was just plain unbearable. The postfix version, however, was exceedingly elegant and I knew right away what the code was doing.

    I only wish firefox was 10% as elegant and cruft free as postfix.

  3. good source by belmolis · · Score: 4, Interesting

    The source for Tcl is widely considered by those who have worked with it to be unusually clean and clear.

  4. TeX by xouumalperxe · · Score: 3, Interesting

    Can't say from personal experience, but I hear that the TeX source is a truly enlightning experience. Knuth is all for literate programming, you see.

  5. Re:New Law? by Anonymous Coward · · Score: 5, Interesting

    The cruftiness of source code is directly proportional to the amount of time spent working on it times the number of people working on it.

    I think you meant the cruftiness of source code is direcly proportional to the number of people working on it DIVIDED BY the amount of time spent working on it.

    This explains why commercial source code produced by large teams of programmers under tight arbitrary deadlines tends to be sloppy. Source code produced by passionate hobbyists under the "we'll release it when it's done" deadline perspective tends to be cleaner.

  6. BOOST::Python, but you haven't seen the source??? by r00t · · Score: 5, Interesting

    At least you admit to being uninformed.

    I haven't looked either, but I happen to know that BOOT::Python often does NOT work. It has thread-related problems.

    At for the rest of BOOST, I've looked at a good chunk. BOOST makes decent programmers cry. The other follow-up post by the Anonymous Coward Xbox developer has it all correct.

    I'll add:

    BOOST is full of butt-ugly hacks. Check out the, uh, template things, named _0 through _9 being used as stand-in dummy arguments. Eeeeeew!!!

    BOOST looks easy to dumb-ass programmers, but these programmers leave bugs that are difficult for expert programmers to find.

    BOOST makes compilers run very very slow, and often breaks the optimizer anyway.

  7. A experiment by kabdib · · Score: 4, Interesting

    I wrote a Perl filter that took C code as input, and applied all kinds of "unprettifications" to it (removing comments, collapsing variable declarations, introducing random curly-brace and indentation styles, removing whitespace or adding strange whitespace). The output looked like it had been written at 3am by a hung-over ex-FORTRAN engineer who had just discovered FORTH.

    Then I demonstrated that a bunch of code checked into our system looked like it had *already* been run through this tool. After the public shaming, a couple of the offenders cleaned up their acts for a while, but they're back to their old tricks.

    These days I'm working on a project where all the devs are really, really serious about the formatting and naming conventions. Some of the rules suck, in my opinion, but there's a lot to be said for consistency.

    [In the 80s, HyperCard team at Apple used to regularly run their sources through a Pascal formatter. The code, in a friend's words, "looked ironed." Unfortunately I haven't run across any good C++ formatters.]

    --
    Any sufficiently advanced technology is insufficiently documented.
  8. Bourne Shell by Repton · · Score: 5, Interesting

    The Bourne Shell must get some kind of mention here. What do you do if you prefer ALGOL to C? Why, #define your own syntax, and thus turn boring old C code into a thing of beauty.

    --
    Repton.
    They say that only an experienced wizard can do the tengu shuffle.
  9. Re:Hello World (Newer Version) by MillionthMonkey · · Score: 3, Interesting

    Wow! That's impressive- I feel guilty now for carving so many minutes out of someone's life. Although if there were javadocs, I'd imagine that most of these disparaging comments would be within the HelloWorld class itself. The library code javadocs should always have lofty descriptions of themselves as if they're going to do brain surgery. Especially if they have empty implementations.

    If I wrote this code in 2007 I would have used "setPayload()" instead of "configure()" so that MessageBody would follow standard JavaBean conventions. That would let me easily wire one up in a Spring XML file. Maybe I could even insert AOP pointcuts somewhere. After all Hello World is the sort of application that practically screams for aspect oriented programming.

  10. Donald Knuth once apparently said by tadghin · · Score: 5, Interesting

    that he thought Bill Atkinson's MacPaint was the most beautiful program ever written. Hearing this, Andy Hertzfeld made it a priority to recover the source code from an old Macintosh diskette. He contacted me because he was a bit worried about Apple's reaction if he just released it on the net (since it was Apple property), and I advised him to get the Computer History Museum involved if he didn't want to take the risk. I believe that he donated the code, but I'm not sure what the Museum did to have it made available.

    --
    Tim O'Reilly @ O'Reilly Media, Inc. 1005 Gravenstein Highway North, Sebastopol, CA 95472 http://www.oreilly.com
  11. We just published a book called Beautiful Code. by tadghin · · Score: 4, Interesting

    So this post is perfectly timed. It's a collection of essays by leading software engineers about code they find especially beautiful.

    Andy Oram, the editor, thought it would be poor form to make a post himself, but heck, I thought: this is very relevant. The table of contents for the book can be found at http://www.oreilly.com/catalog/9780596510046/toc.h tml

    It includes essays by Brian Kernighan, Jon Bentley, Tim Bray, Yukohiro Matsumoto, Simon Peyton-Jones, and many others. The code is intended not only to be beautiful but also instructive and in many cases re-usable.

    We're hoping to build an ongoing site around the book so additional examples would be very welcome.

    --
    Tim O'Reilly @ O'Reilly Media, Inc. 1005 Gravenstein Highway North, Sebastopol, CA 95472 http://www.oreilly.com
  12. Re:Hello World (Newer Version) by ookabooka · · Score: 4, Interesting
    Oh I throughly concur. We should set up a sourceforge project to get the community involved. There are a lot of aspects of the Java language that simply aren't being utilized. Check out this program I made a few months ago. It contains every Java keyword and is (nearly) impossible to follow the logic. Again due to the lameness of the lameness filter you'll have to go to http://rafb.net/p/g46jLN20.html to see it in all its correctly-indented and colored glory, but here it is:

    public strictfp class Semantics extends Exception {
    private static volatile transient boolean l = false;
    private transient volatile static short j = 1;
    public volatile static transient Exception LogicClass = new Semantics();
    protected strictfp synchronized boolean WTF() throws Exception {
    again: do {
    l = !l;
    without: try {
    assert l ? true : LogicClass instanceof Semantics;
    continue;
    } catch (AssertionError e) {
    j++;
    LogicClass = new Exception();
    break again;
    } finally {
    switch (j % 2) {
    case 0:
    LogicClass = this;
    break again;
    default:
    break without;
    }
    }
    } while (--j > -10 ? false : true);
    throw this;
    }
    public static void main(String[] args) {
    Semantics s = new Semantics();
    try {
    System.out.println(s.WTF());
    } catch (Exception e) {
    System.out.print(s.l);
    }
    }
    }
    --
    If you are about to mod me down, keep in mind that this post was most likely sarcastic.
  13. Re:Comments lie. Code never lies. by cburley · · Score: 4, Interesting

    Only because DJB won't honor it. People have found bugs in his code, but he refuses to acknowlege them.

    As my page (to which you link) notes, these bugs are likely exploitable only in theory.

    And I've been hired (and paid well) to modify qmail code, including patching it to fix bugs as well as extending it, for years now, but nobody has even inquired as to what it'd take to fix the "Guninski" bugs that might theoretically be exploitable — at least, not so far.

    I think that's a pretty sure indication that the qmail user base does not consider those bugs to be sufficiently worrisome to fix. (I did publish a simple fix to one of the first bugs Guninski found; that fix was incorporated into netqmail. But I did that gratis.)

    I don't know offhand whether DJB has ever acknowledged any bugs in qmail. But, just as code doesn't lie while comments can, code that is reasonably well-specified, as qmail's components' interfaces are, cannot pretend bugs don't exist in it, even if authors or fanboys do, just as it can't pretend it has bugs even when claimed otherwise[*]. So I don't particularly miss djb's opinions and pronouncements on such issues, since I can read the code and decide for myself.

    [*] There's a web page out there that claims "qmail-smtpd does not detect CR LF properly on packet boundaries", which strikes me as complete and utter — as well as easily demonstrable, by simply looking at the code — nonsense. Not that it can't happen, but it'd almost certainly be due to an OS, networking, or (non-qmail) library bug. Tellingly, despite the high likelihood such a bug would result in huge numbers of legitimate emails being rejected by many qmail servers worldwide, there's no information on this alleged bug beyond somebody supposedly reporting it. That's only marginally more persuasive than saying "qmail-smtpd dropped every third email on every server running it on March 17, 2001, between 11:45 and 12:15 UTC, according to a guy I overheard in a bar the other day." Color me unimpressed.

    --
    Practice random senselessness and act kind of beautiful.
  14. The MacPaint code was donated... by Sits · · Score: 5, Interesting
    Andy mentions this topic towards the end of an interview with Bob Cringely on Nerd TV. At the bottom of this archive of NerdTV episodes is a link to episode number 1 in a variety of formats. Here's the transcript of the Nerd TV interview where Andy says

    So I was thinking of putting it on the site, Apple would send me a cease-and-desist, I'd take it down, but it would be out there then. But I was just a little too chicken. Finally Tim O'Reilly came up with the brilliant solution of donating it to the Computer History Museum as a historic artifact. Perhaps they could get permission from Apple. So that's what we did. It took a few months but [i]n August Apple approved the donation of the MacPaint source code to the Computer History Museum. This was their first major software artifact in their collection so they made a big deal of it, made a video of us, and eventually the MacPaint source code will be available from their web site to anyone in the world.

    It's just occurred to me you are Tim O'Reilly. Wow, there are still some important folks that still post on /. ! Your company gave me some free books and a T-shirt when I was in my second year of University, thanks! Many of the well known people who used to post here have abandoned it in recent years so the feel of the place has changed. The only big name I still see around here is Jeremy Alison from Samba...