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."

17 of 286 comments (clear)

  1. Nothing to see here by AuMatar · · Score: 4, Funny

    Yeah, thats about the amount of beautiful code I expect to see in my life time.

    --
    I still have more fans than freaks. WTF is wrong with you people?
    1. Re:Nothing to see here by morgan_greywolf · · Score: 5, Funny

      "If builders built buildings the way programmers write programs, then the first woodpecker that came along would destroy civilization." -- forgot who said it.

    2. Re:Nothing to see here by larry+bagina · · Score: 5, Funny

      If it's any consolation, you did get the coveted first typo.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

  2. This just reminds me of my friend. by Anonymous Coward · · Score: 5, Funny

    His introduction to C++ teacher told him throughout the class that his code was not "pretty" because he wasn't properly commenting. The code always worked flawlessly, but still she marked "-1 code not pretty"
    On the final project he spent a good portion of time properly commenting all of his code and ended with a commented ascii flower and the following:

    //Look at my flower,
    //my pretty pretty flower.
    //Now my code is pretty

    He was marked off "-1 Sarcasm not appreciated"

    1. Re:This just reminds me of my friend. by mrchaotica · · Score: 4, Funny

      He should have removed one syllable from the last line; then he would have gotten "+1 haiku!"

      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

  3. The problem with the book... by BlueBoxSW.com · · Score: 5, Funny

    Anyone else have laugh when they looked at the cover of the book?

    A Flock of Birds?

    To symbolize beautiful code?

    Flock-of-Birds-style code is the UGLIEST code out there!

    Used only by those who haven't learned to use case statements, build databases, or define arrays.

    Is this beautiful code???

    if(something==interesting)
        if(somethingelse==goodcode)
            if(somethingother==blahblahblah)
                if(somestupidbookcover=birds)
                    doSomethingUseful();
                else
            else
        else
    else
        if(somethingelse==goodcode)
            if(somethingother==blahblahblah)
                if(somestupidbookcover=birds)
                    doSomethingUseful();
                else
            else
        else
    end if

  4. Re:Have to say... by Anonymous+Crowhead · · Score: 5, Funny

    I have yet to see a really good example other than my own.

    I, too, am the only one I know who writes decent code.

  5. Re:Have to say... by kevin_conaway · · Score: 4, Interesting

    I always get burned at the stake when I say this, but the biggest problem with OSS that I run into is horribly ugly code with very few useful comments

    I struggle with this. When I was in school, my instructors drilled into me the importance of documentation and comments. Now that I've been in the real world, I have to say that I don't agree.

    The problem with comments is that you now have two things to maintain, the code and the comments. Often time this is OK for a single developer but for someone coming in to maintain a piece of code, often times they are hesitant to touch the comments especially if they are wrong.

    I find that (for me at least) I have the greatest success with short, composed methods that do one thing and one thing well all backed up by unit tests that test behavior and requirements, not simply that foo() returns 15.

    You might be thinking that I'm contradicting myself here because now I have to maintain both code and tests. However, I feel that the tests provide much more value in that once a test for a piece of code works, you now have confidence in that piece of code. If you miss something with the test, its a simple matter of adding a new test for that case.

  6. Re:Have to say... by Reality+Master+101 · · Score: 4, Insightful

    Now that I've been in the real world, I have to say that I don't agree.

    I have to respectfully say that if you believe this, you haven't written 1) enough code, and 2) complex enough code, to have filled up your brain sufficiently to where you can't remember what the hell you were thinking at that time. When you've reached that level of programmer maturity, THEN you will understand the importance of comments. :)

    Never mind trying to blaze the trail for programmers that come after you. I also predict that you haven't tried to unravel another programmer's crappy code.

    The problem with comments is that you now have two things to maintain, the code and the comments

    Yes. People who change code but don't update the comments should be flayed appropriately.

    I find that (for me at least) I have the greatest success with short, composed methods that do one thing and one thing well all backed up by unit tests that test behavior and requirements, not simply that foo() returns 15.

    Testing and commenting are two different subjects. Comments are not to tell you that "foo() returns 15", comments are to tell you the *context* of code, how it fits in with the overall goal of the subroutine.

    --
    Sometimes it's best to just let stupid people be stupid.
  7. beautiful code by lottameez · · Score: 4, Funny

    while (1){
    Beer b = (Beer)getBeer();
    drinkBeer(b);
    belch(BelchType.LOUDLY);
    }

    --
    Yeah? Well I think you're overrated too.
  8. Most code is beautiful at one point in time by intx13 · · Score: 4, Insightful

    Most code is beautiful at one point in time - namely, when it's first written. A decent programmer can produce some decent code that performs the task at hand elegantly. With a little work this can become beautiful. Most applications I write start out very elegant, beautiful, commented, clever, etc. - It's only after the project grows and I'm working on a file named "main4.3.a.iii.bak2.worksithink.c" that the comments turn into "// why is this here?" and the variables go from "nDBEntryCount" to "temp" and the code becomes an ugly mess.

    The real trick is DESIGNING the application in such a way that it can grow gracefully, and STAY beautiful. And that's really tough - knowing what sorts of features and requirements the future will hold is difficult. A big part of this is the language itself - I love assembly languages, and I could write some really clever and beautiful assembly code. But when the requirements change and the code needs a new feature? There goes all the carefully timed loops and cycle counts!

    Beautiful code is as much beautiful, expandable, future-proof design as it is beautiful implementation.

  9. Beware the raptors ... by Anonymous Coward · · Score: 5, Funny

    http://xkcd.com/292/

    That is all.

  10. I've become jaded by syousef · · Score: 5, Insightful

    Is anyone else jaded by these books that go on and on about why a particular techique or code snippet or methodology is "right" or "beautiful" or "the way forward"?

    I look at some of the code mentioned and yes it's neat. Some of the code snippets from these books (not just this one specifically) is either really obvious or makes me want to blow chunks because it's an over-complication or over-simplification just to demonstrate a technique which you know will be over-applied and end up in some set of corporate standards that sees it being misused. ...then there's some of the frameworks and methodologies out there that are generally worshiped as God's own code, but which when you try to use them turn out to be cumbersome, horrible, unintuitive messes. Years later this is suddenly "discovered" (EJBs I'm thinking of you!!!) and a whole new set of horrible frameworks goes through several iterations (Hibernate 1 vs 2 vs Spring persistence, Struts vs Spring MVC) where nothing is allowed to mature for long enough to have the major bugs ironed out.

    Perhaps I'm just getting old but I'm really getting tired of all this. You want to know what makes code beautiful?

    1) It does the job 100% correctly as intended.
    2) It does it as simply as possible - not so simple it doesn't work, and no more complex than it absolutely needs to be...building everything in but the kitchen sink just in case is a fool's game.
    3) It's readable and well documented enough that anyone who knows the language (or better yet a programmer familiar with a similar framework but not this one) understands it.
    4) Its easy and quick to make changes as requirements change - that means GUI tools for GUI development (What ever happened to RAD tools being the norm in the industry!? It can take a week to make significant changes to a web page in Struts or Spring MVC, where it use to take about a day to do it for the clients developed with the RAD tools of the late 90s!)
    5) It fits in well with the rest of the system. A module that works beautifully in isolation but doesn't fit in with the system can ruin the system.

    All the rest is just a bunch of consultants trying to bilk you for cash.

    Yes patterns can help, but they can also hurt.
    Yes externalizing code into config files can make a system more flexible (but you'll pay for it in readability and tracability/debugability).
    Yes aspects of the agile methodology - continual integration and test driven coding - can help but they're not the only way and there's a cost associated.
    Yes Object oriented code offers things that procedural does not, but again there's a cost and your developers better understand the language constructs.

    You need to look at each of the above as tools in your arsenal, not religious doctrine.

    Note that my recent experience is with Java/J2EE so that's where my examples come from but I've worked on dozens of languages and frameworks.

    --
    These posts express my own personal views, not those of my employer
  11. Re:People hate my gotos by garett_spencley · · Score: 5, Interesting

    Any crap programmer can write spaghetti code with or without the use of 'goto'.

    If goto were not useful or necessary then languages would have dropped it years ago when CS profs started to dread it because they couldn't teach their students properly and got tired of spitting out idiot programmer after idiot programmer who tortured them with goto-ridden spaghetti code.

    Telling people to NEVER use goto is like saying "never use a chainsaw because if you attempt to cut down a weed you'll just end up with a big mess". So what, we use a hand saw to cut down an oak tree ? There are far more elegant solutions for a lot of things that can be accomplished with goto. Conversely, there are occasions where goto makes for a more elegant solution.

    At the very least, as you put it "beauty is in the eye of the beholder". Using your own philosphy I opt for giving programmers all of the necessary tools that they may find useful, and deciding for themselves which ones to use. After all, there are some programmers out there who could write code that is 100 x more efficient and elegant using ONLY gotos in C with main as the only function than I ever could using goto-free, well designed and thought-out object oriented Java, for example.

    No matter what you do, the end result will always be the same anyway. Exceptional programmers will continue to produce exceptional code and pasta chefs will continue to produce spaghetti.

  12. Re:The OpenBSD code is studly. by garett_spencley · · Score: 4, Funny

    Hey Theo ... haven't chatted with you in a while. How's it going ? Family doing well ?

  13. The most beautiful code I've ever seen... by element-o.p. · · Score: 4, Interesting

    ...looked like this:

    not exp log srand xor s qq qx xor
    s x x length uc ord and print chr
    ord for qw q join use sub tied qx
    xor eval xor print qq q q xor int
    eval lc q m cos and print chr ord
    for qw y abs ne open tied hex exp
    ref y m xor scalar srand print qq
    q q xor int eval lc qq y sqrt cos
    and print chr ord for qw x printf
    each return local x y or print qq
    s s and eval q s undef or oct xor
    time xor ref print chr int ord lc
    foreach qw y hex alarm chdir kill
    exec return y s gt sin sort split

    Simply elegant! My younger brother sent it to me; not sure where he got it. It's Perl, by the way.

    --
    MCSE? No, sir...I don't do Windows. Yes, I am an idealist. What's your point?
  14. Stupid frameworks. by mattgreen · · Score: 5, Insightful

    Ugh, Java frameworks.

    Somebody needs to drag the people who make these things in a room, erase their memories, and make them use what they have created. Perhaps then they can start to feel how asinine they can be sometimes. It is as if they get off on how many design patterns, random XML config files, and other "best practices" they can cram into a single framework. "We're switching to using a BuilderFactoryGatewayStrategyFacade." Thanks for the heads-up guys, we were all dying to know exactly how you implemented it! (Don't forget to scatter pattern names all over your code. People have to know you're using them!) All I want to do is integrate such and such framework in with my program. But, no, I have to read the documentation that describes the problem and how exactly to use the framework. Inevitably, they begin spouting off about how "elegant" it is that you can configure exactly which IntFactory to use by hard-coding the classname in a mandatory configuration file that is prone to getting lost at deployment time. (Remember, making objects with just the new operator is a classic beginner's mistake, don't fall prey!)

    The end result is you end up with what should be a fairly simple task (like OO-relational mapping) have 400 page manuals because it ends up doing every little thing that people want to do. In the time it takes you to choose the right framework, download and install the binaries, wade through the required config files, sift through the quickstart, and actually get familiar with how it is done, you could have just written and tested the tedious JDBC code to load and unload an object from the database.

    But, why do that? There's no hype around that! You're not REALLY an enterprise architect until you have twenty different config files that need to be present just to run your product! If it is an enterprise product, it shouldn't be simple to configure!

    All of these products do serve legitimate needs. But the obsessive over-engineering that surrounds them and the religious fervor by which they are declared Good (despite violating the principle of least surprise at every turn) point to fear. A fear that the code you're writing just isn't good enough somehow. The fear that your code is too simple, too straightforward. A worry that that requirement you're meeting is mission-critical, and, mishandled, could threaten the stability of the entire system. This isn't usually the case. It would seem that Java's simplicity sort of drives its hardcore users mad after awhile. What it lacks in expressiveness, people try to make up for by inane configuration and extensibility instead of just sitting down and Getting The Damn Thing Done. Sure, the code is boring. The best code is anything but glamorous.