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

5 of 286 comments (clear)

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

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

  3. 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?
  4. We all use goto, we just call it something else by Anonymous+Brave+Guy · · Score: 3, Interesting

    Which is presumably why languages like Pascal, Java, Python, Ruby, etc. all support goto.

    But how many of the above languages support...

    • early function return?
    • exceptions?
    • break/continue/last/next escapes within loops?

    goto is like assembly language: it's a flexible tool, but very primitive. Just as higher level languages are more expressive than assembly, meaning we rarely have reason to write raw assembly any more, so higher level languages have developed more expressive versions of goto, meaning we rarely have to write a raw goto any more.

    I think someone needs to write a new article, called “Dogmatic structured programming considered harmful”. While block structure with the sequence, iteration and decision operations has proven a useful model for describing algorithms, other powerful abstractions for control and data flow exist. Functional programming tends to use recursion rather than iteration, for example, and many functional languages don't really model sequence in the classical sense either. Almost all modern, general purpose programming languages support the concept of exceptions, which are just a more systematic form of goto. In some programming languages, there is no explicit concept of control flow at all.

    I don't see many people who understand these extended or alternative models complaining about how we should go back to doing everything with block-structured, procedural code. We just have to learn to use different models effectively, as functional programmers found before they realised the importance of tail recursion, as OO programmers found before they learned to control stack unwinding. This is called “progress”, and is what happens with experience... unless you adhere dogmatically to the way things are done at the moment, regardless of any objective merit an alternative may have.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  5. Re:This just reminds me of my friend. by stdarg · · Score: 3, Interesting
    If you put a sentence in haiku form, it's probably not going to be pretty. Just like most "free verse" poetry often looks like
    the person just
    gave
    up
    and decided to
    B R EA K!
    the lines arbitrarily.

    Oh how dramatic. Likewise, you can't say

    My car had a flat
    tire, so I called around for
    quotes for some new tires

    and call it haiku. Well I suppose you could, but it's awful. Here's one I just found that I like:

            * I kill an ant
            * and realize my three children
            * have been watching.

    It describes a brief moment but it captures many levels of feeling. Because it's just sitting there by itself without a surrounding story, it's more forceful and clear. You can pause and think about it. If it were a line from a short story or longer poem, the subsequent lines would probably either insult your intelligence by spelling out the implications, or distract from it by moving on to a different subject. Also, as hard as it is to believe, I thought the 3 line form actually helped this haiku. When I read the first line, I half expected it to be a funny or sarcastic haiku because killing an ant is such a small thing. Then the second line introduces his children, but I still didn't see it coming that they were watching until the third line. Each line introduced a different feeling to me (humor, tension, then sadness) which makes it a very successful haiku, I think.

    There's a funny story told by Herodotus about the Spartans (http://www.greektexts.com/library/Herodotus/Thali a/eng/59.html second paragraph), which I'll quote:

    When the banished Samians reached Sparta, they had audience of the
    magistrates, before whom they made a long speech, as was natural
    with persons greatly in want of aid. Accordingly at this first sitting
    the Spartans answered them that they had forgotten the first half of
    their speech, and could make nothing of the remainder. Afterwards
    the Samians had another audience, whereat they simply said, showing
    a bag which they had brought with them, "The bag wants flour." The
    Spartans answered that they did not need to have said "the bag"

    I quote it to illustrate that some people just enjoy making a puzzle of how to express meaning in as few words as possible. If you find that story as funny as I do, then you may like haikus after all (if you find the right ones that are actually good).

    Note that my rather long-winded writing style means that I am incapable of writing good haikus myself. :)