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

29 of 658 comments (clear)

  1. Firefox by zBoD · · Score: 4, Funny

    Just kidding :))

    --
    BoD
    1. Re:Firefox by Rick+Zeman · · Score: 4, Funny

      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.

      And don't forget that postfix is well-commented, and with superb documentation. Re the comments about qmail, I've kept lying around in my mailbox Linus' thoughts about qmail. Couple of interesting points in there.

      On Sun, 6 Jun 2004, Kalin KOZHUHAROV wrote:

      Well, not exactly sure about my reply, but let me try.

      The other day I was debugging some config problems with my qmail instalation and I ended up doing:
      # strace -p 4563 -f -F
      [...] (deleted to bypass lameness filter)
      qmail is a piece of crap. The source code is completely unreadable, and it
      seems to think that "getpid()" is a good source of random data. Don't ask
      me why.

      It literally does things like

              random = now() + (getpid() (two less than signs deleted) 16);
      and since there isn't a single comment in the whole source tree, it's
      pointless to wonder why. (In case you wonder, "now()" just does a
      "time(NULL)" call - whee.).

      I don't understand why people bother with it. It's not like Dan Bernstein
      is so charming that it makes up for the deficiencies of his programs.

      But no, even despite the strange usage, this isn't a performance issue.
      qmail will call "getpid()" a few tens of times per connection because of
      the wonderful quality of randomness it provides, or something.

      This is another gem you find when grepping for "getpid()" in qmail, and
      apparently the source of most of them:

              if (now() - when (less than sign deleted) ((60 + (getpid() & 31)) (two less than signs deleted) 6))

      Don't you love it how timeouts etc seem to be based on random values that
      are calculated off the lower 5 bits of the process ID? And don't you find
      the above (totally uncommented) line just a thing of beauty and clarity?

      Yeah.

      Anyway, you did find something that used more than a handful of getpid()
      calls, but no, it doesn't qualify as performance-critical, and even
      despite it's peyote-induced (or hey, some people are just crazy on their
      own) getpid() usage, it's not a reason to have a buggy glibc.

                      Linus

    2. Re:Firefox by Ohreally_factor · · Score: 2, Funny

      You have the reading comprehension of something that doesn't have a very admirable level of reading comprehension. I love using constructions like this. It's a sign of a very lazy mind. It's especially fitting for an insult, since it says, "I cannot be bothered to even think up a good insult." You made me very happy.
      --
      It's not offtopic, dumbass. It's orthogonal.
    3. Re:Firefox by Sillygates · · Score: 2, Funny

      Pretty? This one even spells out IOCCC.
      http://www0.us.ioccc.org/2004/newbern.c

      --
      I fear the Y2038 bug
    4. Re:Firefox by smilindog2000 · · Score: 4, Funny

      I've personally suffered greatly from a far worse, but similar usage of a sequentially assigned number, when a random number was called for. At Berkeley, as an undergrad, many classes I needed were over-full. The stupid COBAL programmer Berkeley hired to do student-class assignments needed a random number too break ties. He took the last digits of the student ID, and students with a higher number got in, and the students with lower were kicked out (mine ended in zeros). One semester, I applied for 20 units, and only got assigned 3, but the 3 were given to a prof so horrible I immediately dropped the class.

      There's an interesting story about the difference between a Berkeley trained engineer and a Stanford trained engineer. The Stanford engineers typically finish college, and are downright shocked when they enter Dilbert Land, and for a while are unable to perform well. Berkeley grads don't seem to notice the transition, and get right to work.

      --
      Beer is proof that God loves us, and wants us to be happy.
  2. in the distance... by youthoftoday · · Score: 3, Funny

    I can almost hear the FOSS trolls approach...

    --
    -1 not first post
  3. sure by buswolley · · Score: 4, Funny

    Hello World!!!

    --

    A Good Troll is better than a Bad Human.

    1. Re:sure by dunezone · · Score: 2, Funny

      Hello World - Most written, rewritten, tested, and debugged code known to man.

    2. Re:sure by Firehed · · Score: 3, Funny

      And yet, according to some poor paranoid soul, still contains multiple security flaws. I'll wait for the proof-of-concept before starting to worry. Or update to the English 2.0 "'sup, bitches?!" version.

      --
      How are sites slashdotted when nobody reads TFAs?
  4. what? by joe+155 · · Score: 4, Funny

    "Practically any time I hear a large software system discussed I hear "X is a #%@!in mess,"

    I get that with reading the next line you get the context, but was I the only one taken aback at this seemingly blatant flame of our beloved X?

    --
    *''I can't believe it's not a hyperlink.''
  5. Hello World by MillionthMonkey · · Score: 5, Funny

    public interface MessageStrategy {
            public void sendMessage();
    }

    public abstract class AbstractStrategyFactory {
            public abstract MessageStrategy createStrategy(MessageBody mb);
    }

    public class MessageBody {
            Object payload;
            public Object getPayload() { return payload; }
            public void configure(Object obj) { payload = obj; }
            public void send(MessageStrategy ms) {
                    ms.sendMessage();
            }
    }

    public class DefaultFactory extends AbstractStrategyFactory {
            private DefaultFactory() {}
            static DefaultFactory instance;
            public static AbstractStrategyFactory getInstance() {
                    if (null==instance) instance = new DefaultFactory();
                    return instance;
            }
            public MessageStrategy createStrategy(final MessageBody mb) {
                    return new MessageStrategy() {
                            MessageBody body = mb;
                            public void sendMessage() {
                                    Object obj = body.getPayload();
                                    System.out.println(obj.toString());
                            }
                    };
            }
    }
    public class HelloWorld {
                public static void main(String[] args) {
                            MessageBody mb = new MessageBody();
                            mb.configure("Hello World!");
                            AbstractStrategyFactory asf = DefaultFactory.getInstance();
                            MessageStrategy strategy = asf.createStrategy(mb);
                            mb.send(strategy);
                }
    }

    1. Re:Hello World by smittyoneeach · · Score: 4, Funny

      This is such an exquisite example of design pattern overkill that I may require a private moment.

      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    2. Re:Hello World by Tablizer · · Score: 5, Funny

      This is such an exquisite example of design pattern overkill that I may require a private moment.

      It is the Gang-of-four Job_Security_Strategy pattern. Only the author can figure out their own code like this, and if you get paid per volume of code, you get wealthy.

    3. Re:Hello World by owlstead · · Score: 5, Funny

      /** Look, ma, no literals */
      public class Hello_World {
        public static void main(String ... args) {
          System.out.println(Hello_World.class.getSimpleName ());
        }
      }

    4. Re:Hello World by Goldberg's+Pants · · Score: 3, Funny

      I think an AC just got pwn3d! Love it!

    5. Re:Hello World by XMyth · · Score: 3, Funny

      I just read your original post.

      You're officially my hero.

    6. Re:Hello World by jc42 · · Score: 2, Funny

      What I'd do with this wonderful example is observe that it contains the literal string "Hello World!" which is its sole rigid output. Clearly we need a new feature: The program should be able to substitute a person's (or organization's) name for the "World" substring. If properly done, this can at least double the amount of code.

      And when that's working, I'd suggest adding to its power and flexibility by making it possible to pass a login id or possibly an email address to the code, and have it look up the name in any of several places. Extending the code to do a network "whois" can easily turn it into a major work of art, incomprehensible to all but a few Chosen who have been initiated into the Mysteries.

      --
      Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    7. Re:Hello World by greyseal · · Score: 2, Funny

      Think about i18n!

  6. anything in BASIC by squarefish · · Score: 4, Funny

    The more GOTOs the better!

    --
    Creationists are a lot like zombies. Slow, but powerful and numerous. And they all want to eat our brains.
  7. license by MillionthMonkey · · Score: 4, Funny

    Ooops, I almost forgot:
    /*
          Hello World
          Copyright 2002 MillionthMonkey

          Licensed under the Apache License, Version 2.0 (the "License");
          you may not use this file except in compliance with the License.
          You may obtain a copy of the License at

                  http://www.apache.org/licenses/LICENSE-2.0

          Unless required by applicable law or agreed to in writing, software
          distributed under the License is distributed on an "AS IS" BASIS,
          WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
          See the License for the specific language governing permissions and
          limitations under the License.
    */


    You're welcome, "World"!

  8. Re:The best piece of code I have seen so far by Anonymous Coward · · Score: 1, Funny

    You're wearing asbestos-everything, right?

  9. Re:New Law? by Anonymous Coward · · Score: 1, Funny

    So cruftiness is a linear function man-months?

  10. Amazing by Dachannien · · Score: 4, Funny

    "X is a #%@!in mess," or "Y is unmanageable and really should be rewritten."

    I see those all the time as comments in my own code.

  11. Re:Urban sprawl == mess by niteice · · Score: 2, Funny

    I'm pretty sure that by posting perl code any claim of legibility is out the window. ;)

    --
    ROMANES EUNT DOMUS
  12. Smell by TapeCutter · · Score: 4, Funny

    "only a smell in my opinion if they are hard to read"

    A friend of mine used to say: "Source code is like shit, it stinks when it's not yours."

    --
    And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
  13. Hello World (Newer Version) by ookabooka · · Score: 4, Funny
    I spent about an hour on this, but I think it's funny. There was no way to get this past the lameness filter, so I used nopaste: http://rafb.net/p/D1f39951.html
    Here is a little teaser though :)

    /**
    * This program is an elaborate joke about the strucuture of the Java
    * programming language. Technically you'll have to put all the
    * public interfaces and classes in their own file to get it to
    * compile. The actual code came from a slashdot post, comments were
    * later added by ookabooka.
    *
    * Originally Copyright 2002 MillionthMonkey.
    *
    * Ridiculously verbose and mostly useless comments (AKA good
    * commenting) added by ookabooka Copyright 2007.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    * http://www.apache.org/licenses/LICENSE-2.0
    * Unless required by applicable law or agreed to in writing,
    * software distributed under the License is distributed on an "AS IS"
    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
    * or implied. See the License for the specific language governing
    * permissions and limitations under the License.
    *
    * TODO:
    * Add some try/catches and a plethora of exceptions to further insult
    * Java.
    *
    * @author ookabooka
    * @version 2.41.54b_2-rc4
    * @see http://ask.slashdot.org/article.pl?sid=07/07/14/20 11208
    */
    --
    If you are about to mod me down, keep in mind that this post was most likely sarcastic.
    1. Re:Hello World (Newer Version) by Anonymous Coward · · Score: 1, Funny

      Why do I waste all my mod points a day after I get them, WHY?

      +1 Funny

    2. Re:Hello World (Newer Version) by zolaar · · Score: 2, Funny

      Confuscius says: "He who omits if-then-else statement has no choice."

      --
      One man's constant is another man's variable.
  14. Re:New Law? by MarsDefenseMinister · · Score: 5, Funny

    Cruftiness is the quality of having cruft. Cruft is the stuff that accumulates on code over time. Cruft has no odor, but it stinks. Cruft has no mass, but it weighs the code down. Cruft can't be seen, but it's ugly. Cruft cannot be young, it's always old. Cruft can't be deliberately added, it only appears when you're not looking. Cruft can't be explained to managers, except through awkward car analogies. They still won't get it because managers drive well-maintained elegant foreign cars like BMW's, which gather no cruft. Programmers understand, because their Fords and Chevys are practically built of cruft. Harley motorcycles should have cruft, but noise dissipates cruft. Cruft is mysterious.

    Cruft is never present on code which hasn't had enough work. Cruft only appears on code which has been worked too long, by too many people.

    --
    No weapon in the arsenals of the world is so formidable as the will and moral courage of free men.-Ronald Reagan