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

658 comments

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

    Just kidding :))

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

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

    3. Re:Firefox by timmarhy · · Score: 1

      not to nit pick but aren't pid's generated by random() anyway? yes yes it's crappy, but it would be just as random provided it's calling it after a new pid was created.

      --
      If you mod me down, I will become more powerful than you can imagine....
    4. Re:Firefox by Anonymous Coward · · Score: 3, Informative

      pids are sequentially assigned.

    5. Re:Firefox by Geek+of+Tech · · Score: 1

      >not to nit pick but aren't pid's generated by random() anyway?

      No. Each PID is higher by one than the previous Processes ID.

      --
      Stop the Slashdot effect! Don't read the articles!
    6. Re:Firefox by Simon80 · · Score: 0, Flamebait

      You have the reading comprehension of something that doesn't have a very admirable level of reading comprehension. It's only random the first time you call it, and apparently qmail calls it many more times than that. At the very least, the author of the code could have stored the return value in a global and used that to avoid making a system call a bunch of times on each connection. Beyond that, its usage also seemed pretty braindead (random timeouts using getpid()?). On another note, I'm willing to bet that the person asking /. this question has spent more time reading about writing code than he/she has spent actually writing code.

    7. Re:Firefox by Anonymous Coward · · Score: 0

      I wish I could mod you up. I administer email systems for a living, and I couldn't agree more. Open any qmail source file and you will see the worst code in the free world. Very obviously written by a non-programmer. I think the author stopped working on it because of nausea.

      Postfix is the polar opposite. That code is a joy to behold.

      For this reason qmail will never be updated again, and Postifx gets new features all the time.

    8. Re:Firefox by seaturnip · · Score: 1
      <<

      &lt;&lt;
    9. Re:Firefox by Octorian · · Score: 1

      PIDs are generated randomly, on OpenBSD.
      (not sure about anywhere else)

    10. Re:Firefox by Gazzonyx · · Score: 2, Interesting

      ...
      On another note, I'm willing to bet that the person asking /. this question has spent more time reading about writing code than he/she has spent actually writing code. Why do you say that? And is that a bad thing?

      I probably spend an equal chunk of time looking at code as I do writing it (then again, being an intern consultant/admin I'm always looking for a reason to write code and can never justify scratching an itch someone else, who is smarter than I, has already scratched sufficiently), I think I once spent a good chunk of time, that I should have been studying for my data structures final, reading the 2.6 kernel - and I probably take a peak at samba on every 2 weeks or so... and I'm a software development major.

      This wasn't made to sound like an attack, although it probably does; I'm really curious what prompted you to say what you did, and if you know something I don't (which is currently going off at 50/50 odds - the things I don't know could fill volumes, and the things I do, a small pamphlet, with large text).

      --

      If I mod you up, it doesn't necessarily mean I agree with what you've said, sorry.

    11. Re:Firefox by Mr+Z · · Score: 1

      Reading more about writing code than actually writing code would imply very little coding experience, or a vast desire for redundancy, or a career in software engineering research.

    12. 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.
    13. Re:Firefox by Anonymous Coward · · Score: 0

      I've never thought of that of the product of a lazy mind, but more a considerable further putdown.
      It's more a case of 'that was so ineffably crap, that it doesn't even warrant the time or effort it would take me to think of an actual example for the crap I'm describing, therefore I shall glorify it with neither."

    14. Re:Firefox by Simon80 · · Score: 1

      Well, my impression is that the OP is probably still very inexperienced, based on how they phrased the question (though I don't have significantly more experience, to be honest). It seems to me that by now, a more experienced coder would have found a hobby project that gives them the freedom to write code as cleanly as they want, and/or realized that C's error handling isn't all that bad. With throwaway code, exceptions are better, because you don't have to explicitly propagate them up the stack, but if you're handling errors robustly, there isn't any difference in effort between the two. I find allocating buffers for strings to be a bigger source of pain with C style code than the error handling would be.

    15. Re:Firefox by Anonymous Coward · · Score: 0

      Laziness is not a quality to be despised in some quarters. If there really were any hackers left on slashdot, laziness would be considered a desirable attribute.

      "He was lazier than the sort of person who is never willing to expend any effort." That should be a compliment.

    16. Re:Firefox by einhverfr · · Score: 2, Interesting

      Are there any operating systems out there that use random numbering of PIDs? Windows and Linux both number them sequentially and I would not expect it to happen otherwise.

      PIDs are not random for any reasonable value of random. For low-grade random numbers use something like /dev/urandom (on UNIX) instead. For high-grade random numbers, use /dev/random and note it may take a while to build the entropy.

      --

      LedgerSMB: Open source Accounting/ERP
    17. 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
    18. Re:Firefox by KlaymenDK · · Score: 1

      aren't pid's generated by random()? Only on OpenBSD, AFAIK.
    19. Re:Firefox by Anonymous Coward · · Score: 0

      Indentation plays a big part. Just compare some Linux (well, or BSD or Solaris) kernel code with GNU coreutils's "ls" utility.

    20. Re:Firefox by Anonymous Coward · · Score: 0

      he was deleting them to bypass the lameness filter which doesn't like it when you paste code.

    21. 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.
    22. Re:Firefox by Anonymous Coward · · Score: 1, Interesting


      Now I wish I knew postfix with that recommendation.

      Well, here goes...anecdotes from various years & code...bear with me...up front...the number of lines isn't indicative of the complexity if it's done correctly, including "vertical coding".

      I crafted a nice little VB 6 system which had about six or seven discrete processes to deal with an inbox...and finally to a GDG on a mainframe. Notification of an email message, analyze for format, take the enclosed encryption key and deal with the key ring, updated keys & other garbage, yadda yadda, then put it into the mainframe's queue.

      I ran into someone about two years later and they said it was running without a hitch. They thought about adding some extra, major features but were afraid they'd break it -- despite how everything was stitched together (separate processes for each step - pick up what was in the incoming queue, process it, and send it to the next process's queue. A template for each step - all I to insert was the brain cells of functionality. If something failed, things would at least go as far as possible and wait until things were running again. Simple, fast, reliable.

      I've got my first (and only) PL/I program with 5k lines with lots of documented procedure calls. It was supposed to convert DG's CEO word processing documents to IBM's PROFS. (CEO's internal format was a sealed box. You couldn't even buy the formats, let alone get them for free. This is even moreso when you're trying to push their box out the door. It processed more than 100'000 documents and had no problems when I turned it over. They'd taken bids from outsourced groups and the best they could get was 5-8 people, 5-8 months minimum, and a $50'000 retainer. I wrote it in less than two months and didn't have to offload my usual tasks or work overtime.

      I wrote an ASP [1] project which was almost 5'000 lines because my code is so vertical for readability. As a startup, they wanted to ensure everything would scale when things hit the real world. Someone challenged the necessity of the length until I let them have a crack at it. Defeat. It was to process the transfer of CD and DVD information between an (external) browser (like a Mac or PC) and a collection of CDs and DVDs (see? no need for apostrophes: ala DVD's) on various devices. Some of them were a few thousand discs in testing. No one could figure out how it worked so well. I used what I call active style instead of the usual passive pachinko machine's drop-thru style. (personally, I think those who code that way should be taken out back with a switch and find out if whipping their little p**p** motivates them a bit.)

      For a bit, I had to clean up these messes at client sites and thought I'd seen it all. not. I went in to deal with an ASP/VBscript mess which took some bozo 4-6 months to write and had redundant/cascading #include files. Imagine an #include file which has lots of code and another #include references that file. It was a major clusterf***. (if you don't know what that means, wait until you've got a little more time in the saddle. The way it was written meant 20'000 unique lines of code for every trip to the server(s). It's no wonder they were able to muster ten or eleven active connections, then placed another order for additional high-end servers. One day, a newspaper in Missouri had a city where 1/3 of the largest employer's workforce was being laid off, a sheriff's deputy was brought in for pedophile changes, and a ten car pileup on the interstate was on CNN and a reference was made to the web site. Their servers practically melted.

      For some reason, people seem to think vertical coding is a bad thing because pretty coding with comments makes it look so long. If it's compiled, then what is their beef? If it's something like ASP/VBScript, it's tokenized, loaded, and reused.

      It's not that tough. Vertical code with a liberal use of a consistent format and empty lines, document it with s

    23. Re:Firefox by bartjan · · Score: 1

      That depends on your kernel. There are kernels out there that use randomized pids.
      I'm using the grsecurity patch on my Linux servers, and that gives me the option to have randomized pids, and other nice things.

    24. Re:Firefox by kobaz · · Score: 1

      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.

      The place I work has gobs and gobs of legacy code. The code reminds me of the qmail code with it's hard coded stuff everywhere, loops upon loops upon loops right in the middle of main(). Hell, some 1000+ line programs only have just a main().

      It's actually been getting better throughout the years. People who really know how to program have been rewriting the cruft, organizing common things into libs, etc. The idea is that when you get a project, leave it better than your found it. New code should never have cruft.

      So here we are, in 2007. Myself and two others get a project which is a rewrite of a web interface to our system in php. I did the web frontend, one guy did the daemon backend that sends out xml data for requests, and then the other guy did the xml schemas and xml processing on the frontend.

      I started working on the frontend a little late since I was involved in other projects so I missed out on guiding the other frontend guy, and man was that a big mistake. This guy obviously doesn't know how to code properly, and he also likes to copy and paste. I found some code that handled displaying some codetables. There were four 100 line files that were identical except for one line which handled the different types of codes to be displayed... WTF!

      The application was running incredibly slow, around 40-50 seconds per request. My manager tells us we can't ship this pos, fix it. I notice that the other web guy was doing xslt on the xml. He was generating more xslt based on the xml, and then would run the second xslt on another xml file. He would then convert the xml to csv and then did a serialize on the csv into a session variable, He would then convert it into an array of objects, and then into an array of label=value to pass to my code that used a template engine. For each set of xslt processing, he would do an exec("java") from within php. Two exec's to java per page load, no wonder this thing is slow. I ripped out all of his xml code, all 1000 lines or so, rewrote it in about 300 of pure php, and now we have .2-.3 seconds per page load. Bloody hell, what was this guy thinking.

      During the process I ripped out gems like this:

      $lutfile = fopen($server_lut, "r");
      if ($lutfile) while (!feof($lutfile)) {
      $line = fgets($lutfile);
      if (preg_match("/^$customer_number/", $line))
      {
      $read_customer_number = strtok($line, ",");
      if ($customer_number == $read_customer_number)
      {
      $this->ip_address = strtok(",");
      $this->port = strtok(",");
      }
      else
      display_error_die('DEBUG!!: Bad regex in lookup_connection');
      }
      }
      fclose($lutfile);

      and this:

      $this->payments_cnt = (integer)$line;
      for ($i = 0; $i payments_cnt; $i++)
      {
      if (feof($infile))
      {
      trigger_error("Debtor Display Cache Corrupted");
      exit;
      }
      $line = fgets($infile);
      rtrim($line);
      $flag = strtok($line, ";");
      $label =

      --

      The goal of computer science is to build something that will last at least until we've finished building it.
    25. Re:Firefox by Ravnen · · Score: 1

      Are there any operating systems out there that use random numbering of PIDs? Windows and Linux both number them sequentially and I would not expect it to happen otherwise.
      I don't know about older versions of Windows, but in Vista, the PIDs are not sequential. I've no idea if PID generation is random, but child processes sometimes have a higher PID than parent processes and sometimes a lower one, without any obvious pattern in the distance from the parent PID.
    26. Re:Firefox by TheRaven64 · · Score: 4, Informative

      Are there any operating systems out there that use random numbering of PIDs? OpenBSD randomly numbers PIDs. Malloc and mmap on OpenBSD map pages into a random part of the process's address space too. A lot of work has been done to ensure that an attacker knows as little as possible about a program that they manage to compromise as possible.

      For low-grade random numbers use something like /dev/urandom (on UNIX) instead. For high-grade random numbers, use /dev/random and note it may take a while to build the entropy. By 'UNIX' you mean 'Linux.' Other *NIX platforms do not always provide two entropy sources. On OpenBSD, /dev/random is a hardware random number generator, srandom is the strong (blocking if not enough entropy is available) random number generator, urandom is the one which transparently degrades the randomness if entropy is not available, prandom is a simple psuedo-random number generator and arandom is a device for producing seeds for an ARC4 random number generator. On FreeBSD, there is just /dev/random, which is the Yarrow generator seeded periodically from the various entropy sources.

      Don't ever hard-code /dev/* into your program unless it's one of the devices specified by POSIX. Last time I checked, this limited it to /dev/null, /dev/console and /dev/tty.

      --
      I am TheRaven on Soylent News
    27. Re:Firefox by vrmlguy · · Score: 2, Insightful

      I've been coding for 35 years. The only code that I've written was written by (surprise, surprise) me. The code that I've read has been written by hundreds, if not thousands, of people, who out-number me considerably. But wait, you say, you were talking about reading about writing code. However, much of the code that I read is at on-line sites like Perlmonks and O'Reily and even MSDN, where each bit of code is accompanied by detailed explanations of why it was written the way that it was. If that's not reading about writing code, then I don't know what is.

      --
      Nothing for 6-digit uids?
    28. Re:Firefox by aetherworld · · Score: 1

      I think the Eclipse core code is rather pretty.

    29. Re:Firefox by ardle · · Score: 1

      That's basically what he said. Notably, he said "sign of a lazy mind", not "product" ;-)

    30. Re:Firefox by Gen.Anti · · Score: 1

      Been there...

      1. More code = better value for a client
      2. More standards involved = better software
      3. More frameworks involved = a diminished threat of available hardware and software being not fully exploited

      End sarcasm. It's just important to be reasonable about which parts of a system need to be modular, flexible, configurable etc. Pushing craziest XSLT applications in the strangest places in a system doesn't make the program better. It however makes it big and and complicated, which, I guess, often makes one more popular with clients or management (also see 1.).

    31. Re:Firefox by Maniac-X · · Score: 1

      Apache is very well written, as is Konqueror.

      --
      (A)bort, (R)etry, (I)gnore?_
    32. Re:Firefox by jgrahn · · Score: 1

      Well, my impression is that the OP is probably still very inexperienced, based on how they phrased the question

      That wasn't my impression; the question was well put. It's a valid question from any programmer, I think.

      It seems to me that by now, a more experienced coder would have found a hobby project that gives them the freedom to write code as cleanly as they want

      From the question, you can't really say if the OP does this or not. But is it relevant to the question? I have hobby projects which have elegance as a primary goal (I am proud of some of them, others suck). But that doesn't answer the question if it's possible for groups of people, working for money, in a large project to end up with really good code.

      and/or realized that C's error handling isn't all that bad.

      Personal opinion: it's good enough for C, but you can't write really good C++ code without exceptions.

    33. Re:Firefox by profplump · · Score: 1

      While I don't disagree about Bernstein's personality or coding, um, "style", it should be noted that many of his "random" calls noted above are really intended to be "unique" not "random" despite the variable name. Time + pid is a reasonable way to ensure that you get a unique file name, at least on systems that don't recycle PID's more than once a second. If you actually generated a random file name it would probably be unique, but it's not guarateed to be so, which requires file locks, which is complicated on NFS for example.

      Likewise the timeout handling is another place where "random" doesn't mean random so much as "unique amongst currently running qmail processes" to avoid having more than one concurrent process timeout at exactly the same time. getpid() is cheaper than rand() and doesn't eat from your entropy. It's poorly named, and without comments it's most certainly unclear, but it's not necessarily bad from a functional standpoint.

    34. Re:Firefox by sudog · · Score: 1

      What the fuck difference does it make whether an OS does or does not produce random pids for children? The code is supposed to be portable, and he's making the assumption that the pid is a source of randomness.

    35. Re:Firefox by seaturnip · · Score: 1

      How did I manage to post a post containing nothing but those characters then? He was deleting them because he didn't know the HTML entities.

    36. Re:Firefox by Anonymous Coward · · Score: 0

      ptys are also POSIX, but perversely enough the naming of them does not follow a standard. POSIX/SUS is better than nothing, but it's otherwise not a very good spec.

    37. Re:Firefox by Anonymous Coward · · Score: 0

      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.

      Universities procedures like class assignments are so opaque. How did you ever find out why you didn't get the classes you wanted?

    38. Re:Firefox by slamb · · Score: 1

      PIDs are generated randomly, on OpenBSD.

      Still an unbelievably bad idea to use getpid() as a source of randomness. Portability and readability aside, it reminds me of this xkcd comic:

      int getRandomNumber()
      {
      return 4; // chosen by fair dice roll.
      // guaranteed to be random
      }

      However random the method for generating the pid was, it's only chosen once over the lifetime of the process. So how many times does qmail use the same random number?

    39. Re:Firefox by Brett+Johnson · · Score: 1

      The author of the code is not assuming that getpid() returns random numbers.
      I am not familiar with the code, but even so, it is obvious to me what it is doing.
      The timeouts are constructed to avoid resource contention or "chunky" execution
      when dealing with another running processes in the qmail suite.

      Suppose Process A, B, and C all want to access a specific resource. If they all
      try at once, one will succeed and the others will either fail or block. If they take
      a non-blocking approach, they may decide to wait some amount of time, then
      reattempt the acquisition. If they all wait 5 seconds, then try again, they will
      be in the same situation of all trying to acquire the resource at the same time.

      More generally, suppose the system is set up with many subprocesses (and I
      believe qmail is such a system). All processes sleep for some amount of time,
      then wake up to see if there is any work to do. If all processes slept for the
      same amount of time (say 60 seconds), but they were not started up in a staggered
      fashion, then every 60 seconds the CPU would suffer a hit as all the processes
      try to wake up at once, to see if there is any work to do.

      The code is using the pid of the process to skew the timers so that each process
      sleeps (or waits or whatever) for slightly different lengths of time . This helps
      spread out the background processing more evenly. This differences don't need
      to be completely random or unique, they only need to be "usually" different.
      In this case getpid() is good enough and faster than a call to random().

    40. Re:Firefox by brantondaveperson · · Score: 1
      But the proper way to write server code is not to wake periodically to see if there's any work to do, but to enter alertable wait states of various kinds so that the OS wakes you up when it knows that it has work to give you.


      This is similar to either waking every minute to look at the time, or using an alarm clock instead :)

    41. Re:Firefox by StrongAxe · · Score: 1

      Suppose Process A, B, and C all want to access a specific resource. If they all try at once, one will succeed and the others will either fail or block. If they take a non-blocking approach, they may decide to wait some amount of time, then reattempt the acquisition. If they all wait 5 seconds, then try again, they will be in the same situation of all trying to acquire the resource at the same time.

      This is the whole POINT of using random numbers. If they wait for random times (for a suitably adequate definition of "random"), the likelihood of a second collision after the first collision is quite small. However, abysmal random number generators will not guarantee this. In particular (getpid()&31) will cause two processes to collide about 3% of the time. Furthermore, any two processes that collide with each other will ALWAYS do so with each other, since getpid() will not change for the lives of the processes.

      This differences don't need to be completely random or unique, they only need to be "usually" different. In this case getpid() is good enough and faster than a call to random().

      Faster? How so? I don't know of any systems in which a divide instruction is slower than an operating system call.

    42. Re:Firefox by fimbulvetr · · Score: 1

      Have you ever seen a busy mail server? Using pids and time is absurd for such a combo.

    43. Re:Firefox by WGR · · Score: 1

      Good experienced programmers read far more code than writing it. Most actual programming is either modifying existing software or replacing existing software by nw software. Both of these activities require reading code to understand what actually happens in the existing system,

          Good systems have code that allows easy modifications and makes few assumptions. Design decisions are either transparent in the code or well documented in comments. So reading other people's code helps you write good code, since you know what kind of code is easy to read and modify and what kind of code is sludge in the engine of progress.

    44. Re:Firefox by Simon80 · · Score: 1

      Sure, I agree with you, but notice that my wording was reading about writing code, not simply reading code.

    45. Re:Firefox by Anonymous Coward · · Score: 0

      Well, that was useless, not to mention self-serving and arrogant. Oh, and off-topic. Also, I suggest that you have a cup of coffee or something before you post next time. Toward the end there, you weren't making much sense.

    46. Re:Firefox by ikegami · · Score: 1

      Not on my system (WinXP)

      >echo off & (for %q in (1 2 3 4 5 6 7 8 9 10) do perl -le"print $$") & echo on
      2816
      3964
      2920
      1188
      2656
      2196
      2884
      3120
      2116
      3160
    47. Re:Firefox by smilindog2000 · · Score: 1

      One of my best friends new the guy. He had and argument with the guy about how fair that code was. According to the COBAL programmer, his code did a good job of minimizing hardship by maximizing the number student's who could attend classes they want. The fact that it was always the same students who got screwed, and the same students who got all the classes they want seemed irrelevant to the COBAL programmer. Apparently, he got paid more for improving the over-all measurement.

      --
      Beer is proof that God loves us, and wants us to be happy.
    48. Re:Firefox by Gorshkov · · Score: 2, Insightful

      Reading more about writing code than actually writing code would imply very little coding experience, or a vast desire for redundancy, or a career in software engineering research.
      And spending more time reading code can go a long way into impressing on somebody the importance of writing it clearly in a manner that makes it maintainable and easily understood.

      So many programmers in the world need to have their keyboards substituted for a pair of reading glasses so they can learn some basic competence.
    49. Re:Firefox by Bandman · · Score: 1

      DJB is the kind of guy who would say that anyone using a kernel which numbers PIDs sequentially is doing it wrong.

    50. Re:Firefox by baldass_newbie · · Score: 1

      Alright, it's now been used twice...what the fuck is "COBAL"?
      Is that like a subset of "COBOL", you twits?

      I can see why the OP was always getting screwed and it had nothing to do with the last digit of his student ID and everything to do with his not even being able to name a core five-letter programming language correctly.
      That you even graduated with a CS degree is nothing short of a miracle.

      --
      The opposite of progress is congress
  2. in the distance... by youthoftoday · · Score: 3, Funny

    I can almost hear the FOSS trolls approach...

    --
    -1 not first post
    1. Re:in the distance... by Anonymous Coward · · Score: 0

      Don't forget Unix zealots!

    2. Re:in the distance... by nschubach · · Score: 1

      Well, it's not like Microsoft is going to be providing evidence of any kind of code in the near future... good or bad. So you have two choices. Open Source projects, or... um, Open Source.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    3. Re:in the distance... by Anonymous Coward · · Score: 0

      Sure there is. If you trust this site..
      (@ the leaked win2k code)
      http://www.kuro5hin.org/story/2004/2/15/71552/7795

    4. Re:in the distance... by daeg · · Score: 1

      I like to think MS's code is neat for the most part. When you, a lone programmer, have 17 managers that review your code, you WANT it to be neat if only to shut them the hell up. I would go crazy having to explain why I have two spaces instead of one in my code to 17 different people.

    5. Re:in the distance... by janrinok · · Score: 1

      I'm not sure how anyone can see MS's code - it is all closed source, is it not? - unless you are employed to write such code. In which case, don't you think that such a person might be just a little bit biased regarding the beauty of the code, especially if the claims cannot be verified?

      --
      Have a look at soylentnews.org for a different view
    6. Re:in the distance... by afidel · · Score: 1

      Actually, LOTS of people have seen various pieces of MS code. From partners who have access to certain pieces under NDA (such as Citrix which had full access to the NT3 codebase while writing Winframe) to governments that have forced Microsoft to allow auditing of certain pieces of code (again under NDA). I think the general consensus I have heard is most of it is typical commercial code, neither great nor horrible.

      --
      There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
    7. Re:in the distance... by janrinok · · Score: 1

      I will have to accept the opinions given but my comment was not issued as a challenge or troll. It was merely to point out that very few people write code that they, themselves, think is poorly structured or inadequately commented. Many will think that their code could be improved but that the time taken to do so would not justify the purely aesthetic improvement; if the code works then, to some, that is sufficient. The subsequent maintenance task, or the reuse of the code, is of secondary consideration. So for someone to say that the code that they have written is well structured and of a high quality cannot be taken at face value. It is only when, as you point out, lots of people have viewed the code and reach a consensus that one can accept the view as a reasonably qualitative assessment. In fact, your opinion of the code and daeg's seem to differ. Daeg thinks it 'neat for the most part' while you say it is 'neither great nor horrible'. You may both be correct as the assessments are subjective.

      --
      Have a look at soylentnews.org for a different view
    8. Re:in the distance... by Anonymous Coward · · Score: 0

      I've heard from certain university sources that the NT kernel code, which is C with a bit of platform-specific assembly code, is amongst the best they've ever seen: extremely well designed, clearly specified, well written, well and thoroughly commented, etc. The rest of the Windows code, including some kernel-mode code that isn't part of the kernel proper, supposedly ranges from excellent to poor, and is mostly C++ rather than C.

    9. Re:in the distance... by Surt · · Score: 1

      I've seen some windows and some office code. Neither was impressive. Lot's of fun things like locally duplicated bugfixes for things that should have been refactored, spaghetti code, all your usual favorite kinds of code that happen to large organizations unwilling or unable to take seriously the idea of repairing their core code infrastructure.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    10. Re:in the distance... by the+not-troll · · Score: 1

      Before they come, let me troll for closed source:

      A company I worked for started as an Open Source company for server side data processing during the dot com boom. However, we often got complaints about how badly the code is written (hey, how else should we make sure that nobody steals it?). But the last straw came when we got a complaint from the ESRB because some old lady saw our code when her son hacked it and fainted because she saw all those variables called "f*ck" and "sh*t" (I still doubt that they legetimately could do that).

      So we closed the source to prevent a lawsuit. This has obviously helped, because we stopped receiving complaints how bad the code quality was, so it must have improved. Accordingly, our software was seen in a positive light, giving us enough profits to survive the dot com bust. Of course, some complained that they couldn't read the code, but we've had it with those Open Source Zealots after they nearly caused us to get sued and go bankrupt (hey, so we copied code from the GNU project - who cares?).

      However, we soon found a new problem. See, we didn't only sell our main product, but also certain libraries which enabled the main product to be embedded in other software. Of course, we didn't sell those libraries directly because they had no GUI that way and we didn't want to be sued, so we only sold them to those who specificially asked for them and sued everyone under the DMCA who mentioned their existence. However, some hackers had a look at the symbol tables and complained about the interface being so unclear. So we started stripping all symbols from the libraries and all our executables (yes, I know we were idealistic in not doing so in the first place). However, the work invested there, including writing a script which sent the executables to a special server with an early web 2.0-application doing the stripping, proved useless as the sale of the libraries was discontinued due to lack of demand.

      The same time, some other problems showed when users complained about the clunkyness of the GUI of our main product (I must say that we were lucky not to have used a command line interface - just imagine the complaints of people who didn't know of the existence of the command line about how hard it is to use). We first thought that it might have something to do with the standard Java GUI, so we ported the application to .NET (which meant a complete rewrite, but without the source, we didn't have another choice - not that we would have done anything else even if we kept it, because if we had the source, the code would be so ugly we couldn't understand it and would be forced to rewrite it). Of course, this meant that users of MacOS or Linux couldn't use it, but they didn't buy it in the first place: Our userbase was primarily Windows, which was also why we didn't offer the MacOS and Linux versions on our web page, because the work needed to add two more option buttons besides the windows one would have been inappropriate considering how little the market for the other versions was.

      However, the complaints continued. Experienced by our experience with the source code, we decided that we needed to overhaul our user interface in a similar way. So we started writing our second-to-last version by removing all text and replaced it with images which blinked and changed when you pressed one. Some then started selling it as computer games, granting us significant revenue. However, our management - fearing another run-in with the law and being disconcerted by the complaints failing to cease in spite of this superior user friendlyness - wisely decided that our efforts were insufficient and rewrote the user interface such that it was perfectly clean and predictable. Of course, there was no way we could make it work with our back-end code, because we lacked source code or documentation, but the customers finally were satisfied, as evidenced by the lack of complaints.

      Today, the company is bankrupt, due completely unrelated lawsuits in which we failed to

      --
      In Soviet Russia, government controls corporations.
      In Capitalist America, corporations control government.
  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?
    3. Re:sure by Koiu+Lpoi · · Score: 1

      Probably the prettiest language out there is lolcode.
      Here's hello world:

      HAI
      CAN HAS STDIO?
      VISIBLE "HAI WORLD!"
      KTHXBYE

      It doesn't get more beautiful than that.

    4. Re:sure by StarfishOne · · Score: 1
      I really like the LOLPythonl variant.


      The Fibonacci numbers example on that page is just great :))

      GIMME EACH I IN UR FIBBING WIT N OK?
      VISIBLE I

      Brilliant stuff!
    5. Re:sure by Anonymous Coward · · Score: 0

      Now compiling "Hello World" -47 Warnings -13 Errors

  4. New Law? by VGPowerlord · · Score: 5, Insightful

    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.

    Has someone created such a law before?

    --
    GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
    1. 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.

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

      So cruftiness is a linear function man-months?

    3. Re:New Law? by Myopic · · Score: 1

      I agree but when you write it down as a formula, make sure your "number of people" variable subtracts one, by which I mean only two or more programmers will tend to produce crufty code.

      so for
      n = number of programmers; n >= 1
      tn = the time spent by each programmer indexed by n
      T = t1 + t2 + .. + tn
      T/n = of course, average time spent
      C = cruftiness
      K = constant coefficient

      the formula might be something like

      C = K * T/n * (n - 1) = KT - KT/n

      Which basically says that cruftiness is a product of time, minus a little bit because programmers tend to uncruft other people's stuff, but only a little bit, and less when he is working with more and more stuff written by other people.

      It's interesting to note that by this formula if n=1, when there is one programmer, there is no cruftiness. If you as an individual allow cruftiness into your code, you might modify it to include cruftiness over time.

      Also note that when T = 0, when no code has yet been written, then there is not yet any cruftiness.

    4. Re:New Law? by thePsychologist · · Score: 1

      Multiply that by the age of the language. In the beginning (of computers), there was assembly and some very simple languages were created like Basic. These simple languages were enough for people to write decent programs without having to drudge through assembly.

      Languages got more and more complex with additional features and we end up with C and other things like that. Hackers were very up there with new features and more real world power (of course all useful languages today in one sense are equally powerful, Turing-complete).

      However, programmers didn't know too much about how to design an aesthetically pleasing language. You can see as time goes by how languages have become more and more readable by design.

      Yes, you *can* write elegant code in Perl. But it's easy to write terrible looking code. Recently with languages like Python and Perl, the elegance of programming has been built into the language, both with the formatting of the code itself and how the language can be used.

      So pretty source code can be written in many languages, but the effort to do so increases dramatically and becomes impossible with so many developers unless the language itself enforces elegance.

      --
      "What lies behind us, and what lies before us are tiny matters compared to what lies within us." Ralph Waldo Emerson
    5. Re:New Law? by Nazlfrag · · Score: 1

      Shouldn't many eyes make all cruft shallow? As noted by a sibling, it seems arbitrary deadlines are the real cause of cruft, not just the number of coders. Also, the code by 1 programmer will only be cruftless to him. Others will see other ways to approach problems, and consider the firsts methods cruft. So how about, cruft is in the eye of the beholder?

    6. Re:New Law? by hobo+sapiens · · Score: 5, Insightful

      No, submit it to foldoc.org. Also, it needs a corollary, which we'll call The Hobo Tangent: Enhancements are the root of all evil.

      Let's cue the scene...

      An application's code is written by a competent developer and is nice and clean and pretty. He releases the application, and its a success. He gets moved to the next high profile project, and then the application's code gets handed to the maintenance droid, you know, the new guy on the team who shops *exclusively* at Whole Foods, listens to Nickelback, and has stacks of People magazine in his cubicle. He took a semester of VB while at Party U pursuing a liberal arts degree, and so he is a programmer too, you know!

      Then, some PM or business manager who probably gets paid more than the original competent developer gets some bright ideas to make the application do things it never was intended to do. Let's say its a scheduling tool. Well, hey, they say, let's make it ALSO have an RSS feed! And a document repository! And a calculator! Can can you create some little project management software to work with it? A requirements document gets written, and a timeline is assigned.

      Everyone does their little piece, totally oblivious to the steaming pile of dung spaghetti they are turning the application's code into.

      Two years later, the original developer gets called to fix a problem that is simply beyond the dimwits holding the code. Poor guy doesn't even recognize his own application, and for him, it's like getting called to the morgue to ID the remains of a family member.

      And that, friends, is why people complain about bad code.

      Does this post make me sound cynical?

      --
      blah blah blah
    7. Re:New Law? by epiphani · · Score: 1
      Ok, my turn to chime in. I'll give an example of two packages that do exactly the same thing, that - from a code perspective - are examples of good and bad.

      The good: Dovecot IMAP server. Its clean, well abstracted, easy to read. Everything seems to have its place.

      The bad: Courier IMAP. I won't say much about Courier, I'll just let this one example, seen everywhere throughout that package, speak for itself:

      unlink(strcat(strcat(strcpy(q, dir), "/"),de->d_name));
      I work with email packages a lot. I can rewrite our pop3d in a day, but if i want to make one change to courier, it takes me a week. No abstraction, no organization, and uglyness such as above.
      --
      .
    8. Re:New Law? by jalben · · Score: 1

      I think you're formula is exceptionally true. The trick lies in that K co-efficent. If K is the skill of the programmers involved, then it's verifiable. Of course, if we could figure out a way to assign numerical grades to coding skills, my pay rate might drop significantly :(

    9. Re:New Law? by Ajehals · · Score: 1

      Does this help?

      n = number of programmers; n >= 1
      f = feature creep
      a = arbitrariness of deadline
      tn = the time spent by each programmer indexed by n
      T = t1 + t2 + .. + tn
      T/n = of course, average time spent
      C = cruftiness
      K = constant coefficient

      C = (K(T/n)f(n-1))a = ((KTf)(KT/n))a

      I though feature creep was important in calcuating cruftiness (nice feature request though.. :) ), although maybe I should have looked at a way of averaging additions and removal of features somehow (the removal of a feature tends to increase cruftiness in complex applications and eases it in simple ones (IMHO)) and I need to define arbitrariness somehow.

      By the way - posted at 4am local time and I think I have screwed something up so maybe we should factor in when the code is written too (OSS projects that are contributed to by hackers at 4am may be more crufty than those worked on by programmers during working hours... Oh and the language has a bit of a bearing too.

    10. 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
    11. Re:New Law? by JAFSlashdotter · · Score: 2, Interesting

      I'm not 100% sure if cruft is a layman's term for Design Debt, or if Design Debt is just one type of cruft, but they're definitely related.

      --
      We apologize for the preceding message. All those responsible have been sacked.
    12. Re:New Law? by TheRaven64 · · Score: 1

      I'd second Dovecot as an example. When I started using a small number of the suggestions from the author on how to write good C code, it dramatically improved my code quality. I don't use all of them because most of the time I work in Objective-C, and only dip into pure C when I need speed at the cost of abstraction.

      It's worth noting that Dovecot follows the OpenBSD coding conventions. If you want an example of good code, take pretty much anything from OpenBSD. The userland code is incredibly clear, and the kernel is the only one I've read that I can start reading a random source file and know what it is doing and why. The NetBSD kernel is nice in places, but very crufty in others, and Linux code just makes me want to scratch my eyeballs out whenever I have to look at it. In OpenBSD, if you try to commit ugly code, you suffer the wrath of Theo, which is not something most people want.

      I find a good test of code clarity is to strip the comments and then try reading it. If the code still makes sense without the comments, it's good. Comments shouldn't be telling you what the code is doing so much as what other bits of code that you are not looking at will be doing with this code, so you can understand the 'why'. If you can't understand the 'what' without comments, then the code is probably unmaintainable.

      --
      I am TheRaven on Soylent News
    13. Re:New Law? by Anonymous Coward · · Score: 0

      I've never printed out anything a slashdotter has written before; but, your comments on cruft are so dead on! This is going on my wall at work. Full credits given, of course.

    14. Re:New Law? by Anonymous Coward · · Score: 0

      That almost brought tears to my eyes.

    15. Re:New Law? by hobo+sapiens · · Score: 1

      It perfectly describes about three or four things I have designed and what happened to them over time, and I know I'm not alone.

      Experience is indeed the best teacher, trouble is, it often leaves you too bitter to care.

      --
      blah blah blah
    16. Re:New Law? by Brett+Johnson · · Score: 1

      When I started using a small number of the suggestions from the author on how to write good C code, it dramatically improved my code quality.
      Where might I find these "suggestions" of which you speek?
    17. Re:New Law? by midnighttoadstool · · Score: 1

      My theory is that there is too much division of labour and no one believes in property any longer : so we build bits of things for non-personal entities whose representatives torture us with their praise and saturday barbeques.

      The answer might be a certain kind of independence and self-sufficiency. But the laws in my country, and most nearby, are increasingly stacked hugely against such marvelous aspirations.

    18. Re:New Law? by Arapahoe+Moe · · Score: 0
      Ah, I love Slashdot on the weekend because I have the time to dig around and locate grandiose pieces of self-aggrandizing claptrap for rebuttal.

      Let's cue the scene ....

      Another small-minded developer is surfing slashdot on the weekend when he finally spots a story that he can comment on and announce to the world how great and totally awesome he is. And how terrible everyone else involved in building and maintaining a piece of software is.

      And that, friends, is why people complain that developers don't have a clue about anything.

      Does this post make me sound cynical?

      That part about "maintenance droids" was great. Oh and that part about "Party U", oh haha. Good ones. Oh, lord, "dung spaghetti" bwahahaha.

      Your post is very clear about the type of person that you are. And people like you are the ones who get their jobs outsourced. Why would anyone outside of development want to work with someone like you, when they can work with someone in India who couldn't possibly be such a pain in the ass?

    19. Re:New Law? by TheRaven64 · · Score: 1

      There are two text files on the Dovecot site. One is about secure code and the other is about writing good C. Unfortunately, the one I can't find is the more useful of the two.

      --
      I am TheRaven on Soylent News
    20. Re:New Law? by hobo+sapiens · · Score: 1

      "Your post is very clear about the type of person that you are."
      Ditto. Beside being a troll and a mongoloid, you appear to be an inbred elementary school janitor with a millimeter peter and a Napoleon complex to match.

      Look: I don't come to your job and kick your mop bucket down the hall, so go back to your trailer park and go troll elsewhere. The good news is that you don't have to worry about someone outsourcing your $5 / hour job, so you can continue to live in your mother's trailer and wank on llama pr0n all day. Of course, once it is found out that you like to fondle the little boys at school, you'll be doing hard time in the retard room at the state pen.

      Speaking of your mother, is she still so fat she oozes mayonnaise?

      --
      blah blah blah
    21. Re:New Law? by Arapahoe+Moe · · Score: 0
      Hey Smykowski, don't worry, it's not all scumbags down at the state unemployment center. You might even learn something from the experience you self-important ass clown.

      I would gladly expand on your obvious intellectual and social deficiencies further if I thought it would help .... sadly, I think my criticism must remind you of all your schoolmates who made fun of you growing up. It sucked you dry didn't it? You HAVE to be intellectually superior to all of "those" people, right? RIGHT.

      Turns out you don't have the market cornered on intelligence, pal. You just might have the market cornered on petulant ass-holery though.

      Now, run along with your friends, Jimmy Neutron. I'm done babysitting.

    22. Re:New Law? by Inthewire · · Score: 1

      Or...genius shits out a masterpiece, every attempt to kill the flies fails, the owners of the latrine call the rectum that dropped the nugget hoping his description of the steaming heap will be enough for the exterminators to plan an efficient extermination.

      --


      Writers imply. Readers infer.
    23. Re:New Law? by Anonymous Coward · · Score: 0

      oooOOoooo, a pissing contest with someone who has to pee sitting down. I just hope the gerbil doesn't get out, you nasty little troll.

      I see you don't mention your mother. Is it because you were raised by two dudes who like to sleep in the same bed? Then again, you don't see many of them at the trailer park. Maybe your mother is also your sister and grandmother, that would at least explain the low double digit IQ.

      I do think it's impressive that you have figured out how to use a keyboard, especially considering you haven't mastered the art of sleeping through the night without pissing yourself. When you wet your bed, that makes for some nasty bedding material. You know what I mean, the newspaper on the closet floor -- it has to be changed once a week when the stench makes your mother|sister|grandma's node bleed. It sure beats the diet of boiled roaches they fed you when you were just a larva. Your mother just had to come out of the closet once, but you, well, you have to come out every morning to go to the janitor's closet. But then again, if I looked like you probably do, I'd stay in the closet all the time, too. Don't want to scare the children, there, Quasimodo.

      Well, here's to you choking on a turd today! Cheers!

    24. Re:New Law? by Arapahoe+Moe · · Score: 0
      I wouldn't call it a pissing contest, Mr. AC. I would call it shitting all over the "i'm so teh awesome" attitude of "hobo sapiens". It's just so fucken lame.

      sigh

      Am I speaking to the falafal one himself here? All this talk of penises and gay baiting sure reminds me alot of that "No Spin" asshat. Eff off, shitbag.

    25. Re:New Law? by Anonymous Coward · · Score: 0

      shitbag

      Oh, is it time for your lunch already? Did you bring yours? I hope you like chocolate pudding.

      There's a reason for the gay baiting:if you want to catch homo you have to use the right bait. It's oK,if you like to servise other guys you should just own up to it. And then u cn blow me.

      I think I know the worst part about being you, well besides the overpowering stench, the sub-dolphin IQ, and the fact that you are inbred: getting teabagged by your mother's dog every morning when you wake up on your piss-soaked bed of newspapr every morning. Then again, that's probably the closest you've had to a toothbrush for a long time.

      Your grammar sucks, and, you don't say nothing meaningful. I guess if nobody, not even my own mother, liked me, I'd be angry too. Maybe you could do the world a favor and choke on the frozen turd on a stick you'll have for lunch today today.
    26. Re:New Law? by Anonymous Coward · · Score: 0

      hahahahahahahahahaha

      I just noticed your comment history. You say you are of indian heritage. Well, then I have some names that your tribe could call you!

      Little jimmy big stench
      sleeps with men
      shame of mother
      sits on gerbil
      tribe faggot
      plays with dongs
      dances with men
      little dumb ass
      brown tooth dick eater
      takes it in the wampum

      Oh, I could just go on and on. You're such an easy target! Morons like you don't come along too often, and you and I are gonna be great friends! I wish your website worked, but it appears even the people hosting your site (http://fsk37.no-ip.org/portal) couldn't take your abject stupidity.

      Now run along, or I shall taunt you yet again. I'll be watching you, sluggo.

    27. Re:New Law? by Arapahoe+Moe · · Score: 0
      Your grammar sucks, and, you don't say nothing meaningful.

      Are you effing kidding? Do you know what a double negative is?

      There's a reason for the gay baiting

      Man, you are a waste of life, huh? Are you a religious nut or just a run of the mill hateful AC? Stop being a pussy a post under your nick, cock knocker.

      Maybe you could do the world a favor and choke on the frozen turd on a stick you'll have for lunch today today.

      I'm not that important shithead. I'm sure the world could give a rat's ass.

    28. Re:New Law? by Arapahoe+Moe · · Score: 0
      Morons like you don't come along too often, and you and I are gonna be great friends!

      But you won't post under your nick, tenderfoot. How can we play cowboys and indians if you won't be a fucken man? I can be Chief Daddy Longsack, the Indian with the gigantic nutsack, and you can be Captain Dickface, the whack job who likes to fuck people in the ass with his nightstick. Sound fun?

      I'll be watching you, sluggo.

      Really? Fine.

    29. Re:New Law? by Anonymous Coward · · Score: 0

      haha, a gay indian! Now that's funny! A descendant of Chief Suckanut who lives next to lake Pokeabutt! I'll bet you like it all kinds of ways, you flaming injun!

      Your mother is a cactus and your father never wastes any part of the buffalo, including teh cock! I'll bet that's wyh you have an affinity fer them so much! LooooOOooooOOOOooooOOOOOOoooooser! Waste of skin!

    30. Re:New Law? by hobo+sapiens · · Score: 1

      heh, it sure is fun watching you slug it out with a bunch of ACs. Looks like trolls beget trolls. They are killing you, though, son, and you'd better quit before they finish the job.

      --
      blah blah blah
    31. Re:New Law? by Arapahoe+Moe · · Score: 0
      Finish what job? Are you people fucken kidding me?

      Some 1's and 0's on a computer screen are really going to fucken affect me. That such a thing occurs to you as anything other than being completely farcical, is fucken disappointing.

      Looks like trolls beget trolls.

      Again, who the fuck talks like that? Certainly not any real fucken person having a real fucken conversation. That's exactly my point about you fucken people. How can anything you express in this medium, in that fucken way, create any sort of real dialogue or impart any sort of understanding? It's not fucken english that anyone anywhere uses in real life and it's not fucken rocket science. It's fucken retarded. It's too bad that just about everyone on this site was neglectful of their education and denigrated the liberal arts, as if it were some sort of nazi star of david, such that they cannot comport their arguments in a way that is persuasive to any real group of people.

    32. Re:New Law? by Arapahoe+Moe · · Score: 0
      A descendant of Chief Suckanut who lives next to lake Pokeabutt!

      Now that is funny. The rest of it is a little too Bollywood or Michael Richards but whatever.

    33. Re:New Law? by Anonymous Coward · · Score: 0

      "cannot comport their arguments in a way that is persuasive to any real group of people"
      Ok, let's talk communication. Your repeated use of the word "fucken" [sic] reminds me of an old adage: "Profanity is a small mind's attempt to express itself forcefully." And as we all know, your brain is quite, shall we say, limited.

    34. Re:New Law? by Arapahoe+Moes+Mother · · Score: 1

      Ok, so I went and got an account. What do you think? Did you know it was me? Just wanted to tell you how much I hate you and wish I'd left you at the wal*mart like your father did. You were a mistake!

    35. Re:New Law? by Arapahoe+Moe · · Score: 0

      If I were using the word "fucken", in the above post, as a pejorative term then you might have a point. Unfortunately, you don't and your sentimental views on the propriety of language is less than useless.

    36. Re:New Law? by Arapahoe+Moes+Mother · · Score: 1

      Moe, just wanted to remind you that I am your mother and I hate you. That's it, thanks.

    37. Re:New Law? by arthernan · · Score: 1

      I think I have trashed ten times the amount of code that I have written.

  5. Amarok? by HappySmileMan · · Score: 3, Informative

    I'm just a 15 year old with a basic knowledge of C++, I've cracked open some source packages to test how much I know from time to time and Amarok seemed fairly well done to me, though that is of course compared to other packages, I still hyad to do a little bit of searching around to understand it.

    Also the Last.fm player seems fairly well done, though for both these programs I didn't look through the full code or change anything, so maybe I just happened to stumble across the only 2-3 human-readable source files?

    1. Re:Amarok? by m50d · · Score: 2, Interesting

      Amarok looks quite horrible by compairson with what its UI is built on. Though they have their gnarly parts, on the whole I am always impressed with the KDE libraries.r

      --
      I am trolling
    2. Re:Amarok? by mrseigen · · Score: 1

      The code for the last.fm player may be good, but the quality of the application across various platforms is highly suspect.

      It does amazing things like prevent my computer from going to sleep while it's active, or wedge the sound player in terrible ways. It's certainly much worse than the old iScrobbler application.

    3. Re:Amarok? by eean · · Score: 1

      You are very confused. Why are you talking about the last.fm player?

    4. Re:Amarok? by HappySmileMan · · Score: 1

      I kinda have to agree there, the program itself is horrible, I can't play music on it unless I close all open programs and open them again, however I found it very helpful to look through the code for learning purposes, if I actually want to listen to music I use Amarok or the in-browser player they provide, which works fine

    5. Re:Amarok? by slippr · · Score: 1

      The post he was replying to mentioned the last.fm player.

  6. Next up on slashdot... by Anonymous Coward · · Score: 2, Insightful

    Is an artist ever happy with a painting?

    Trends and tastes change. If any coder is 100% happy with a project, they're in the wrong field.

    1. Re:Next up on slashdot... by estevon07 · · Score: 5, Insightful

      I couldn't agree more. As I grow older, I've learned there really is a time when something is "good enough" to satisfy known requirements. I find that many applications are over engineered to some pie in the sky version of what's right and good - usually at the expense of simplicity and stability. I've often heard Java folks talk about re-factoring code and that's fine if no one is using your app, but in the event that folks and money are dependent on it, then re-factoring really just increases risk to all involved. The best possible outcome is that no one will notice the changes.

      It's definitely hard for more passionate developers to realize when time to value ratio has diminished to the point that your time is better spent on other projects. There's always one more thing to spruce up or optimize. Having been both a musician and developer, I like to think of my work as a reflection of me. Playing an instrument is similar in that there is always more to learn and practice on any given song, but sometimes you need to put it down and move along to other pieces. Even the best musicians play a variety of songs. I'm sure Eddie Van Halen could have perfected Eruption for the next 20 years after he recorded it, but he decided to spend his time on other works.

    2. Re:Next up on slashdot... by TheLink · · Score: 1

      A sign of age perhaps ;). As you grow older in this imperfect world you may start to realize why most creatures get older and die.

      It's just too hard to keep fixing all that crufty old code - after a while you're no longer sure what's a bug and what's a feature. And the fixing gets more and more difficult AND dangerous on each fix. And after enough fixes/changes, the whole thing eventually stops working.

      Hopefully a less crufty younger version was made before that...

      --
  7. Maturity = Mess by loony · · Score: 2, Insightful

    Well, you'll always find people that say a code base is a mess when the better word would be different. I have a if statement with out { and } to close it... Is it needed in C++ for a single line? Nope - does it make it clearer and easier to read? Yes to me - and my friend Chris will tell you exactly the opposite...

    And on a related note - why rewrite? Can't people ever just go for cleaning something up? No cause then you are just doing mindless reformatting - while if you rewrite, you can claim you make it better, faster, whatever... So of course people will say its better to rewrite...

    Finally, all mature code is a mess. If I rewrite it, I concentrate on the core piece of functionality... That is going to be small, lean, pretty and fast... Then the code matures - it gains more features. It gains portability. It is being worked on by many... and suddenly your re-write is no better than the code you set out to replace.

    Peter.

    1. Re:Maturity = Mess by Tablizer · · Score: 1

      Well, you'll always find people that say a code base is a mess when the better word would be different.

      I agree, it is largely subjective. People think different and like things certain ways to make their brain feel comfy. For example, some say that large functions is a "smell". However, they are only a smell in my opinion if they are hard to read, such as the sections not clearly deliniated. I won't make a function small for the sake of smallness, there has to be a reason for it. My code is a mix of large and small functions.

      and suddenly your re-write is no better than the code you set out to replace.

      One partial compromise is to comment existing code better, and perhaps put some kind of meta markers in it so that you can find stuff quicker in the future using text search.

    2. Re:Maturity = Mess by PianoComp81 · · Score: 4, Insightful

      And on a related note - why rewrite? Can't people ever just go for cleaning something up? No cause then you are just doing mindless reformatting - while if you rewrite, you can claim you make it better, faster, whatever... So of course people will say its better to rewrite...
      On one project I'm currently working on, we DO just clean up the code. It's necessary because over time developers (myself included) haven't been following the coding standard for the project. To make the code more readable to future developers, we actually will try to clean up a file or pieces of a file when we touch it (comments, style, magic numbers, etc.). There are a lot files, and it hasn't always been a success (it's a continual battle), but it's better than rewriting it.

      Now, I *have* rewritten a lot of the code on the project, but not because it was "ugly". We had quite a lot of "prototype" code still in the project. Since it was prototype code, it didn't check for or handle error conditions very well (not to mention the endless bugs that have been found due to the prototype code). We've had to rewrite a lot of the code because it was easier to do that than fix the bugs in the code. This usually allows for easier debugging in the future AND gets rid of any of the bugs that were found (the bugs were usually caused by a bad or even completely wrong approach to the implementation).

      The difference is knowing when to clean up the code and when to rewrite it. If a developer just can't understand the code (because it needs cleanup or it's just very complicated), then it should be cleaned up and commented properly. Sure it's tedious, but everyone on the project loves you afterwards because they can suddenly understand the code! If there are bugs and it's obvious the implementation should have been done a different way (for speed, usability, modularity, whatever), then a rewrite might be in order.

      (and of course, as you mention, as time goes on the code starts looking "bad" or "old" again - time for hopefully another cleanup rather than a rewrite)
    3. Re:Maturity = Mess by x_MeRLiN_x · · Score: 1

      As far as I know we're not talking about formatting. Having inconsistent white space is much worse - simply because it's so easily avoided - not to mention the fact that the whole process of changing code to suit your style can be automated. The topic of debate as I understand it is spaghetti code, ill-advised hard coding and blatantly inefficient approaches.

    4. Re:Maturity = Mess by WilliamSChips · · Score: 1

      My code is the spawn of Cthulhu. I've seen it, and only the fact that I was already insane protected me.
      --
      Please, for the good of Humanity, vote Obama.
    5. Re:Maturity = Mess by Anonymous Coward · · Score: 0

      Having the open and closing braces helps the compiler during macro-expansion and interpretation. A hard lesson learned porting code across SunOS, AIX, and Windows.

      How pretty a code is also dependent on the type of coding.

    6. Re:Maturity = Mess by Antique+Geekmeister · · Score: 0, Troll

      I see you've used CPAN!

    7. Re:Maturity = Mess by libkarl2 · · Score: 1
      There are reformating tools (see indent(1), perltidy, and others) out there. Not all of them make me happy, but sometimes it has to happen.

      I have noticed three main (non-style) factors to why mature code becomes messy...


      1) The new functionality is added in by someone who is not fully aware of how the code base was orginally structured. They commit encapsulation fouls, succumb to the temptation of adding "just one more field" in a class that is already overstuffed, or add code to a method/function that is not in keeping with the logical intent of the method/function.

      2) The code base is being maintained by an individual whose coding and design philosophies are radically different than that of the orginal author(s). This can be due to differences in experience levels, schools of thought, whatever. In many companies, the new hires start out in a maintenance coding position of some sort, yet changing existing code to fit changing requirements can be an extremely difficult task if the new reqs diverge far enough from the old ones. Its amazing how quickly you can find yourself in over your head.

      3) Obsolete, depreciated, functionality is not removed. It languishes in the code base and aids an auditor in deciding that that particular code base is a mess, when in fact 20% - 35% of the code in question is (or is almost) unreachable. At this point, and for obvious reasons, a full rewrite becomes more and more attractive (read productive). Late stage porting efforts to disparate platforms are a major source of dead code. While maturity = mess, so too does portability = longevity.

      I would go on to mention that sometimes fundamental design flaws make it to implementation, but that is basically the same as having a project reach critical mess during testing. Some code is ugly at birth, should have never been born, and will probably won't live past the age of 3.

      --
      You are where you are at the time you are there.
    8. Re:Maturity = Mess by billcopc · · Score: 1

      I'm doing exactly that these days, I left the locally painful field of consulting and joined a small (but feisty) web dev firm about a month ago. At this point, every project I touch usually starts with some level of refactoring, or at the very least reformatting because the last guy's coding style is reminiscent of an HTML file bounced between a Frontpage twit and a Dreamweaver twit several times. The best part is that CSS is used, but often times it's hard-coded right in the tags rather than an actual stylesheet, so changing one color involves hunting dozens of bits of crap all over the place.

      Elegant code can be elusive, because well, if we didn't need to get creative with the code, we'd all be out of our jobs. The important thing is to consider who's going to work on that code, write it so that anyone can read through it and make edits without slaughtering cute furry animals. You will thank yourself two years from now, when a client asks you to change some widget or toggle a default value and it takes you 15 minutes instead of 15 hours.

      Now I don't believe in shrink-wrapped code patterns, but I do believe in a sane level of abstraction and organization. Most importantly, I try to keep things simple on the surface, by using descriptive names and short inline blurbs that explain the trickier aspects of a function, or give usage examples. Now this is one particular peeve I find with much of the C++ code in the open-source world, it's undocumented and spread out over a gazillion little files. I'm sure people have arguments for that sort of thing, but I fail to see the point in having ten one-page files when they would logically work better as one. It sometimes seems like people break up their C++ files into smaller chunks arbitrarily, rather than pursuing any particular goal like code reuse, team development or development-style-of-the-month. It's far easier to scroll through a long document or use text-search, than it is to wrestle a dozen open tabs, each featuring interlocked code.

      --
      -Billco, Fnarg.com
    9. Re:Maturity = Mess by jc42 · · Score: 1

      As far as I know we're not talking about formatting.

      On every project I've ever worked on, when ideas like code standards or "readability" are brought up, it has always meant formatting. Always. After 40 some years of programming, I've yet to see an exception.

      Funny thing is that the resulting management-decreed code standards always make the code harder to read. This is mostly for the trivial reason that such standards always introduce many line feeds and sillinesses like lines that contain only a brace, decreasing the number of lines visible in an edit window and forcing much waste of time scrolling up and down. There are other ways of making the code less readable, but stringing the code out vertically is the most common and most effective.

      I suppose you could say that a chunk of code that zig-zags down the screen, one or two tokens per line, is "pretty", as an abstract artsy sort of wallpaper. But to a programmer trying to understand it, it's pretty ugly.

      On a number of projects, I've written little reformatting programs, one to put code into the "standard" format for the project, and several others to put it into more compact formats that various programmers prefer. That way, the managers get to see "pretty" code that they like (but don't bother actually reading), while the programmers can put it into forms that they find more readable.

      --
      Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    10. Re:Maturity = Mess by Gutboy · · Score: 1
      And on a related note - why rewrite? Can't people ever just go for cleaning something up?

      Back in my Air Force days, I was asked to make some modifications to some code that had been writen 5-6 years before, consisting of some 10-20 thousand lines of code. The author if this code had decided that it was a good idea to have 50 flag variables, named "Flag01", "Flag02", "Flag03", etc., and 20 'switch' variables, named (you guessed it) "Switch01", "Switch02", etc.

      This wonderful piece of code was filled with things like:

      if (Switch05 == 7) Flag14 = 8;
      if (Switch18 == 3) Flag07 = 0;
      ...

      I rewrote the code, and didn't use a single variable named 'Flag' or 'Switch'! Was it faster? Who cares, it was maintainable, which made my job easier since I had to maintain it.
    11. Re:Maturity = Mess by Tablizer · · Score: 1

      [your code is] the spawn of Cthulhu. I've seen it, and only the fact that I was already insane protected me.

      If you are serious and you have specific criticisms, I would like to see them.

    12. Re:Maturity = Mess by smallfries · · Score: 1

      He is quite obviously joking. Read his message again, there are enough clues for you there. Of course everyone that has read your reply now suspects that you are autistic, and so worries about the quality of your code...

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
    13. Re:Maturity = Mess by starfishsystems · · Score: 1
      On that note, I've encountered a surprisingly strong relationship between cleaning up code and understanding it.

      Anecdotal though this observation may be, I've been following the practice for about thirty years now and it's never failed me yet. Best of all, it minimizes mental fatigue. In fact, for much of the time it's almost therapeutic. It progresses gradually from rote activity to insightful redesign.

      Setting aside the various possible refinements such as versioning, group walkthroughs, and regression testing, it goes basically like this:

      • Reformat the code for consistent indentation, layout, use of whitespace and so on, with the intention of clearly expressing lexical structure. Make no other changes.
      • Change symbol names for consistent capitalization, name length, symmetries in naming style. Add definitions for constants. Remove unused declarations. The intention is primarily to improve readability, but you'll probably notice that you've improved meaning as a side effect. At this point, isolated parts of the code are starting to look competently written, and you have at least moderate confidence that you understand how those parts work.
      • Move things around for consistent grouping. What exactly this means will depend a lot on the size and complexity of the application, as well as how it fits into the larger corpus of software to be maintained. This is essentially an exercise in librarianship, of making things easy to find.
      • Make what we might call syntactic structural changes. Replace weird tests and loop constructs with obvious ones, make more sensible variable assignments. You'll probably find that all sorts of little things get changed at this stage, and some disappear outright. This is where you have to stay sharp and do the most aggressive testing and debugging, because it's easy to introduce obscure errors or to remove something that looks weird but is responsible for correct behavior. In short, this is the dirtiest part of the exercise right here.
      • Begin semantic restructuring without changing the architecture. The work should be getting easier again, because you're only looking to replace messy semantics with clean semantics. For example, you might recognize that several functions that do nearly the same thing could be merged, that similar methods could be moved into a superclass, that the code should not have raw library calls scattered about but should be passing them through a slightly more abstract layer.
      • Refactor the architecture where it has become obvious that refactoring is called for.
      It's a somewhat slow and contemplative process, rather like spring cleaning. It takes time, but it's not stressful, and except for wbat I've called syntactic restructuring, it doesn't require a great deal of alertness. On the contrary, you're transforming the code so that it will appear obvious even to a not very alert person. And, amazingly, it usually is obvious at the end of the process.
      --
      Parity: What to do when the weekend comes.
    14. Re:Maturity = Mess by slamb · · Score: 1

      If a developer just can't understand the code (because it needs cleanup or it's just very complicated), then it should be cleaned up and commented properly.

      To rephrase only slightly, if it just needs cleanup, then it should be cleaned up? Well, yes, but you haven't said anything that's not obvious.

      I'd say the real question is always "is the design right?". When I've worked with big chunks of existing code, I've rewritten it in only when there's an aspect of the design that's totally wrong and has infested nearly every line. Off-hand, I can only think of two classes of such mistakes:

      • wrong threading model. For example, I inherited code for a multiplexing protocol that had this ridiculous hierarchy of one thread per connection, one thread per channel, and then dispatching to a pool of workers. It was difficult to understand, slow, and would mysteriously fail based on load. (Completely full of race conditions.) I rewrote it as one thread that did all the IO asynchronously and the pool of workers. Much less code, problems all went away.
      • wrong programming language. Several times I've replaced a mountain of C or Java with a molehill of Python.

      Otherwise I've refactored - eliminated duplicate code, reorganized to fix broken abstractions, removed unnecessary overengineered design patterns, fixed function names, added comments, switched libraries, corrected error handling, fixed bugs in general, etc.

    15. Re:Maturity = Mess by Anonymous Coward · · Score: 0

      Very often programmers rewrite code so they can understand it.

      Most often this is due to the original code being so poor that it's difficult to understand.

      Unfortunately the rewrite is often just as bad as the original because while the rewriter can understand it, no one else can.

      Rinse, repeat...

  8. TeX by Anonymous Coward · · Score: 0

    It's by Donald Knuth, it must be good (and it is).

    1. Re:TeX by xouumalperxe · · Score: 1

      Damn, just read your post, after posting the same. Beat me to it by 20 minutes :(

    2. Re:TeX by belmolis · · Score: 1

      The irony is that, although TeX produces very high quality documents, as a programming language it is horrible and reading TeX programs of any complexity is very difficult.

    3. Re:TeX by xouumalperxe · · Score: 1

      I meant the code for TeX itself, not stuff written in TeX. I just use LaTex and Lillypond as appropriate, and leave the "proper" TeX for people with the time and inclination to write those packages.

    4. Re:TeX by Tacvek · · Score: 1

      Well, the thing is that TeX is written in WEB. WEB is an unusual mixture of Pascal and documentation (writen in Plain TeX of course). The source must be preprocessed (It uses a complicated preprocessing system) before it is valid Pascal, and IIRC the form of pascal used is non-standard, so some changes need to be made to to it. Then it must be compiled. So very few people actually do that. Web2C is a tool to convert the mess into C code. That is what most TeX distros use. However, one may one to take into account the special patching formats used by WEB. I find it all a mess. But that's just me.

      --
      Stylish sheet to fix many problems in Slashdot's D3: https://gist.github.com/801524
    5. Re:TeX by larry+bagina · · Score: 1

      Even worse: Knuth might write a book on compiler/interpreter construction.

      --
      Do you even lift?

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

    6. Re:TeX by Anonymous Coward · · Score: 0

      TeX itself is different, though. It's written in a language called WEB, which is itself sort of a combination of TeX and Pascal. WEB programs are written as much for people as they are for a computer; the TeX source contains about as much (or more) explanation of what it's doing as it does code. And it's not just a matter of more comments: WEB also lets the code be arranged in a way that makes it easier for humans to understand --- the TeX source, for example, starts off with very high-level descriptions of what it's doing, and then fills them in.

      The result is that the source code (after being run through a program called WEAVE, to produce TeX which can be typeset for humans to read) reads like a book --- and is even sold as one (called "TeX: The Program").

      In WEB (or CWEB, the same thing but based on C rather than Pascal), for example, you can have something that looks like:

      (Initialize variables)
      while((more input to process)) {
          (Read user input)
          (Process input)
          (Print results)
      }
      (Clean up)

      where each parenthesized part is expanded on sometime later in the human-readable version of your program. (In the generated Pascal or C, these will be filled out as appropriate from the other sections of the program).

      (This style of programming is called "literate programming," by the way; it's quite interesting. Well-written literate programs read like books explaining what the program does. The downside, of course, is that writing programs this way requires much more work than writing pretty much any other way, and also requires good writing skills --- you have to be good at explaining things to other humans, not just to computers).

    7. Re:TeX by xouumalperxe · · Score: 1

      Yeah, it's odd that web can be "compiled" with both tangle and weave, and then generate different stuff. And using pascal is a pain, I'd much rather have it be C. But it's still one of the pieces of software with the least amounts of bugs in the history of computing. And it's thoroughly (you might even say annoyingly) commented.

    8. Re:TeX by Anonymous Coward · · Score: 0

      And even worse than that: there are people on slashdot who don't seem to know the difference between "compiler/interpreter construction" and "programming language design"! :)

      Even then, while TeX (and especially Metafont) are somewhat strange as far as languages go, it says a lot about TeX that something quite clean like LaTeX could be implemented on top of it. TeX is very good at what it's meant to do --- moreso than anything else I've seen for typesetting.

    9. Re:TeX by belmolis · · Score: 2, Interesting

      Yes, I understand that. I just think it is somewhat ironic that the implementation of TeX is much prettier than the language itself.

    10. Re:TeX by J.R.+Random · · Score: 1

      Even worse: Knuth might write a book on compiler/interpreter construction.

      Only if he lives to 130 or so. I'm a middle aged hacker and Knuth has been working on volume 4 for my entire career (~28 years). And the compiler book comes after volume 4.

    11. Re:TeX by Anonymous Coward · · Score: 0

      Computers & Typesetting, Volume B: TeX: The Program is worth reading even if only in parts. You walk away from the experience thankful that you have intrinsically more readable languages today. (I am thinking of Java and Python in particular.) Pascal, which as defined by Wirth, is a teaching tool and is readable but, at that time (early 80's), any practical use of it required using the vendor's non-standard extensions. WEB was a means of adding modularization and vendor independence. At this it was successful. Where it went wrong was that it did not set the conditions of programming to steer the programmer into doing good design. The result, and you get this from just reading the first few chapter of The Program, is that the TeX implementation is a mass of global variables and twisty code.

    12. Re:TeX by Tacvek · · Score: 1

      Yeah, it's odd that web can be "compiled" with both tangle and weave, and then generate different stuff. And using pascal is a pain, I'd much rather have it be C. But it's still one of the pieces of software with the least amounts of bugs in the history of computing. And it's thoroughly (you might even say annoyingly) commented. I will certainly grant it both of those.
      --
      Stylish sheet to fix many problems in Slashdot's D3: https://gist.github.com/801524
  9. 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.''
    1. Re:what? by WilliamSChips · · Score: 1

      Actually X is one of the packages you hear criticized a lot from the people who want code to bring the pretty.

      --
      Please, for the good of Humanity, vote Obama.
    2. Re:what? by zero1101 · · Score: 1

      "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? Yeah, it's like "X is a #%@!in mess, and this code ain't so hot either!"
    3. Re:what? by Anonymous Coward · · Score: 0

      that wasn't a flame of X as much as it was a sample line of exquisite perl.

    4. Re:what? by Anonymous Coward · · Score: 0

      Well, X _is_ a mess. It's the number one piece of software on Linux that I hope will die soon and be replaced by something lighter. It is an old, old mess in so many ways. It is inherently slow and as discussed some days ago (in the discussion about the new scheduler for linux), X makes it difficult to make effecient scheduling. /David

  10. BOOST by alyosha1 · · Score: 3, Informative

    The boost libraries tend to be a pleasure to work with. BOOST::Python especially continues to surprise me by how much it 'just works'. That said, I haven't had much need to look at the source code itself, but there seems to be a strong desire in the boost community to do things in as clean a way as possible.

  11. Why code always gets messier and messier by Anonymous Coward · · Score: 1, Insightful

    1) Cleaning up code is a job to do after the code is done.
    2) The code is never done. Refer to rule one.

    1. Re:Why code always gets messier and messier by Spy+der+Mann · · Score: 1

      This is why i always clean up code while my boss isn't watching :P When he comes around, i switch to the code I'm supposed to be writing (hee hee). In the end it turns out good, because it keeps me efficient and makes me waste less time fixing bugs due to sloppy code.

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

    1. Re:Understanding != Writing Code by nonsequitor · · Score: 2, Insightful

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

      If you can't understand the code it's the author's fault. That is if you have mastered the syntax of the language of course.

      I'm currently working with an embedded code base that was written for job security. Everything is somewhat elegantly organized, but nothing is commented and functions are usually 200 - 500 ELOC. There aren't any notes explaining module interactions with module descriptions or example usages. Considering the project size is around 25,000 lines that makes the code very dense. Sure in 6 months I can document it and have it usable for a team again, but if I don't have time for fixing bugs or adding a feature, contractors will need to be able to come in and work on it with a minimum of rampup time. 6 months is not acceptable.

      Not everyone needs to understand the derivation of every algorithm used, but they shouldn't have to perform the work a second time to verify its accuracy. Unsustainable code is ugly. If the average programmer can not read the source with documentation and understand its purpose, then the original programmer is at fault for not expressing themselves in a way that others can understand. This is why senior programmers make coding standards and do design work.

    2. Re:Understanding != Writing Code by einhverfr · · Score: 1

      I have never heard someone call code "ugly" because they couldn't understand it. Ugly usually means "repulsive" and this usually means that it is an aesthetic and expressive difference.

      SQL-Ledger code is about as ugly as Perl code gets. Heck I think it would make anyone who know.s Perl cry. As I say, the author hit (as far as I could tell) 75% of the programming anti-patterns listed in Wikipedia, and many of them he managed to extend in bizarre and disturbing ways. For example, he has magic strings in his *comments.* Delete the comments and things break. I kid you not. Then there are the points where he takes the spaghetti metaphore rather literally (say a function that wanders between six or seven files because of different files overwriting functions which are called inside). Then he has the God object which again is quite literal because it is the *only* object and does *everything.*

      If that wasn't bad enough, the Perl is just plain ugly. You will have calls like: AP->transactions(\%myconfig, \%$form); ($form is the God object.) Note that the only reason why %myconfig is not a hashref is because he decided to dereference it on return of another function.

      He also insists on parsing the HTTP request himself rather than relying on standard libraries, and where he can't avoid using CPAN, tends to copy and paste the relevant portions of the code into his software (as you can see in SL/Mailer.pm). He didn't do this with DBI and DBD::Pg, though.

      Is it any wonder that a year ago, the code was vulnerable to a serious security bypass issue because he was using timestamps for session ids and not checking them against what was actually issued (he was only checking to see whether the timestamp was somewhat recent-- the real session key was the login)? You can read more about that at http://www.securityfocus.com/archive/1/445512. To be fair, since we have moved away from SQL-Ledger, that program *has* patched all auth bypass security issues we have reported to DWS, but most other security issues have not been patched because the author doesn't see insider threat as a real issue.

      --

      LedgerSMB: Open source Accounting/ERP
    3. Re:Understanding != Writing Code by Anonymous Coward · · Score: 0

      I find it odd that you mention nothing about domain concepts - the real-world things that you are modelling in your application. They can certainly require a considerable effort to understand, and until you're done you won't truly understand the code.

      Another issue is that if understanding the language is the gold standard of readable code, then you're directly ruling out any additional abstraction levels. I appreciate that in straightforward business applications this can be a good thing, if it means a faster learning curve for new hires. However, it is equally true that a few well chosen abstractions can simplify the structure of any application, even if getting to know and appreciate those abstractions takes time and leads to accusations of obfuscated code from less patient coders.

    4. Re:Understanding != Writing Code by the+not-troll · · Score: 1

      If you can't understand the code it's the author's fault.


      Not necessarily. Sometimes it's just the reader who is to dumb to understand the concepts used.

      At least that's what happens to me whenever I read the code I wrote.
      --
      In Soviet Russia, government controls corporations.
      In Capitalist America, corporations control government.
    5. Re:Understanding != Writing Code by tknd · · Score: 1

      I've heard this a number of times before but I think it's a false sense of where the "hardness" is. If reading the code is hard, then that means that the code was not well written or not written for easy reading. So go back to writing code, and when you write it, make your only goal to make it easy to read. Suddenly you'll find writing code that is easy to read is very hard :).

    6. Re:Understanding != Writing Code by KillerCow · · Score: 1

      Of course it isn't. Code tells you the "how," any novice can see how code is doing it's thing (that's what code is), and to a novice, coding is saying "how" to do something. Read their comments. That's what they think the task is: saying "how" to do something. They write code like:

      Queue queue = new Queue(); // put the element in the queue
      queue.put(element);

      If you know the libraries and the spec backwards and forwards, and things are named and modularized appropriately (the difference between novices and someone good), you can work backwards to see the "what" -- what is this code trying to accomplish. Then you graduate to things like:

      Queue remoteMsgQue= new Queue(); // hold this message for later
      remoteMsgQue.put(recvdMsg);

      Code can never tell you the "why," and it takes expert insight to figure that out, or to leave enough hints in the code. Someone who's been working for a long time would write: // use this queue to allow processing and receipt of remote messages asynchronously following the producer/consumer pattern
      Queue incomingMsgs= new Queue();
      incomingMsgs.put(recvdMsg);

    7. Re:Understanding != Writing Code by nonsequitor · · Score: 1

      Way to take a quote out of context. Did you miss the part where I qualified that statement?

    8. Re:Understanding != Writing Code by the+not-troll · · Score: 1
      Do you mean this by qualification?

      That is if you have mastered the syntax of the language of course.


      Then claiming I took it out of context means that you assert that I didn't master the syntax. While I must admit that this is a very elegant ad hominem, it definitely doesn't show that I took it out of context: If I actually didn't master the syntax, how would I have been able to write a compileable program in the first place? It only shows that you believe that there is a dichotomy between "the author writes bad code" and "the reader can't read", not admitting the possibility that one could express rather complex concepts in a program.
      --
      In Soviet Russia, government controls corporations.
      In Capitalist America, corporations control government.
    9. Re:Understanding != Writing Code by Anonymous Coward · · Score: 0

      I totally agree. I don't think ppl appreciate that it takes skill/experience to read code. I've noticed that over the years of reading code, it gets easier over time.

  13. Code prettyness only at module level by LiquidCoooled · · Score: 2, Interesting

    I find code can be exceptionally well presented but only if you look on a file by file basis.
    Most projects have nice clean stable blocks which to look at you just know its right.

    Other parts resemble a jungle and have no logical flow and are horrid.

    Whenever I am building an algorithm, it goes through the numerous rebuilds, after initially getting it working each one has more and more order until it looks like it will win a race.
    If the boss comes in and sees working code though, they don't understand this prettyness and will expect it to be shipped.

    --
    liqbase :: faster than paper
    1. Re:Code prettyness only at module level by billcopc · · Score: 2, Insightful

      If that's truly how your code works, you need to fire your boss!

      Every project should budget resources to future-proof the actual code by cleaning it up and writing adequate documentation, and I don't mean a cookie-cutter paragraph for every single function. I mean do what needs to be done to ensure that the next time you have to work on that code, you won't waste twice as much time re-learning what it does.

      Managers who ship code the minute it compiles are either assuming the project will never be revisited, or (most likely) they are complete imbeciles.

      --
      -Billco, Fnarg.com
  14. 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 SillySnake · · Score: 1

      You must work on Saturdays.

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

    4. 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 ());
        }
      }

    5. Re:Hello World by FIT_Entry1 · · Score: 0

      I used to think singletons were nice looking bits of code, now not so much.

    6. Re:Hello World by smittyoneeach · · Score: 1
      Ah, well. As was noted long ago...

      The thing that hath been, it is that which shall be; and that which is done is that which shall be done: and there is no new thing under the sun.
      Eccl 1:9
      Solomon may not have been a strong proponent of software patents, one surmises.
      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    7. Re:Hello World by MillionthMonkey · · Score: 5, Informative

      Not so secure when the company is sued for stealing source code. He took credit (with his copywright notice) for a very old joke. A blatent copy-and-paste. One has to wonder how much of that he does on the job.

      Ha ha, joke's on you, you dick- that "old joke" was written by me five years ago as part of a larger post and I was not at work- in fact it was way after hours and I was about to go home. I just started with the base concrete implementation and this is what it looked like after a few minutes of stuffing patterns into it- Singleton, Factory, and Strategy. I keep thinking one of these days I'll release a 2.0 version with Proxy and Bridge. Since I was the original author I retain the right to paste it wherever I want and to attach any license agreement I feel like attaching.

      This has become the most famous code I've ever written which is the sort of thing that makes you reflect on your career. So far it has netted me about 20-30 karma points over the years (lord knows how much karma was gotten from pirated copies). I found it being examined in some software engineering papers and it even made its way into one of the patterns books (as an example of "Patterns Happy" code). When I found out about that, I made the guy send me a free copy and acknowledge me in print so I can maybe net some jobs unnecessarily screwing up simple code with GoF patterns which always pays well. Now that I released it under the terms of the Apache license he might come back for his book.

    8. Re:Hello World by Joren · · Score: 1

      The joke ain't older than his own 2002 posting, is it?

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

      I think an AC just got pwn3d! Love it!

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

      I just read your original post.

      You're officially my hero.

    11. Re:Hello World by Anonymous Coward · · Score: 0

      t is the Gang-of-four Job_Security_Strategy pattern...
      better known as the "gang-bang" pattern.
    12. 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.
    13. Re:Hello World by rednip · · Score: 1

      Looks great, but you forgot the xml config file (and it's related loader) for variables you wouldn't dare change without refactoring the code.

      --
      The force that blew the Big Bang continues to accelerate.
    14. Re:Hello World by jswalter9 · · Score: 1

      Jim? Is that you? Or did someone steal your style? :)

      --
      Retired from software... maybe. Sort of.
    15. Re:Hello World by ignavus · · Score: 1

      Wow! If you split it into separate files, and compile them in the right order, it actually works!

      Or er, so a friend told me.

      --
      I am anarch of all I survey.
    16. Re:Hello World by DavidD_CA · · Score: 1

      Where are your error handling routines?

          Your comments??

              User-defined settings???

                  Debug preferences????

      Amature. :P

      --
      -David
    17. Re:Hello World by CAIMLAS · · Score: 1

      The sad thing? I actually had a professor do something very similar to that as an "introduction" to a Java course... and not as a "hey, this is how to not code" example, either.

      --
      ~/ssh slashdot.org ssh: connect to host slashdot.org port 22: too many beers
    18. Re:Hello World by greyseal · · Score: 2, Funny

      Think about i18n!

    19. Re:Hello World by Scarblac · · Score: 1

      In a similar vein, the Uncyclopedia article on Java is pretty funny. Especially the comparison with other languages below the Java Hello World...

      --
      I believe posters are recognized by their sig. So I made one.
    20. Re:Hello World by rgravina · · Score: 1

      Wow, you wrote that?! I've come across that code in lectures (in Japan too, so there your code is used around the world!).

      Nice stuff. Would be interesting to see that ported to other OO languages :)

    21. Re:Hello World by julesh · · Score: 1

      Nice code! I'd suggest, however, that the class name "DefaultFactory" isn't adequately descriptive. You should rename it to "StandardOutputMessageStrategyFactory" for the sake of clarity.

    22. Re:Hello World by m303 · · Score: 1

      Assuming your DefaultFactory should be something Singleton-like, the getInstance() method is not thread-safe. If it's called from differents thread, there maybe different factory instances lurking around.
      You could make the getInstance() method synchronized, but that's slow if called often or use a static initialisation like:
      static DefaultFactory instance = new DefaultFactory();

      --
      `dd if=/dev/sig ibs=120 count=1`
    23. Re:Hello World by Paua+Fritter · · Score: 1

      I keep thinking one of these days I'll release a 2.0 version with Proxy and Bridge.

      If you do, you might want to consider adding a Facade to hide all that complexity. It could e.g. have a single

      public void doHelloWorld()
      method which would contain all the implementation details.
    24. Re:Hello World by smittyoneeach · · Score: 1

      Yeah, although he should look to be more elaborate with this code. If we wanted terse, we'd write in C, no?

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

      I like the use of the name DefaultFactory; it soft of illustrates the grand ideals of the over-engineering. Of course there will be a name clash if the package is integrated with almost any other code out there but in this (very full) universe, there's only one DefaultFactory...

    26. Re:Hello World by cculianu · · Score: 1

      God I hate Java. It's so ugly. Really. Somehow C++, even though it's very similar, isn't as ugly.

      You don't end up with super-abstract craziness like this in C++, even though you CAN. It's just that C++ programmers tend to be more practical, or something.

      I hate Java and how some Java programmers stroke their dicks with this type of coding. Yuck.

    27. Re:Hello World by canuck57 · · Score: 1

      Not so funny, but instead of firing up a 90MB VM why not just use C... #include int main(int argc, char**argv) { puts("Hello World"); } Only 3912 bytes to load on my system. Bet the farm it loads faster than the VM.

    28. Re:Hello World by j-pimp · · Score: 1

      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.

      Actually, if you have a code generator doing all the grunt work for you, it wont take you long to write like that. If you use .net 3.0 and the guidance packages to write a WCF web service the code will look like that. However, all you have to do after running the guidance package is fill in the business logic functions.

      Should you write all your code like that? No. Some code belongs in utility classes where the only public members are static that inherit directly from object and implement no interfaces. However, some things you want reusable and extendable. Now a hello world is not a good candidate for the full design by contract factory pattern implementation because it abstracts the code to the point of making it harder to read. However, often in the case of real world code it does not do this.

      --
      --- Justin Dearing http://www.justaprogrammer.net/ We're just programmers.
    29. Re:Hello World by Frogbert · · Score: 1

      May I be the first one to call the GP Mario.

    30. Re:Hello World by vistic · · Score: 1

      No need to recompile for different architectures for which there is a VM?

    31. Re:Hello World by zero_offset · · Score: 1

      3912 bytes? Are you insane? C is for terrorists, homosexuals, and priests who fondle young boys! .data
      hello_message db 'Hello, World!',0dh,0ah,'$' .code
      main proc
                  mov ax,@data
                  mov ds,ax

                  mov ah,9
                  mov dx,offset hello_message
                  int 21h

                  mov ax,4C00h
                  int 21h
      main endp
      end main

      --

      Slashdot quality declines as the number of hot grits posts decreases. - Provolt's Law, Apr-09-2005

    32. Re:Hello World by Anonymous Coward · · Score: 0

      It also needs Unit Tests and some Javadoc!!!

    33. Re:Hello World by Nwallins · · Score: 1

      puts("Hello World") "Hello World" is a literal
    34. Re:Hello World by kestasjk · · Score: 1

      Ha ha, joke's on you, you dick- that "old joke" was written by me five years ago Who's the dick? The guy is basically saying "Give the guy who wrote that joke credit for it", and you come back with "BAHAHA! I wrote the joke, dick!"

      How about: "Thanks for encouraging people to credit me for the joke I wrote, even if you made an unfortunate and unlikely mistake in encouraging me to credit myself"
      --
      // MD_Update(&m,buf,j);
    35. Re:Hello World by MillionthMonkey · · Score: 1

      I could have posted boilerplate comments in the code explicitly taking credit with a pointer to the original link. But I think it looks prettier without such stuff! Unfortunately every time I post this joke (which is now getting old) someone says I'm plagiarizing myself, which *I* take as a compliment even as I insult the guy. An AC doesn't have any feelings to hurt since he won't get a message about it.

      I'm putting together a page of obfuscated Java programs I've written; this one is straightforward but some others have more ingenious clockwork. Maybe I can enter some of these in a contest.

    36. Re:Hello World by Anonymous Coward · · Score: 0

      If you think C++ is not overly complicated, just what is a protected abstract virtual base pure virtual
      private destructor, and when was the last time you needed one? --Tom Cargill, C++ Journal, Fall 1990

      And it's not like you can't over-patternize c++ or anything either...
  15. Inconsistency by Anrego · · Score: 5, Insightful

    I find the thing that really makes code unreadible is inconsistency. This is particularly true of languages like C++ where there is no well defined one true coding convention. If all your code is in house, this is not such a problem, because you can define your own coding convention and stick to it. If however you are relying on other libraries, chances are your going to end up with one library that names its function like_this, and one likeThis, and another fnct_LikeThis ...

    Worse is when you don't even define a coding convention for the code you throw into the mix. Now you have libraries with inconsistent naming, and multiple developers all using their own favorite notation.

    Additionally, their is inconsistency in the functioning of libraries. Some use function pointers, some work by inheritance, some (like glade) read the export list..

    I'm not a huge Java fan, but I think they have maintainability down pat. Very consistent language, well defined coding convention, and a mature set of defacto tools (JUnit, javadoc, log4j, struts, spring, hibernate, etc..) make it a lot easier to jump into older code because everything feels familiar. In most other languages you have to spend quite a bit of time just decrypting the existing code, and then more time learning the particular API's they've chosen.

    1. Re:Inconsistency by mcpkaaos · · Score: 1

      Quite frankly, if you use third party libraries that fall outside your coding conventions (and you are absolutely right - most or all do), you should adapt them. Create your own interfaces and make disparate libraries appear no different than the rest of your system. This simple tactic will cost you minimal overhead up front (interface design) with a huge savings in maintainability down the road (refactor to your own interfaces). If you are programming directly to third party APIs you are just asking for trouble.

      --
      It goes from God, to Jerry, to me.
    2. Re:Inconsistency by Breakfast+Pants · · Score: 1

      GNU indent anyone?

      --

      --

      WHO ATE MY BREAKFAST PANTS?
    3. Re:Inconsistency by VGPowerlord · · Score: 1

      Just in case someone is interested, you can take a look at the Code Conventions for the Java Programming Language.

      --
      GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
    4. Re:Inconsistency by Doctor+Faustus · · Score: 1

      I find the thing that really makes code unreadible is inconsistency.
      I've inherited code from a dozen or two different programmers in eight different languages over the last ten years, and I've always found that inconsistent naming was absolutely inconsequential. Names that are way too short, all caps or just plain wrong are a problem, but otherwise, differences in how people think dwarf differences in how they name their variables.

    5. Re:Inconsistency by baxissimo · · Score: 1

      Quite frankly, if you use third party libraries that fall outside your coding conventions (and you are absolutely right - most or all do), you should adapt them. Create your own interfaces and make disparate libraries appear no different than the rest of your system. This simple tactic will cost you minimal overhead up front (interface design) with a huge savings in maintainability down the road (refactor to your own interfaces). If you are programming directly to third party APIs you are just asking for trouble.

      I'm not sure what sort of 3rd party libraries you're thinking of, but the thing that immediately springs to my mind is GUI libraries. I don't think it makes sense to create a wrapper around wxWidgets simply because I prefer classic_underscore_style to their CapitalizeEveryWordStyle.

      Seems like a huge amount of work for marginal gain.
      If you have time to do that kind of thing where you work, then lucky you.

    6. Re:Inconsistency by Graff · · Score: 1

      I'm not a huge Java fan, but I think they have maintainability down pat. Very consistent language, well defined coding convention, and a mature set of defacto tools (JUnit, javadoc, log4j, struts, spring, hibernate, etc..) make it a lot easier to jump into older code because everything feels familiar. In most other languages you have to spend quite a bit of time just decrypting the existing code, and then more time learning the particular API's they've chosen. I totally agree about that, I'm also not a fan of the language but at least they have a very well-defined coding convention which makes it much easier to read if the programmer followed the guidelines.

      I do a lot of programming in Objective-C by way of Apple's Cocoa and I find Apple's Coding Guidelines for Cocoa to be a great set of coding conventions to follow. Once you get used to their guidelines it becomes very easy to read code that follows those guidelines. Add to this the fact that Objective-C is naturally an easy language to understand and you have a great combination.
    7. Re:Inconsistency by Ben+Hutchings · · Score: 1

      Will make you many friends among those who read diffs!

  16. dicomlib by alyosha1 · · Score: 1

    Not to blow my own horn, but I happen to think the DICOM medical imaging libraries that I maintain score pretty highly on code reuse, RAII, exceptions and general maintainability.

    1. Re:dicomlib by ceoyoyo · · Score: 1

      Anything that successfully implements DICOM is beautiful, no matter what it looks like.

  17. 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.
    1. Re:anything in BASIC by Anonymous Coward · · Score: 0

      C++ Goto's make things more interesting:

      int main() {

      :hell

      printf("F U");

      goto hell;

      return 0;

      }

    2. Re:anything in BASIC by ari_j · · Score: 1

      :hell

      I think you mean "hell:", with the correct syntax.

    3. Re:anything in BASIC by fishtop+records · · Score: 1

      The more GOTOs the better! There was a classic article in Datamation back in the early 70s that defined the COMEFROM for folks who hate GOTO. There was even a COMEFROM Depending upon X to parallel the COBOL GOTO Dependinging upon AccountingCodeVariableInCobolStyle
    4. Re:anything in BASIC by Anonymous Coward · · Score: 0

      goto is bad, comefrom is much better

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

    1. Re:good source by jerryasher · · Score: 2, Insightful

      I came in here to say exactly that. The design and source to Tcl and the source to AOLServer are actually clean, clear, and elegant. I think much of that is thanks to the Tcl/Tk Engineering Guide.

    2. Re:good source by C.A.+Nony+Mouse · · Score: 2, Informative

      I'm not surprised. I've spent much time (long ago) reading and modifying code of university CAD tools. Magic (also by Ousterhout) was by far the most readable, and very easy to find your way in considering it was something like half a million lines of C, IIRC. In fact, I changed my own coding style as a result.

      --
      J
  19. Check out Rickli's NeDi by Anonymous Coward · · Score: 0

    I've been hacking on Remo Rickli's NEDI code (in Perl). The modules are well designed and the code itself is really beautiful; very well formatted and logically easy to follow (one would hope). I remember cracking open the tarball a while ago and being amazed...

  20. The best piece of code I have seen so far by ls671 · · Score: 1

    The best I have seen are the JVMs from java 1.0 to java 6. Of course this doesn't qualify at the application level but it is still a great piece of software.

    I have used other tools, namely Microsoft librairies and especially with MS librairies, the amount of time I have lost intrepreting strange results I was getting and fixing the problem was incredibly high. 7 times out of 10, the problem was a poor (buggy) implementation of what the library was supposed to do. And 3 times out of 10, it was OUR code, very frustrating and time consuming because you then have to PROOVE that the library is the problem and fill up a bug report.

    With java, 99% of the time, OUR code is the problem. That's a great gain in productivity !

    When I started with java, I was impressed by the structure of the JVM which I have studied extensively. I also liked the javadocs which I still use all the time given the high number of classes in java nowadays. I have never looked back since.

    In our projects, to keep things clean and nicely organized, we just inspire ourselves from how it is done in the JVM source code and we do not try to re-invent the wheel with our own fancy way to do things.

    --
    Everything I write is lies, read between the lines.
    1. Re:The best piece of code I have seen so far by Anonymous Coward · · Score: 1, Funny

      You're wearing asbestos-everything, right?

    2. Re:The best piece of code I have seen so far by r.jimenezz · · Score: 1

      It's a good thing the VM has been GPLed recently - I for one had never dared reading its code, just in case I later decided to contribute to some clean-room implementation.

      --
      The revolution will not be televised.
    3. Re:The best piece of code I have seen so far by ShakaUVM · · Score: 1

      I've dealt with very major bugs in Java, as a result of the JVM being implemented differently on different platforms, especially on minor platforms, like IRIX.

      Since Sun thought it would be awesome to get rid of #ifdefs, because, you know, they're not necessary, we had to essentially kludge together some nasty looking code to get the program to run correctly crossplatform... which is just stupid, since that is what Java was designed to do.

    4. Re:The best piece of code I have seen so far by ls671 · · Score: 1

      Of course, I wasn't saying java is some kind of perfect solution. Even in Sun's reference implementation there is plenty of bugs http://bugs.sun.com/bugdatabase/index.jsp.

      I wasn't talking about the write once, runs everywhere Sun's paradigm either, that's another story ;-) Well written C/C++ code is pretty much write once, runs everywhere too.

      I was just saying I like the product overall.

      --
      Everything I write is lies, read between the lines.
  21. RAll? by Anonymous Coward · · Score: 0

    What is RAll? I've never heard of that term before and quick search didn't show anything. Thanks!

    1. Re:RAll? by Caine · · Score: 0

      How much do you suck at searching? The first hit is a good Wikipedia article.

    2. Re:RAll? by Anonymous Coward · · Score: 0

      Oh! I was reading those last two letters as lower-case L's, not capital I's. Much appreciated!

    3. Re:RAll? by WilliamSChips · · Score: 1

      He misspelled the Is as ls.

      --
      Please, for the good of Humanity, vote Obama.
    4. Re:RAll? by compro01 · · Score: 1

      not if you mistake the I's for L's, as a number of fonts don't differentiate between them. same with 0 and O. one of my pet peeves regarding fonts.

      --
      upon the advice of my lawyer, i have no sig at this time
    5. Re:RAll? by scotch · · Score: 1
      What kind of acronym starts off with two caps and the has two lower case letters?

      Doesn't seem like a reasonable ability to read or google was demonstrated.

      --
      XML causes global warming.
    6. Re:RAll? by MysteriousPreacher · · Score: 1

      I miss the old fonts that had a line through the zero so you knew it was a numberal. Them Nordics had to come along though and spoil things.

      --
      -- Using the preview button since 2005
    7. Re:RAll? by compro01 · · Score: 1

      you'd probabalely like one of the proggy fonts. several of those have that nice slashed zero.

      --
      upon the advice of my lawyer, i have no sig at this time
  22. NetBSD has got quite a good reputation. by Noryungi · · Score: 1


    Such a good reputation, in fact, that an entire book has been devoted to reading its source code. It has a reputation for correctness and portability (duh) and seems an interesting starting point.

    Since I am only getting started in C programming, though, I can't recommend this book. Or the NetBSD source, either.

    --
    The right to offend is far more important than the right not to be offended. (Rowan Atkinson)
    1. Re:NetBSD has got quite a good reputation. by TheRaven64 · · Score: 1

      Bits of the NetBSD kernel are nice, bits are ugly. The driver subsystem is very nice from a high-level perspective, but individual files are often quite crufty. Take a look at OpenBSD code, and you'll see the difference. OpenBSD began life as a cleaned-up NetBSD, and it's continued this way.

      --
      I am TheRaven on Soylent News
  23. 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"!

  24. Angband by mr_Spook · · Score: 1

    I haven't worked on it much per se, but I really like the code in Angband. The style is generally consistant and easy to look at, not to mention quite well commented. Of course, it's also the first C code I ever looked at, so I'm probably a touch biased.

    Angband.

  25. Re-writes are necessary sometimes... by __aasyaa1156 · · Score: 1

    We are currently in the beginning stages of a large project where I work. We are going to consolidate 2 Win32 apps (one C# and one Delphi) and 8 websites (all ASP classic) into 3 separate web applications (ASP.NET). We are also going to be re-writing most of our database stored procedures and restructuring pieces of the schema. You may be asking, why do all this? The reason is two-fold. The first is obvious: Not having to write the same or similar code multiple times in multiple languages. The second is even more important: Poor design of the existing system. There are a number of pieces of our current system that are so poorly designed that it is almost impossible to maintain them, let alone expand on them. At some point, a re-write becomes the best solution. The important thing to remember (in my opinion, anyways) is not just to re-write, but to re-design the system. Don't port broken logic and functionality to a new language. Take a step back, ask yourself what the problem you are really tring to solve is, and write the best possible solution. Well, that's my 2 cents!

  26. libjpeg by unkept · · Score: 2, Interesting

    the independent jpeg group's libjpeg is pretty well written in terms of style and design

  27. Uh.. by Anonymous Coward · · Score: 0

    TeX?

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

  29. Peer-reviewed code by Anonymous Coward · · Score: 0

    At the company I work in, there is code that is generated to get a job done, and grows organically as it is required to do new things. That type of code always looks horrible, and anyone who sees it is tempted to rewrite it.

    But we also have a lot of code generated for projects, that follow properly thought-out plans, and is subject to code reviews by all members of the programming team. Reviews enforce correct use of the agreed programming guidelines, including appropriate commentary and documentation.

    I'm guessing that a lot of open-source software falls into the first category - tools to scratch specific itches, hacked to do more stuff, and then unleashed into the community.

  30. PHP example... by Anonymous Coward · · Score: 0

    In particular I am interested in large user applications using modern C++ libraries and techniques like exception handling and RAII."

    This fulfills none of your requirements, but I am constantly hearing that Drupal is the final word in excellent code for PHP...

  31. LLVM is a pretty C++ application by Anonymous Coward · · Score: 1, Informative

    Check out the LLVM project, a compiler infrastructure package written in C++. It's a pleasure to hack on LLVM, but a nasty chore to hack on GCC.

  32. The linux kernel by A+beautiful+mind · · Score: 2, Informative

    It's code is pretty good. The quality and formatting standards are pretty high for the kernel, which shows in the research about bugs/line ratios too.

    --
    It takes a man to suffer ignorance and smile
    Be yourself no matter what they say
    1. Re:The linux kernel by Anonymous Coward · · Score: 0

      Except for the parts written by Kuznetsov. Especially in 2.6 kernel.

    2. Re:The linux kernel by gatkinso · · Score: 1

      You are joking, right? Much of the code in the kernel could win IOCCC hands down.

      Christ get past tabs, indentation, and nameing standards.

      This is not to say it is BAD code, but 'pretty' is not a word most would use to describe it.

      --
      I am very small, utmostly microscopic.
    3. Re:The linux kernel by ClamIAm · · Score: 2, Interesting

      Much of the code in the kernel could win IOCCC hands down.

      Which parts?

    4. Re:The linux kernel by mandolin · · Score: 1
      Which parts?


      In general, the "not-sexy" stuff.


      In particular, some of the more obscure drivers. Sorry I do not have source on me at the moment, I'm thinking of an older ethernet driver that I needed to get working on a different arch, that used uncommented hard-coded values everywhere to do its work. The serial drivers were also ugly at the time: despite the presence of a "generic" serial driver (thx to Alan Cox?), several of its siblings still did the cutn'paste thing, probably due to lack of interest in cleaning them up.


    5. Re:The linux kernel by ClamIAm · · Score: 1

      some of the more obscure drivers.

      Well, this is probably the source code equivalent of walking through a minefield.

    6. Re:The linux kernel by Anonymous Coward · · Score: 0

      The serial drivers were also ugly at the time: despite the presence of a "generic" serial driver (thx to Alan Cox?), several of its siblings still did the cutn'paste thing, probably due to lack of interest in cleaning them up.

      It would be interesting to look at the code now to see if it has been cleaned up.

  33. Some proprietry UNIX kernel code was a work of art by Anonymous Coward · · Score: 0

    I got to see an illegal copy of some propriety UNIX kernel code and it was a work of art.
    That version of UNIX no longer exists... MSFT means computer to most people.

  34. Enlightenment by Anonymous Coward · · Score: 0

    The only code I've looked at an thought, "Wow! this is really clean code" was the Enlightenment code.
    Of, course, it *is* a complete rewrite of an old codebase - so it should be.
    Mind you it's been a few years since then - it's probably a complete tangle now..

  35. vsftpd by Anonymous Coward · · Score: 0

    Considering the mess that is the FTP protocol, it's very pretty code for implementing that protocol.

  36. It's a matter of taste by robcfg · · Score: 1

    At least, most of the time. There are times you see some code from another person and it can be very well done but appear a complete mess to you because everybody thinks different and when it comes to implementing code these differences can make you rewrite a whole system.

  37. Disgust by the_kanzure · · Score: 2

    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.
    If only mess you see when reading code, then programmer you are not-- a programmer must have the most serious mind, the deepest commitment. See more than mess, he must.
    1. Re:Disgust by VGPowerlord · · Score: 1

      Learn to use the force, you must.

      --
      GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
    2. Re:Disgust by Weaselmancer · · Score: 1

      Learn to use the source, you must.

      --
      Weaselmancer
      rediculous.
    3. Re:Disgust by TaleSpinner · · Score: 1


      Forth love if honk then.

    4. Re:Disgust by Anonymous Coward · · Score: 0

      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.
      If only mess you see when reading code, then programmer you are not-- a programmer must have the most serious mind, the deepest commitment. See more than mess, he must. English, motherfucker, do you speak it?
  38. Developers Developers Developers Developers by rubypossum · · Score: 1

    Having worked on large scale projects at different companies in many languages; Perl, C++, C, C#, Java, PHP, Python, Ruby and COBOL (yes, COBOL.) I can say that Ruby seems to have the best balance of power vs. cleanliness (although it lacks the built in functionality of Java or the sizeable Perl CPAN.) Java and C# manage complexity very well but lack the power of a scripting language. Python seems to be equal to Perl in its ability to manage complexity. It all comes down to programmer discipline. One company I worked for had two million lines of Perl in their main product! Because they had good programming practices it was very easy to maintain (OOP programmed and POD documentation for everything.) On the other hand, I've been handed Java code to maintain that was a mess. Poorly named methods, mysterious inheritance quirks and completely undocumented algorithms (i.e. lots of for loops with j and i variables.) To summarize with a famous quote "Developers! Developers! Developers! Developers!".

    --
    I have a theory that the truth is never told during the nine-to-five hours. - Hunter S. Thompson
    1. Re:Developers Developers Developers Developers by Anonymous Coward · · Score: 0

      Ruby reminds me quite a lot of Lisp (in more ways than one, but primarily) in that behind every nice, clean piece of code that does something elegantly, there's usually some gnarly bit of metaprogramming you wouldn't want to maintain yourself making the whole thing possible.

  39. Great Question by diosmio · · Score: 1

    This is a great question. In my experience many programs that work well often have code that is not pretty at first reading. The important thing I think is to understand both the code AND the environment in which the code was written. I think considering one without the other is pointless. Was the management geek averse? Were the engineers formally trained or did they learn by doing? Was there a time crunch, a big customer waiting without baited breath for the new piece of software? Did the developers focus on it working well with minimal configuration regardless of the elegance of the framework? Was the group all about mental masturbation and framework creation rather than implementation, testing and actually finishing something? I think it may be time for a kind of Natural Selection/Turing Test to asses the quality of a particular development approach: Imagine if you had a large sample of users. Now if all of these uses feel that the software performs exceptionally at its task that it is just flat-out awesome can we conclude that those who wrote it did an excellent job? If those that wrote the software did an excellent job, by this standard, then regardless of what approach they took, they produced great software, even if it did not follow one particular school of software development. The bottom line is that the environment and the approach play a role in selecting what software is "good". Another point to consider is that Software Engineering/Development is a relative child (Internet is 16 years old or thereabouts) compared with other more mature disciplines. Consider Electrical Engineering or Industrial Engineering, compare an Anti-Lock breaking system to a virus scanner or a modern UI with a modern speaker enclosure. Where is the "schematic diagram" for a program (and please don't say UML)? I follow the sort of evolutionary approach I guess. Design a good deal (use patterns and language facilities where appropriate), but focus on getting the thing working and working well; test it a lot, move it around as soon as you can (e.g. deploy it to a new environment), get it in front of judges(users) then enhance and test lots more, get it out there fast, but not totally kludged together. After a few iterations of this a real framework emerges (the kind software preachers say is there from the beginning) which should as soon as it is visible be implemented.

    1. Re:Great Question by domanova · · Score: 1

      Indeed, a fascinating question. Worthy of thinking what measure to use to find some answers. I'm not sure I really care if I can read the code for an FFT, as long as it has good test credentials, but some things I need to get my head round.
      When it comes to an OO structure, I am impressed if I can find the object I need to [derive,extend,whatever] easily, and the thing allows me the power to extend while refusing opportunity for self-immolation.
      I'm not sure you could ask for perfect from anything. In the last decade I've been happy with most, but not all, Java libraries (although I don't do graphics that way) in that they are reasonably consistent, well thought through and let me do rational things.
      I've also crossed some in-house C++ financial systems which are utterly terrifying - in particular from the exotic options floor of an London investment bank - where you extend an object at your peril. I guess it kept the guys in a job.

      --
      Down with categorical imperatives
  40. Drupal PHP CMS by wikinerd · · Score: 1

    Having contributed code (the mysqli layer) to the Drupal PHP CMS, I can say that its code quality surpasses that of most other PHP projects, and is an example of good PHP workmanship.

    1. Re:Drupal PHP CMS by Anonymous Coward · · Score: 0

      Drupal is quite possibly the only good-looking PHP app. It's impressive, makes me feel like the PHP language itself isn't even worthy of it. Prado is another, though more for the idea than the quality of the source. Of course, being PHP makes these run on all kinds of web hosts, so I suspect that's the main reason for it.

    2. Re:Drupal PHP CMS by Anonymous Coward · · Score: 0

      Yeah, dude. That's some seriously nice code. Regexp hacks to rewrite SQL-queries, no error checking, useless comments...

    3. Re:Drupal PHP CMS by Firehed · · Score: 1

      The code may look beautiful, but the content management back-end is one of the most confusing I've ever dealt with. That, or I was just expecting it to act too traditionally and missed something fantastically obvious. For all the praise I've seen it receive, I expect the latter to be the case.

      I certainly hope it's neater under-the-hood than Wordpress is (I haven't examined the source at all). I went about starting to write my own theme templates for WP... the inconsistencies throughout never cease to amaze me. And the inefficiency? Wow. If I weren't concerned about a) porting over my existing data and b) XML-RPC/trackbacks/automated stuff that I don't understand in great depth, I'd just write my own blog software from scratch. It may be feature-rich, but almost every function that dumps out actual HTML calls up three levels of sub-functions. I mean... was a replacement for echo() really necessary?

      --
      How are sites slashdotted when nobody reads TFAs?
  41. nojoke by Anonymous Coward · · Score: 1, Informative

    emacs source. a work of art.

    1. Re:nojoke by Charliems · · Score: 1

      vi is better :)

  42. Shouldn't that be Maturity == Mess? by tylersoze · · Score: 1

    Or did you actually mean to assign the value of Mess to Maturity? ;)

  43. Urban sprawl == mess by einhverfr · · Score: 1

    From my project, I will give you a few examples of old code (horribly messy) vs new code (could be better but far less of an issue):

    New code (not perfect by any means but not quite a F#$%*&^ mess).

    Request handler: http://ledger-smb.svn.sourceforge.net/svnroot/ledg er-smb/trunk/lsmb-request.pl
    Login Script: http://ledger-smb.svn.sourceforge.net/svnroot/ledg er-smb/trunk/scripts/login.pl
    Template: http://ledger-smb.svn.sourceforge.net/svnroot/ledg er-smb/trunk/UI/login.html

    Old code (calling it a F%$^&*g mess is being too kind...):
    Request handler: http://ledger-smb.svn.sourceforge.net/svnroot/ledg er-smb/branches/1.2/menu.pl
    Login Script: http://ledger-smb.svn.sourceforge.net/svnroot/ledg er-smb/branches/1.2/bin/login.pl
    What, no template? Notice all those print statements?

    --

    LedgerSMB: Open source Accounting/ERP
    1. 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
    2. Re:Urban sprawl == mess by chromatic · · Score: 1

      Don't take that as an example of great Perl code; I counted four likely mistakes in the first program alone.

    3. Re:Urban sprawl == mess by einhverfr · · Score: 1

      Hence the mention of "could be better but far less of an issue." My major point was that a whole lot of the discussion of "F#$%^*( mess" is somewhat relative.

      There are actually several areas of active development to make the new framework more robust. The request handler is one of those areas. Note that this is still far in advance of any release of production code and certain areas (including the request handler) are due for review and secondary re-engineering.

      What you are missing in seeing the second program (but present in other files) include custom extensions of anti-patterns such as:

      * Why have magic strings when you can have magic comments? (comments which, if you delete, will cause the program to fail or behave other than expected).

      * The old code uses an accumulate and fire god object for pretty much everything which it passes to functions through that \%$form construct. The login page handles everything through the request object because there isn't any other option. However, other areas actually instantiate other objects from child classes for business logic purposes and pass data to them. How revolutionary! :P

      Of course we still have a ways to go before 1.3 (even for just code quality).

      No, I wouldn't hold this up as great Perl code nor did I claim to (I do think we have a great architecture we are moving to but that is another matter). However, if you don't like the new code example, I fear for your sanity if you look at the old ones.

      --

      LedgerSMB: Open source Accounting/ERP
  44. Not untrue - remember "Netscape"? by Anonymous Coward · · Score: 0

    There's a reason why they junked the code base for that browser.

    And it wasn't just the browser. I've actually seen the code that Sun bought from Netscape - what Sun now sells as "Directory Server" and what used to be iPlanet, IIRC. Good fucking lord is that a TURD.

    If anyone of you out there ever hires a coder with "Netscape" on their resume, you've got some serious 'splainin' to do...

  45. python by codepunk · · Score: 3, Insightful

    Just about all code I have seen written in python is great looking stuff..mainly because of
    the imposed indentation and clear language characteristics.

    --


    Got Code?
    1. Re:python by Breakfast+Pants · · Score: 0


      @yes
      def python(self, is=r'''sweet''', pretty=ur"""and""", **generally)
              return self.__pretty__

      --

      --

      WHO ATE MY BREAKFAST PANTS?
    2. Re:python by Breakfast+Pants · · Score: 0

      (Blast--I forgot the colon. That irrelevant piece of mandatory extra verbiage would have made this example *so* much prettier)

      --

      --

      WHO ATE MY BREAKFAST PANTS?
    3. Re:python by WilliamSChips · · Score: 1

      Why the fuck would you be using raw triple strings for something like that? The Zen of Python says that there should be one obvious way to do things(as opposed to Perl's TIMTOWTDI) and that is obviously the wrong way.

      --
      Please, for the good of Humanity, vote Obama.
    4. Re:python by a.d.trick · · Score: 1

      Java: for the verbose obsessive-compulsive in all of us.

      There, fixed that spelling error for you ;)

    5. Re:python by Anonymous Coward · · Score: 0

      On that note:

      The questioner asked about C++ specifically. I don't know that anybody (even Bjarne) claimed that C++ was a "pretty" language. I've heard its practitioners say it's a "practical" language, and use that as an excuse for all kinds of cruft (which I don't want to debate here). But "pretty", never.

      I've seen beautiful code in Python, Scheme, Ruby, Common Lisp, and even a little C. But not C++. It's just not a language that encourages beauty.

    6. Re:python by Ambidisastrous · · Score: 1

      I think that was the point.

      Anyway, at least the "wrong way" takes more effort in Python. Except for the missing colon -- but colons and whitespace vs "end" vs curly braces is an argument nobody wins.

      The biggest flaw in Python is that Pythonistas get too defensive when talking about the lesser flaws. Python's sweet, but it's no silver bullet.

    7. Re:python by sedholm · · Score: 1

      Python code looks fairly neat, but that doesn't keep you from doing ugly things:

      class Foo:
          def value(self, v):
              f.value = v

      f = Foo()
      f.value(42)
      print f.value

  46. I hereby nominate my own code! by ulatekh · · Score: 1

    y4mdenoise is a temporal video denoiser I wrote some years back. Oh, if I only had time to continue working on it...I'd love to port it to Cell. Damn day jobs.

    --
    "Once we've identified and embraced our sickness, we'll have strength...and that's when we get dangerous." - John Waters
  47. 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.

    1. Re:Amazing by slart42 · · Score: 1

      At my last job, I was trying out the new spotlight when Mac OS 10.4 came out. Of course you first try out search engines by entering the word "fuck". It turned out that the large majority of results were source code files from the project we were working on (Seems I have way to little pr0n on my disk):

      "This is really fucked up"/"Apple fucked up the implementation of this API"/"No idea why the fuck this works"/etc..

  48. Sure there is. by kotletzielony · · Score: 1

    Code of Fruit chess engine is very good. (and it's a very strong and simple engine) http://arctrix.com/nas/fruit/ Libego library (Go game angine) is nice as well. http://www.mimuw.edu.pl/~lew/ They say Netscape code is nice, but I can't find it ...

  49. postfix by hey · · Score: 2, Insightful

    postfix (the mail program) looks pretty nice to me.

  50. C++ and Clean Code by tom's+a-cold · · Score: 1

    C++ has a mix of very low-level and high-level features. That, plus a plethora of side-effects and a huge range of features, means that your chances of a large "clean" C++ code base aren't great. Someone would have to enforce coding standards that limit the use of certain language features in order to get it to a maintainable state. Only then can a code base be well-maintained. If you like clean code, semantic complexity is your enemy, and C++ has highly complex semantics once all those overlapping features start interacting.

    So there might be clean C++ apps out there, but it's going to be like the proverb about a dog walking on its hind legs.

    Ruby or Python, on the other hand, are a different story.

    --
    Get your teeth into a small slice: the cake of liberty
    1. Re:C++ and Clean Code by gatkinso · · Score: 1

      That is not true - I work on a very large C++ project that is well nigh a work of art.

      Any one who answers this topic basing their point on lanaguage alone should be 1) modded down, and 2) dissmissed out of hand as being a complete and utter ameteur.

      --
      I am very small, utmostly microscopic.
  51. God's code by Tablizer · · Score: 0, Troll

    God did an esquisite job on the human brain. It is well-structured and well-commented. However, I pissed him off once and he thus made me a mere mortal. Now I cannot understand any of it.

    1. Re:God's code by jdigriz · · Score: 0, Troll

      While the source may be well-structured and well-commented, it's extremely poorly designed for its functionality. It's constantly getting into states that are difficult if not impossible to get out of. There's no easy way to reload the software or initialize the system so as to start over with a clean state. Its logic is suspect unless the neural net has had long training times, and in power-save mode there's all sorts of extraneous activity. It's also a bear to modify the code directly without resorting to training the neural net. And don't even get me started on the lack of debug data.

    2. Re:God's code by Tablizer · · Score: 1

      But God *wanted* chaos in his simulation. He got board with the "Brady Bunch" version.

  52. OpenBSD by Anonymous Coward · · Score: 1, Informative

    wins hands down. Contrary to popular belief, it's not about security, it's about quality. Security ensues.

  53. Are you kidding? by Anonymous Coward · · Score: 5, Insightful

    Boost is what I call "template madness". It uses template metaprogramming to the max, which (in the real world) means three things:

          (1) It's impossible to debug. You can't read the code. The debugger can't unravel the templated variables and stuff in any meaningful way for you. You can't even step through code, that's doing a supposedly simple operation like memory allocation!
          (2) Some compilers will choke on the code, or compile it wrong in subtle ways due to differing interpretations of some obscure section of the enormous C++ language spec.
          (3) The error messages from the compiler are useless. You have to run them through a filter to even figure out what they mean.
          (3) Bugs in the library are very difficult to fix. Template metaprograms are essentially programs written in a functional language, except one that has horrible syntax. This is not the stuff that normal C++ programs are made of.

    Your mileage may vary. My day job is working on a game engine for an upcoming Xbox360 game. Engines are hard enough without impractical crap like template metaprogramming in them. Give me straight-line C/C++ code any day.

    1. Re:Are you kidding? by JNighthawk · · Score: 5, Insightful

      Mod up. AC knows what he's talking about.

      Even beyond that, Boost fills up the symbol table quick as hell, because of how templated it is. I worked on a project that used LuaBind, which requires Boost, extesnively. We eventually had to swap over from Visual Studio 2003 to 2005, because of Boost's templating filling up the symbol table. Visual Studio would just fail to compile. Lua's hard enough to debug as it is, but tossing Boost on top of it made it impossible.

      --
      Wheel in the sky keeps on turnin'.
    2. Re:Are you kidding? by blackcoot · · Score: 1

      how is that a problem with boost rather than a crap compiler / linker implementation issue?

    3. Re:Are you kidding? by Bryan+Ischo · · Score: 1, Insightful

      Thank you for that, your post is right on the money. C++ template metaprogramming is just a horrible, horrible idea, and because Boost is so fundamentally geared towards template metaprogramming, I have to refuse to ever use Boost wherever I get to make the decision. It's unfortunate because the Boost library is very closely tied to the "future" of C++ (I believe that large parts of it are going to be incorporated in the C++ standard soon, and I suspect that C++ and Boost will become more and more intertwined as time goes on). This sucks because it means that as time goes on C++ is going to get less and less useable. Why can't they just leave a good thing alone?

    4. Re:Are you kidding? by immerrath · · Score: 1

      If you use it cautiously and gently, Boost greatly improves the expressiveness of C++. C++ is a dolt by itself, Boost makes it a person of slightly below-average intelligence with Tourette's.

    5. Re:Are you kidding? by Jeremi · · Score: 1
      how is that a problem with boost rather than a crap compiler / linker implementation issue?


      It's actually a problem for people who are required to use boost in conjunction with a compiler that isn't quite up to boost's requirements (i.e, most of the compilers out there). It doesn't really matter which software you point the finger of blame at, the problem is still there.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    6. Re:Are you kidding? by abdulla · · Score: 1

      Personally I'm not a fan of LuaBind, mainly because it's not as flexible as I'd like and it seems to be getting out of date. But using template metaprogramming techniques, you can create a much cleaner and smaller bridge. Also things like the preprocessor metaprogramming library that comes with Boost are just invaluable. I find if you use Boost judiciously, it can be a very handy tool. A lot of the things it has you'd rather not write yourself, unless you have the time and there is a clear benefit.

    7. Re:Are you kidding? by Anonymous Coward · · Score: 0

      ...enormous C++ language spec...Give me straight-line C/C++ code any day.
      This is SO sad. It's not C++ is the law of nature/physics, but we have to put up with this crap.
    8. Re:Are you kidding? by JNighthawk · · Score: 1

      It was a student project and LuaBind was easier and, more importantly, quicker than writing the bindings ourselves. Boost seems too black-box/managed for my tastes, with most of the code leaning more towards safety than speed.

      I should preface my comments with the fact that I'm a game programmer, so speed is more important than idiot-proofness to me. I've never taken a look at the preprocessor metaprogramming library, just asio and LuaBind. I've never used asio (honestly, I'd prefer dealing directly with the sockets than trying to figure asio out), but LuaBind seemed to work alright, if a bit slowly.

      --
      Wheel in the sky keeps on turnin'.
    9. Re:Are you kidding? by Anonymous Coward · · Score: 0

      which of well-designed, well-implemented, peer-reviewed & tested do you not like?

      i'll bet you money that you harbour a very special longing for the good old days of k&r when "nothing happened behind your back"

      the world will never run out of luddites

      it's called abstraction, stupid

    10. Re:Are you kidding? by kraut · · Score: 1

      So the fact that MS still can't write a decent C++ compiler after 18 iterations is boost's fault?

      Actually, they're almost decent now. And some parts of boost are a bit... esoteric. But on the whole it's a damn useful library.

      As for template error messages... yes, they suck a bit. But after a while you grok them.

      --
      no taxation without representation!
    11. Re:Are you kidding? by Anonymous Coward · · Score: 0

      Okay, so is that a problem of Boost or a problem of the specific compiler? I would say the compiler.

      Also, what Boost is trying to achieve is very valuable, and it cannot be achieved in any other way than by using template meta-programming (among other techniques) without losing much of it's strength. Now, C++ template meta-programming sure is _ugly_, but is that a problem of Boost or of C++? I would say C++.

      In fact, if C++ was greater than it is, what Boost provides would already be in the standard library (which it aims to be, module by module).

      The concept of compile-time programming is very powerful, it is just a shame that it has to be expressed in such an ugly sub-language in C++. It should be more of a "direct" feature, not a clever indirect use of existing language features. Another way to go would be to use a dynamic language such as Python as a very intelligent "preprocessor" that could generate compile-time C++ code for you, instead of using C++ to express the compile-time stuff. The problem is that it is not trivial for Python to interact elegantly with your C++ typesystem etc. without more or less being able to parse and understand C++ code. /David

    12. Re:Are you kidding? by Anonymous Coward · · Score: 0

      Seriously - your whole complaint can be summed up as "I don't understand template metaprogramming, so it must be stupid". Has it occurred to you that this might be a field of study for you, instead of something to put down?

      I'm not saying that all of your points are invalid - but some are to do with your understanding, some are to do with broken compilers, some are to do with compiler's lack of "intellience", and none can be explained as boost being bad in and of itself.

      I'm not trying to say that boost does everything perfectly either - but don't flame something you don't understand.

    13. Re:Are you kidding? by Surt · · Score: 1

      I would have to say that yes, designing your implementation in such a way as to be incompatible with the majority of tools represents a design flaw on the side of the implementation, not of the tools.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    14. Re:Are you kidding? by JNighthawk · · Score: 1

      Agreed. It's like trying to use 'export' and then complaining that the compiler sucks because it doesn't support it.

      --
      Wheel in the sky keeps on turnin'.
    15. Re:Are you kidding? by JNighthawk · · Score: 2, Insightful

      It being ugly and hard to debug is a problem of both, but regardless, the problem exists and it causes many of us not to adopt Boost.

      --
      Wheel in the sky keeps on turnin'.
    16. Re:Are you kidding? by Anonymous Coward · · Score: 0

      I can't understand this "C++ libraries are ugly/too hard to debug" argument. If the code seems convoluted or strange, it is very probably so for a reason. Have you ever looked inside glibc? Its code is quite complex and convoluted too. But you normally don't care, as you are a user of the functionality. Idem dito for Boost and STL on the C++ side of the fence.

      I can't count the number of times a colleague said "I can't understand this Boost (/STL) stuff, it's so weird it's probably wrong. Instead of using it, I'll just write my own shared_ptr (/container) which will be much cleaner and faster", only to end up with a class which, after several revisions and missed deadlines, still isn't exception safe or thread safe.

      Why is it that every programmer assumes he's The Worlds Smartest, who can easily hand-code way better stuff than is available in the libraries?

    17. Re:Are you kidding? by Anonymous Coward · · Score: 0

      Replying to each your points:

      1) Impossible to debug? You cannot debug. Templates become code. Then you debug.
      2) Use good compilers.
      3) Error messages are useless because you don't know how to read the code. See 1.
      3) I introduce you to the number 4 (four). So heavily templated code is not the stuff normal C++ programs are made? You couldn't be any stupider if you tried. Check out the STL, yeeeessss, another useless heaviliy templated code. Unreadable and unusable. Oh, and "some" compilers "choke" on it.

      You, sir, are not programming a game engine. You are far too inexperienced. You are probably doing menial tasks with the code the real programmers wrote to code a game engine.

      "Some compilers" "A game engine" "Bugs are very difficult to fix" You have skyrocketed to the first number in my list of slashdot posers. Have a nice day.

    18. Re:Are you kidding? by alexeiz · · Score: 1

      It's actually a problem for people who are required to use boost in conjunction with a compiler that isn't quite up to boost's requirements (i.e, most of the compilers out there).

      Most of the compilers? It'd be great if you were more specific. In fact most of the compilers are very well supported by Boost. See the following page with the Boost test run for the 1.33.0 release: http://engineering.meta-comm.com/boost-regressio n/1_33_0/developer/summary.html Compilers/platforms that pass the overwhelming majority of tests include: cw- 9_5- darwin gcc- 3_3- darwin gcc- 3.2.3- linux gcc- 3.3.6- linux gcc- 3.4.4- linux gcc- 4.0.0- linux gcc- 4.0.1- linux intel- 8.1- linux intel- 9.0- linux gcc- 2.95.3- linux gcc- 2.95.3- stlport- 4.6.2- linux gcc- 3.4.3 tru64cxx65- 042 gcc- 3.3.6- osf1 gcc- 3.4.4- osf1 tru64cxx65- 042 tru64cxx71- 005 gcc- 3_4_3- sunos sunpro- 5_3- sunos mingw- 3_4_2 como- 4_3_3- vc7_1 mingw- 3_4_4 vc- 8_0 vc- 7_1 borland- 5_6_4 cw- 8_3 vc- 6_5 vc- 6_5- stlport vc- 7_0 vc- 7_1 vc- 8_0 intel- win32- 9_0 cw- 9_4 intel- win32- 8_1

      Actually the only few breaks are on new VC++ 8 and Intel 9 compilers. Older compilers are better supported.

    19. Re:Are you kidding? by Anonymous Coward · · Score: 0

      gfilt, my ninjas. it is all about gfilt.

    20. Re:Are you kidding? by Jeremi · · Score: 1
      Most of the compilers? It'd be great if you were more specific. In fact most of the compilers are very well supported by Boost.


      If by "up to Boost's requirements", I had meant "correctly compiles correct code", then yes, I agree. However, what I meant by that was "gives helpful, user friendly errors in response to incorrect code"... which, as I understand it, most current C++ compilers are not advanced enough to do in conjunction with heavily templated code.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    21. Re:Are you kidding? by alexeiz · · Score: 1

      However, what I meant by that was "gives helpful, user friendly errors in response to incorrect code"... which, as I understand it, most current C++ compilers are not advanced enough to do in conjunction with heavily templated code.

      It strikes me you're just trying to guess. When there is nothing left to say, there is this. OK, the first guess failed. Let's redefine "up to Boost's requirements." Maybe the second guess will do. But this one's a miss too. Have you ever used Boost at all? There are only few areas where templates are used heavily: lambda, mpl, spirit. Do you know how many other libraries Boost has? In most of them template usage is moderate by modern C++ coding standards. Heck, Boost smart pointers are not even policy-based (read: less templates). Now, try something else.

  54. Pretty code? by ScrewMaster · · Score: 1

    Not that I've seen. I suppose in that mythical environment where programmers are always given time to do the job right, where requirements are always fully documented up front, and customers aren't allowed to change the spec at will ... sure, I imagine there's plenty of pretty code there. Now, I've never worked in such an environment, and I've taken over several large projects along the way and it was usually an ugly, thorny mess. Sometimes it's because the coders just didn't care, or just weren't very good, other times it's because they were barely given enough time to do the job, much less care about niceties.

    The other problem is that code does evolve, does have to change to meet new requirements, and often there just isn't an elegant way to fit those changes into the existing architecture. Other times it's just "make the fix and get it out the door." Anyway you look at it, from an organizational and neatness perspective, code suffers entropy: it goes downhill from bad to worse. Maybe that's different in development environments that aren't subject to market pressures, but I wouldn't know. Research, or maybe government projects? I've been in the industrial sector most of my life and those kinds of projects work to schedules. Meet it or beat it.

    Occasionally, codebase entropy can be reversed, but only temporarily and at great expense. Usually this is done when the disharmony has reached such proportions that the program can no longer be maintained.

    --
    The higher the technology, the sharper that two-edged sword.
  55. It was hard to write... by DoktorSeven · · Score: 1

    it should be hard to read.

    --
    This is a sig. Deal with it.
  56. I'm partial to the classics by Tablizer · · Score: 1


    10 PRINT "THIS IS PRETTY CODE!"
    20 GOTO 10

    1. Re:I'm partial to the classics by Zerbey · · Score: 1

      Nope. You didn't comment it.

  57. There are different types of messes by einhverfr · · Score: 2, Interesting

    My first large project I ever attempted (HERMES, now abandoned, http://hermesweb.sourceforge.net/ had, I believe, reasonably pretty code. Architecturally, there were some pretty parts too. But overall, the architecture was a mess simply because I didn't know better. I eventually abandoned it because I realized it was going to be impossible to fix the initial design mistakes without entirely replacing a large percentage of the code.

    My current large project is LedgerSMB. This deals with an entirely different magnitude of mess. Essentially we forked from a codebase which we have come to understand is nearly unmaintailable and yet we *have* to replace all the code because we have lots of users on the software who rely on it. Hence we are refactoring with an axe.

    The older codebase (SQL-Ledger/LedgerSMB 1.0/LedgerSMB 1.2) has a number of architectural limitations and issues, as well as a lot of evidence of an overall lack of architecture. If that weren't enough, the code is pretty problematic too. It could be worse (at least the codebase is reasonably readible if you put enough effort into it).

    I think it hits about 75% of the software programming antipatterns mentioned on Wikipedia, and extends some of them in weird ways. For example instead of just magic strings, we have magic comments (comments which are actually part of the program code and which deletion causes problems). And we have function calls which pass by "reference-to-deferenced-reference." In perl terms \%$ref.

    Hence we are moving everything to a new and *cleaner* architecture.

    --

    LedgerSMB: Open source Accounting/ERP
    1. Re:There are different types of messes by Chris+Pimlott · · Score: 1

      My first large project I ever attempted (HERMES, now abandoned, http://hermesweb.sourceforge.net/)

      If it's abandoned, do the world a favor and put up a conspicuous note to that effect on the homepage. Nothing is more irritating than wasting time with a program that you only later discover has been dead for years.

    2. Re:There are different types of messes by einhverfr · · Score: 1

      Done. Thanks.

      --

      LedgerSMB: Open source Accounting/ERP
    3. Re:There are different types of messes by einhverfr · · Score: 1

      And just to be clear. Abandoned might be too strong a word.

      Community development has ceased. I only do commercial support and bugfixes on an as-needed basis and am not terribly interested in attracting new users. I will continue to do such support until I have a migration path available for users of the software, and that will probably eventually be to LedgerSMB.

      --

      LedgerSMB: Open source Accounting/ERP
    4. Re:There are different types of messes by spiracle · · Score: 1

      einhverfr, Can you please post an example of a magic comment? Sounds interesting.

    5. Re:There are different types of messes by einhverfr · · Score: 1

      In the LedgerSMB project, in 1.2, we were having trouble getting the database loading functions to work with our SQL scripts (which worked fine in psql). It turned out that the code required the SQL comment:
      -- end function

      after every function.

      A second example is that you see comments scattered throughout the code like #$locale->text('Jan');

      These comments are aggregated together by the script that builds the localization database. Remove them an people's translations stop working next time they regenerate the string db.

      In both these cases, the comments are code. Scary.

      --

      LedgerSMB: Open source Accounting/ERP
  58. Depends on programming language too by Anonymous Coward · · Score: 0

    I find functional languages (lisp, haskell, etc) make cleaner code because, once you know them, they tend to promote readability.

    Even though C/C++ were my first two languages, I never found the readability great. There are several factors - confusing/complex order of operations, shortened function names, lack of reusing code.

    Even for the simplest pieces, I found that the code had to be read several times to be understood.

    In my experience, it is C++ that ends up being a pile of spaghetti the more complex and demanding the task gets - it is not an easy thing to recoordinate the code once the task changes even slightly without resorting to kludges.

  59. OpenSolaris by jlarocco · · Score: 5, Informative

    As large and old as it is, OpenSolaris has fairly readable code. Plus, most of it has comments explaining why it's done the way it is.

    1. Re:OpenSolaris by spyowl · · Score: 1

      I found Postgres code has similar qualities. I would also nominate Qt 4.x and Reiser4.

    2. Re:OpenSolaris by Anonymous Coward · · Score: 0

      You're obviously clueless if you really think so. If you want really clean code, check out NetBSD and OpenBSD - beats OpenSolaris and many others by far.

    3. Re:OpenSolaris by TheRaven64 · · Score: 1

      I'd forgotten about OpenSolaris. I poked around some of the code while writing an article about ZFS. It was very clear, close to OpenBSD in terms of kernel code readability, maybe slightly better in places. I'd recommend OpenBSD to anyone wanting to poke around in a kernel as a learning experience, but OpenSolaris might also be another good option. Just avoid Linux unless you want to claw your own eyeballs out...

      --
      I am TheRaven on Soylent News
    4. Re:OpenSolaris by jadavis · · Score: 1

      I second PostgreSQL. It's great code, especially in the lower level parts of the architecture, and the comments are very helpful.

      I have mixed feelings about OpenSolaris (admittedly I don't know much about it). I browsed through the ZFS code a little, and it seemed like good code. However, when I looked here: http://cvs.opensolaris.org/source/xref/onnv/onnv-g ate/usr/src/uts/common/fs/zfs/vdev_cache.c I was very confused about the comment beginning "All i/os smaller...", and it got me more confused when I tried to look for the places those variables were used. The comment at the top says the readahead is 128k, but the code looks like it's 64k readahead (look at the VCBS macro).

      I asked on #opensolaris before I posted this, and there wasn't any response. I could be wrong and I'd be happy to hear an explanation.

      --
      Social scientists are inspired by theories; scientists are humbled by facts.
    5. Re:OpenSolaris by Anonymous Coward · · Score: 0

      You're obviously clueless if you really think so. Yes, obviously anyone who doesn't think your exact same thoughts must be clueless. Jackass.
  60. reSIProcate by Nomen · · Score: 1

    I've been using the SIP stack library reSIProcate http://www.resiprocate.org/ a lot this week, and in general it's a very nice real-world example of RAII and exception error-handling in C++. It has a bit of magic in its reliance on preprocessor macros for defining SIP header-specific methods from a single macro 'template' - but this seems to be the only way to use proper C++ typing to model the different parsed headers and keep things maintainable (although I'm aware people have tried to use mixins and roles in C++, i have no idea how well that works in practice). http://estacado.net/resip-dox/stack/classresip_1_1 SipMessage.html is an example of the doxygen for the fundamental class which describes a SIP message - browsing around the doxygen should given an idea of the rather nice RAII idiom they use, as well as the interesting usage of macros... Picking a file entirely at random, http://svn.resiprocate.org/rep/resiprocate/main/re sip/stack/test/testUri.cxx is both a good example of RAII being used (from the user's perspective), and a fairly good example of a comprehensive C++ unit test (without any faffing around with a unit test framework). The class being tested is their class for expressing SIP URIs (surprise surprise).

  61. perl by Anonymous Coward · · Score: 0

    :(){ :|:& };:

    1. Re:perl by Random832 · · Score: 1

      That's bash, not perl.

      --
      We've secretly replaced Slashdot with new Folgers Crystals - let's see if it notices.
  62. Always improve the code by glimt · · Score: 1

    I've worked as a programmer for Autodesk for a few years. Autodesk has a number of very mature products, and a lot of very old code. Some of the projects have matured better than others and as a result there were some good lessons to be learned from those projects. A couple of things I picked up while I was there: - Anytime you touch a piece of code you should improve it. This will result in the software always improving over time, rather than degrading over time. - Always write the simplest code possible to solve a problem. That is don't over-engineer a solution by designing/building unnecessary elaborate flexible object models for requirements that *might* come down the road. - Assuming you have written the simplest code possible, and that you want to always *improve* the software... If you do get a requirement that the current code doesn't support w/o a kludge then immediately refactor it, but only as much as you need to solve the current problem.

    1. Re:Always improve the code by Gen.Anti · · Score: 1

      To deliberately ignore possible future improvements, hoping this will bring an opportunity of rewriting the code you write at the moment. A fantastic new perspective. Seriously. Thanks.

    2. Re:Always improve the code by glimt · · Score: 1

      Well, if you are guessing, you know you are going to get the requirements wrong anyway, right? :-)

  63. im hesitant.. by jnf · · Score: 1

    I'm hesitant to say there is really any pretty C++ code out there, I do code security reviews for a living and have read a lot of code, and I don't think you can really have a useful C++ application that is also pretty. If I could ask Bjourne one question it would be 'Did you realize someone would have to read the code when the language was designed?' I mean things like placement news, templates, operator overloading, et cetera make the code horrible to read and are quite ugly imho.

    1. Re:im hesitant.. by Cassini2 · · Score: 4, Insightful

      My take on C++ is that the best programs only use a fraction of the features. The language is so big it is dangerous. Just because a feature exists in the language, does not mean it is good for every application. I am very wary of operator overloading and templates too. You need to make your code sufficiently clear that you can be sure it works. if you cannot quickly understand your code, then chances are you made a mistake.

    2. Re:im hesitant.. by ZorbaTHut · · Score: 2, Interesting

      I've been writing C++ code for about a decade. I consider myself competent with almost every weird nook in C++ - I have extensive template metaprogramming in some projects, I've used and abused multiple virtual inheritance, and about the only thing I avoid are exceptions because I feel they're a non-solution.

      And I think you're dead right. C++ is a hideously complex bitch of a language. Anyone trying to use all the C++ features will quickly drive themselves insane. I rarely use inheritance, I rarely make my own templates, I never do operator overloading unless it's absolutely clear what the operators mean (number classes, geometry classes, and string classes, basically.) In many ways, my code looks like C code, albeit C code with obsessive typesafety and extensive use of the STL.

      I've programmed in other languages quite a bit. I honestly feel C++ is the single best language out there. But it isn't for anyone, and it's certainly not for people who can't sit down and say "okay, we need to make this damn program simple."

      --
      Breaking Into the Industry - A development log about starting a game studio.
    3. Re:im hesitant.. by TheRaven64 · · Score: 1

      I've programmed in other languages quite a bit. I honestly feel C++ is the single best language out there. Without wanting to get into a language flame-war, I'm wondering if you've tried Objective-C. I was fairly proficient in C++ when I started learning Objective-C, and so far I've found it to be everything I wanted C++ to be.
      --
      I am TheRaven on Soylent News
    4. Re:im hesitant.. by Anonymous Coward · · Score: 0

      AFAIK, Mac OSX is written in Objective-C and so was Tim Berner-Lee's httpd and browser (while he was working at CERN)

    5. Re:im hesitant.. by ZorbaTHut · · Score: 2, Interesting

      I haven't, honestly. I'm looking at the Wikipedia article and it looks like it's got a lot of stuff that I'm not so interested in, like more reliance on runtime tests and lack of templates.

      While I don't write my own templates, I do use them extensively in the STL, and I'd really miss the typesafety of having them. It looks like Objective C is not nearly as obsessive about typesafety as I am.

      --
      Breaking Into the Industry - A development log about starting a game studio.
    6. Re:im hesitant.. by IpalindromeI · · Score: 1

      If you love type safety, you should check out Haskell.

      --

      --
      Promoting critical thinking since 1994.
    7. Re:im hesitant.. by ZorbaTHut · · Score: 1

      I'm not a huge fan of functional languages, and I'm also not a huge fan of garbage collection. Haskell, as far as I know, is both.

      --
      Breaking Into the Industry - A development log about starting a game studio.
  64. Malbolge? by Rie+Beam · · Score: 1

    "Pretty" is pretty subjective. Some see it as simple, clear, easy to read code. Myself, I find the more esoteric code "pretty" -- Malbolge, anyone?

      (=`:9876Z4321UT.-Q+*)M'&%$H"!~}|Bzy?=|{z]KwZY44Eq0 /{mlk**
      hKs_dG5[m_BA{?-Y;;Vb'rR5431M}/.zHGwEDCBA@98\6543W1 0/.R,+O

    It's pretty in that "sick cat curling up next to you" kind of way.

  65. Agree completely by Statecraftsman · · Score: 1

    I agree completely on X. Y, I've never heard of but given the code I've written I wouldn't be surprised.

  66. Any app that doesn't need to be rewritten... by 3vi1 · · Score: 2, Insightful

    "Any app that doesn't need to be rewritten hasn't grown sufficiently beyond its original intent." - Jesse Litton, 1990

  67. The TCL Source is indeed very nice code... by Anonymous Coward · · Score: 0

    I was going to mention this myself.

  68. Depends - are you an ass, tits, or face man? by gatkinso · · Score: 1

    Or is it the legs that do it for you?

    "Pretty" is a relative term. Pretty code to me is robust, fast, maintainable, short, maintainable, readable, and maintainable: in that order.

    Personally, I am a tits man.

    --
    I am very small, utmostly microscopic.
  69. Inform and the Z-Machine by kurige · · Score: 1
    The Inform Compiler - by Graham Nelson. http://www.inform-fiction.org/inform6.html From the Designer Manual

    Inform is a system for create adventure games ... It translates an author's textual description into a simulated world which can be explored by readers using almost any computer, with the aid of an 'interpreter' program. From the website

    Inform is a design system for interactive fiction, a new medium for writers which began with adventure games in the late 1970s and is now used for everything from literary narrative fiction through to plotless conceptual art, and plenty more adventure games too. Since its introduction in 1993, Inform has become a standard tool.

    The flip-side to "pretty" code is good documentation. There are too few programmers out there who can both write elegant code and explain what it does just as elegantly. I have his "The Inform Designer's Manual, Fourth Edition" sitting on my shelf right now, and I can honestly say that it is the only manual that I have had the pleasure of describing as a "page turner".

    The code itself is equally impressive. Satiated with (helpful) comments, compiles on virtually any platform, easy to read, follow, and modify as you see fit. There's also a separate "Technical Manual" for those who are interested in modifying the original code.

    Let's see... Let's not forget nethack. They thought of everything. :) http://www.nethack.org/

    And then there are always those little tidbits of code like this inverse sqrt function that fall into the it just works category. Code that mere mortals such as myself can hardly comprehend - let alone write! http://www.math.purdue.edu/~clomont/Math/Papers/20 03/InvSqrt.pdf

  70. x windows by WindowsIsForArseWipe · · Score: 0

    "X is a #%@!in mess," Please leave x windows out of this! It works, Don't touch it

  71. damn good by r00t · · Score: 2, Informative

    Some parts are NOT for newbie wimps, but the complex parts are well-justified. Most of the core code ("kernel" directory) is very clean and readable.

    There are useful well-written abstractions, without the typical obfuscating layers of abstraction fluff.

    The code is written to run fast, while still being portable and readable.

    Static checking is all over, but not in-your-face annoying. Some of it involves compile-time assertions. Some of it involves a lint-like tool called "sparse" which makes sure that people don't do things like random math operations on bitmasks and wrong-endian data. Sparse also stops accidental (unsafe) use of user pointers from the kernel.

  72. Yes! by JoeZilla · · Score: 1

    Of course there's a ton of "pretty" code out there.

    Even though even great code bases can quickly turn into a mess by being maintained to hell by unsupervised maintenance programmers and lack of good programmers on the team. Let's be honest, maintenance is boring and which A+ programmer wants to do maintenance. And, let's not forget about stupid business decisions ;-)

    Maybe you need to just find a boutique consulting company or a product development company that honors tech skills!

    If you do want to see great code, look at the code of the Spring framework sometimes!

    - jz

    1. Re:Yes! by djinn87 · · Score: 1

      I can't agree enough. Spring is a pleasure to program with because it makes any Java project easier and because it's great inspiration for how to write great code.

      -matt

  73. Design before you build it by Anonymous Coward · · Score: 0

    Hmm...

    It is always better, in the long run, to design your "house" before you build it. Set some rules for yourself like a naming convention, a class structure that doesn't have too many levels, use templates, pseudo-code the application, type the pseudo-code into the objects, then begin coding. Keep your pseudo-code up-to-date with the actual code. Create a global error handler and use it to categorize and prioritize error resolution. Use CONSTANTS.

    The pseudo-code is your documentation and design implementation. It can be extracted and used to recode quickly in a different language.

    Getting a quick idea and diving into the code is a good way to get something done fast but don't expect it to be understood next time you look at it. You may re figure it out but having to figure it out is time wasted.

    Pretty code, to me, is code that is not obfuscated, is well commented, well laid out, follows a predictable naming convention and accomplishes it's task with finesse and with a minimum of code.

    YMMV
    Codifex Maximus

  74. Ogre3d by Grey_14 · · Score: 1

    Some of the best software for design, functionality and 'pretty' code that I've seen is Ogre3d, a cross platform rendering engine, It's hawt...

  75. Postfix. by Anonymous Coward · · Score: 0

    Postfix. It is well documented, variables given meaningful names - it's a pleasure to work with.

  76. Modular by Christianfreak · · Score: 1

    The best apps are the ones that were written to be extended. If I can write my own module that plugs into a codebase without touching that codebase then it doesn't matter what their code looks like.

    That said, the last place I worked had some pretty decent code. A few perl modules I've worked on, such as HTML::Template were pretty nicely done as well.

    My pointers for good code:

    good indentation. Tabs are preferable but if you use spaces, use just spaces! I can't count the times where I opened a source file and one developer used spaces and another used tabs, or $obscure_editor which completely screws up the flow and makes it nearly impossible to figure out what block a particular line is supposed to be in.

    Good variable naming schemes. The name of the variable should tell me something about what it contains. I'm sure every developer has run into the cute guy who thought it would be fun to start at $a and end at $z. Or $obj1, $obj2 ... $obj27. (I hope there's a special place in hell for that guy)

    Keep it simple. If $language has a short-cut for doing something, learn the shortcut instead of adding 40 lines for how it would be done in C. Don't reinvent the wheel. Also while speed is important, no one cares that your clever algorithm web app 2 nanoseconds faster than the built-in function would. It probably took you 3 extra days of time anyway.

    Keep it consistent. If the developer before you used camel case and you don't like it. Suck it up and use camel case. Same for anything else. Code religion can be fought by the water color or in the coding guidelines meetings. In the source files it just creates a mess for everyone else.

  77. NetBSD by Steinar · · Score: 1

    NetBSD has, in general, quite good code for both reading and understanding. Have a look!

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

  79. 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.
    1. Re:Smell by Anonymous Coward · · Score: 0

      Your friend is an idiot.

    2. Re:Smell by TapeCutter · · Score: 1

      It's a joke, laugh you identity impared troll!

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
    3. Re:Smell by Anonymous Coward · · Score: 0

      No; he's right.
      All shit stinks. The friend is some kind of auto-coprophiliac.

    4. Re:Smell by TapeCutter · · Score: 1

      Jebus AC's are dumb as dogshit, or should I say canine coprolites?

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
  80. Coding Dojo by wrook · · Score: 1

    This is a really great question! But unfortunately I have no really good answers. Working code in the real world runs the gamut from brilliant to horrible. And to make matters worse, this range exists usually within a single project.

    Sorting the wheat from the chaf (sp?) is a difficult task. This is made even more difficult by the fact that you will get as many definitions for "good code" as the number of people you ask. I've thought a lot about what good code means to me. And I've finally arrived at an answer I think is acceptable.

    Good code is code that is easy to modify. The easier it is to modify, the better the code. By "easy to modify" I mean that taken any random problem, the path to making the existing code solve that problem is straight forward and obvious to implement.

    Even with this definition I run into problems. Normally people find their own code easy to modify, and other people's code difficult to modify. Thus, I make the extra statement that the easier it is for other people to modify, the better the code.

    This lets out a lot of "pretty code". Above, someone posted a really great solution to "Hello, world". It is, in fact, extremely pretty. But it is not the simplest solution and thus difficult to modify. I would not call it (nor do I expect the author would call it) "good code".

    Unfortunately I would categorize many "modern libraries" in this same group. They are often extremely well written and very pretty. But using them increases the complexity of the code and the resultant program is not what I would call "good". Often *not* using those libraries results in simpler and better code. But judicious use of the appropriate libraries is also essential to writing good code.

    So, I wouldn't spend too much effort looking for good code. In fact, good code is often hard to recognize unless one tries to modify it (at least if you use my definition). So a better approach would be to practice writing and modifying code. A good place to do that can be a coding dojo.

    These are groups that have sprung up in the last few years that practice doing coding problems. Being able to study these scenarios is one of the most important things you can do to improve your coding ability, IMHO. Most of these dojos use a variant of extreme programming to practice. I believe this is also worth learning, whether or not you end up using the practices on your own.

    Do a google search for coding dojo and check out what they are doing. I think this will be closer to what you are looking for.

  81. Lions' book - Unix 6th Ed by usrerco · · Score: 1

    I don't know about 'pretty', but the Lions' on 6th Ed. Unix is a great example of /clean/ code. I think of it as 'pretty clean'.

    http://www.amazon.com/Lions-Commentary-Unix-John/d p/1573980137/ref=pd_bbs_sr_1/002-4816217-2120035?i e=UTF8&s=books&qid=1184460207&sr=8-1

    As for clean C++, it's harder to appreciate I think because C++ has a bit of overhead to it that makes the code appear more sprawling.. harder to appreciate I think. That said I feel that out of the many C++ apps I've written, large and small, there are a few I think are 'clean' and even, dare I say, almost 'elegant'. But it takes a lot of effort; one can spend a lot of time cleaning things up, and making comments 'just so'. I put the most effort into code that I know will be seen publicly, or might need to be handed off to others.. open source and team oriented work for hire especially.

    1. Re:Lions' book - Unix 6th Ed by Lance+Cooper · · Score: 1

      It is really quite readable, we used it as a text for my Operating Systems class. Though I wouldn't recommend anyone who wasn't already fairly adept look at it too closely, since it doesn't line up with modern practice in many regards (the one that comes to mind is the inclusion of a binary that exec()s /etc/init as an array in main()).

  82. Hence KISS by Silver+Sloth · · Score: 1
    You're spot on - hence the corollory

    Everyone knows that debugging is twice as hard as writing code. Hence, if your're as clever as you can be when you write the code you need to be twice as clever as you can be when you debug it The quote (the sentiment is right even if I can't remember the exact words) is from Elements Of Programming Style by Kerningham (yes, that Kerningham) and Plauger. The book is so old that the examples are in Fortran and PL1 but the lessons are as relevant as ever.
    --
    init 11 - for when you need that edge.
    1. Re:Hence KISS by solafide · · Score: 1

      I think you might mean Brian Kernighan, who wrote the C book. [Also a great book :-)]

    2. Re:Hence KISS by Silver+Sloth · · Score: 1

      At 2am after a night on the town I have trouble remebering how to spell my own name. Yes, I meant the 'K' of K&R.

      --
      init 11 - for when you need that edge.
  83. Pretty? Not mainly. by Tablizer · · Score: 1

    "Pretty" is for weak warriors who want their mommies. Us Klingons have rules to keep the Klingon Spirit in our code:

    # Specifications are for the weak and timid!
    # This machine is a piece of GAGH! I need dual Pentium processors if I am to do battle with this code! You are MISTAKEN!! Only a most excellent machine could be worthy of being compared to a plate of gagh! How dare you! I am NOT mistaken. Machines should not be eaten, they are weapons, they should be hard and sharp, not soft and creepy!
    # You cannot really appreciate Dilbert until you have heard it in the original Klingon.
    # Indentation?! - I will show you how to indent when I indent your skull!
    # What is this talk of "Release"? Klingons do not make software "releases". Our software "escapes", leaving a bloody trail of designers and quality assurance people in its wake!
    # Klingon functions calls do not have "parameters" - They have "ARGUMENTS" and they ALWAYS WIN.
    # "Debugging"? Klingons do not debug. Our software does not coddle the weak.
    # I have challenged the entire quality assurance team to a Bat'leth contest. They will not concern us, again.
    # A TRUE Klingon warrior does not comment his code!
    # By filing this user request, you have challenged the honour of my family! PREPARE TO DIE!!
    # You question the worthiness of my code? I should kill you where you stand!
    # Our users will know fear, and cower before our software! Ship it! Ship it and let them flee like the dogs they are!!
    # Sales people have no honor
    # Four thousand lines of code may be typed in one night by a fast coder.
    # A bug may become a feature in the time it takes to compile the code.
    # Only a fool codes in an IDE.

    (list commodered from c2.com during glorious battle)

    1. Re:Pretty? Not mainly. by Goldberg's+Pants · · Score: 1

      "Our users will know fear, and cower before our software! Ship it! Ship it and let them flee like the dogs they are!!"

      That may be the funniest thing I've ever read on Slashdot in my 9 years as a signed up user.

  84. Racial discrimination by efceeveea · · Score: 0

    I think the more convenient issue here is that programmers need to stop messing around with all there little "codes" and "programs", and just learn to speak binary. Get to the heart of the issue. 010100011101011011011100010110011 Run Jane, Run 0111011001010010101101101010110011110100 See Dick grow.

  85. Prototype by swagr · · Score: 1

    It's not big, and it's not c++, but I think the prototype Javascript library is a pretty good example of where brevity, functionality and "prettyness" should meet in code .

    http://www.prototypejs.org/assets/2007/6/20/protot ype.js

    --

    -... --- .-. . -.. ..--..
    1. Re:Prototype by booch · · Score: 1

      Actually, jQuery code is much more concise and readable than Prototype. It also follows JavaScript idioms better, and has a simpler API. They're fairly similar, and Prototype is becoming more like jQuery over time. But Prototype has a much larger mindshare, so it's used in more projects. I'm hoping they merge some day.

      --
      Software sucks. Open Source sucks less.
    2. Re:Prototype by Zarf · · Score: 1

      It's not big, and it's not c++, but I think the prototype Javascript library is a pretty good example of where brevity, functionality and "prettyness" should meet in code . I'll second that. I think in the case of prototype the natural forces of browser compatibility issues, bandwidth, and peer review have created a beautiful library. If the library wasn't "pretty" it wouldn't survive.
      --
      [signature]
  86. exception handling by r00t · · Score: 1

    You lost "pretty" right there.

    Neither "goto" nor "longjmp" could be so bad. Exception handling takes you up the call chain, over some arbitrary number of calls, right out through arbitrary locations in your code. Holy crap! The bug potential is amazing, as is the obfuscation.

  87. SWISH++ by pauljlucas · · Score: 1

    If I do say so myself, SWISH++ has pretty code.

    --
    If you reply, do so only to what I explicitly wrote. If I didn't write it, don't assume or infer it.
  88. 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.
    1. Re:A experiment by moreati · · Score: 2, Interesting

      Unfortunately I haven't run across any good C++ formatters.

      I'm not trolling, honest. Why wasn't GNU Indent suitable? I'm not a C++ programmer by any stretch, but it seems ideal.
    2. Re:A experiment by vocaro · · Score: 1

      Unfortunately I haven't run across any good C++ formatters.

      What's wrong with Artistic Style?

    3. Re:A experiment by statusbar · · Score: 1

      indent is not good for c++, specifically with the < and > used in templates and the 'public:' etc keywords... "bcpp" is nicer, but not good enough yet for myself, requires a lot of setup. I think boost uses it though...

      --jeffk++

      --
      ipv6 is my vpn
    4. Re:A experiment by baadger · · Score: 1

      Astyle isn't bad. Neither is bcpp. For me though the problem with all these C++ beautifiers is the formatting of the output still depends too much on the formatting of the input. They don't strip all the formatting before rebuilding the source so the results can sometimes be unpredictable. For example, a new line ('\n') after function names and before the parameter parenthesis ( is kept as-is which is a bit of a pain for me as one of my preferred coding habits is to do this:

      int /* I usually new line here only in C++ code, since in pure ANSI C all primitive types are short and readable, and I rarely deal with non #define'd or typedef'd C POD's (struct's) in C. */
      main
      ( /* In most code I see, people don't put a new line here, I prefer it and no beautifier I've tried will support it */
            int argc,
            char** argv
      )
      {

      }

    5. Re:A experiment by moreati · · Score: 1

      Aha, I'd seen it referred to in the Linux kernel style guide for C. I assumed it was equally applicable to C++.

      Thankyou for answering. Alex

    6. Re:A experiment by zobier · · Score: 1

      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." That's the second time in two days I've seen HyperCard mentioned here; I wish Apple would open the source.
      --
      Me lost me cookie at the disco.
    7. Re:A experiment by Anonymous Coward · · Score: 0

      Use indent for C. Use astyle for C++.

  89. There's no such thing by Secret+Rabbit · · Score: 1

    As soon as you go a fair bit beyond the trivial, code is just a mess. There really isn't a way around it. The only reason why people might think that this isn't the case is /because they are used to it/. And there is a significant difference between used to it, and clean.

  90. Thread-safety by Mr.+Heavy · · Score: 1

    I should point out that your DefaultFactory's singleton is not thread-safe, and the entire getInstance() method should be synchronized.

    1. Re:Thread-safety by MillionthMonkey · · Score: 1

      No need to synchronize anything; since the object and its superclass declare no corruptible fields that can be observed in an inconsistent state, protecting the singleton with a static AtomicReference will prevent the worst case scenario (two threads each having their own copy of a stateless singleton) with less overhead than explicit synchronization.

    2. Re:Thread-safety by MillionthMonkey · · Score: 1

      Ahh never mind- the initial reference to the AtomicReference itself would require synchronization on the class lock. Plus we might add more fields to DefaultFactory as we extend it in the future to add more features, so the explicit synchronization is more maintainable. Although maintainability is a questionable objective for this project.

    3. Re:Thread-safety by Billly+Gates · · Score: 1

      I couldn't agree with you more.

      AtomicReference and thread synchronization are an absolute essential in any hello world program for freshmen lvl programming classes. :-)

  91. Refactor Ruthlessly by remitaylor · · Score: 1

    Good thoughts, except I don't accept your argument that mature code is a mess. If developers refactor while coding, mature feature-full code can be almost as elegant as the original code.

    I do like that you mention differing syntactical preferences between developers. We have 3 people on our core team and we all have *very* different ideas about what code is elegant, in terms of: newlines, tabs/spaces, curly braces, etc. We do, however, have common ideas about what parts of our codebase are elegant / easy to work with, and what parts are a "mess." We all have the same sense of code smell.

    The key thing is to make sure developers "refactor ruthlessly." If you keep your code clean and maintainable, you won't find yourself in the situation where you're considering completely rewriting it.

    Also, if you have a good test suite, it makes it easier to refactor (or do big rewrites) as you'll be able to easily see what you broke. In theory, you'll know you're done when all of your tests pass again.

  92. no one is ever happy by fermion · · Score: 1
    Code is really a matter of design. What is important, the factors one wishes to stress, the pet peeves of the developers. For instance, recently there has been much talk about CSS and HTML and XHTML and what is acceptable where. The CSS fanatics will write unreadable code, where the XHTML fanatics will have a coronary if certain HTML is used, even where it makes total sense, i.e. where one is actually marking a peice of text to add to meaning.

    I have worked on several projects in several languages. In general, the code I have been given is of high quality. I might not have written it that way, but I have never had a problem reverse engineering it, understanding the design decisions, and make the corrections. I suspect if code, as all designs, were approached by engineers and not critics we would have much better products.

    In fact the only bad code, as far as i am concerned, is when someone is trying to apply the latest and greatest paradigms without thought or rationale. I have certainly been guilty of this, and have written stuff as bad as the design pattern in this thread. Cleaver code is for contents, not professional efforts.

    I suspect that rather than looking for pretty code, looking for code that teaches a technique would be time better spent.

    --
    "She's a scientist and a lesbian. She's not going to let it slide." Orphan Black
  93. +0.8 by Anonymous Coward · · Score: 0

    You missed a major WTF; HTML in the database layer and the author thinks his code is an example of good design practice. Ugly too When I'm logged into a server and need to diagnose a problem, lines that wrap on an 80 column term quickly become unreadable. Hell, I have to scroll sideways to read it in my fucking web browser.

    1. Re:+0.8 by Anonymous Coward · · Score: 0

      Oh noes!

      Error messages are displayed with HTML formatting. Who'd a thunk.

  94. recognizable story by Device666 · · Score: 2, Interesting

    cruftness = people * time is a reasonable approximation, I can confirm the same kind of stories. Even if the operating system and the projects software would be trustworthy, the consultants would probably %$^& the customers database too. Hurray for corporate politics.

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

    3. 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.
    4. Re:Hello World (Newer Version) by tOaOMiB · · Score: 2, Informative

      You appear to be missing the simple if and else keywords! How do you miss an if-then statement?

    5. Re:Hello World (Newer Version) by p3t0r · · Score: 1

      You're missing some really important keywords like 'implements', 'for', 'if', 'else', 'final', 'abstract', 'interface', 'import', 'package'. To bad, they could make your example better!

    6. Re:Hello World (Newer Version) by Anonymous Coward · · Score: 0

      "if" and "else" are for noobs
      these are ARCHITECTS you're talking to!

    7. Re:Hello World (Newer Version) by Anonymous Coward · · Score: 0

      Indeed - any OO architect could tell you that an if statement would be better expressed through an interface with multiple implementations that provide the actual code at run-time without need for error-prone and hard-to-test if statements. Many of the most basic patterns such as the State pattern depend on the flexibility and extensibility of alternate code paths expressed as objects.

    8. Re:Hello World (Newer Version) by MillionthMonkey · · Score: 1

      I would have used octal somewhere. Octal can make obfuscated code really mysterious because the only hint is the prepended zero. Unfortunately one of the obfuscation mechanisms here relies on sign flipping; changing the base from 8 to 10 won't screw with the result (I think). A switch statement on a loop variable with octal-valued case statements would be nice, especially with case fall-throughs and loop exits or manipulations of the variable, which should be quietly declared as a byte. That way you can loop from 0 to an int above +127 and so while everyone is looking at case 0200 you break out of the loop from within a negatively-valued case. It can be cleverly disguised as a "sanity check" that innocently throws an exception.

      Although this is a more standard kind of obfuscation. It's more like a puzzle. The Hello World is funny because it's a straightforward overapplication of GoF patterns on a program that obviously doesn't need them, and it has no further obfuscation than that. It illustrates its point efficiently just by being unreadable. But it was easy to write because it doesn't take a lot of brain power to apply patterns to code. I didn't even really follow the control flow all the way through until after I had posted it.

    9. Re:Hello World (Newer Version) by ookabooka · · Score: 1

      Ah yeah, I omitted a few keywords like "for". My goal was to make it as confusing as possible by using bizarre keywords like strictfp, transient, syncrhonnized, instanceof, etc. Keywords that aren't used that much. Also I wanted it to not look like java, so anything that isn't typically used much in java code went in. Notice the assert and ? operator. I used ? instead of if-else for a reason. Also gotta love the "break again" statement, didn't know you could break to label. Do-while loop with the while at the end, etc. Not to mention that the class always throws itself as an exception. . for some reason I find that freaking hilarious. Maybe someday I'll rewrite it to truly include them all. I can confidently say that in its current form it servers its purpose.

      --
      If you are about to mod me down, keep in mind that this post was most likely sarcastic.
    10. 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.
    11. Re:Hello World (Newer Version) by Nyago · · Score: 1

      I love you.

      --
      Reality is fluffy!
    12. Re:Hello World (Newer Version) by MtHuurne · · Score: 1

      Actually, you cannot break to a label, you can only break from a labeled block. From the Java Language Specification: "this statement, which is called the break target, then immediately completes normally". This had me confused for quite a while when trying to figure out the behaviour of your program.

    13. Re:Hello World (Newer Version) by ookabooka · · Score: 1

      Pretty much everything in there is designed to make it impossible to figure out what it's doing. Also it does nothing useful.

      --
      If you are about to mod me down, keep in mind that this post was most likely sarcastic.
    14. Re:Hello World (Newer Version) by jlowery · · Score: 1

      Um, no 'final' keyword?

      BTW, anybody using 'auto' in c/cpp?

      --
      If you post it, they will read.
    15. Re:Hello World (Newer Version) by duerra · · Score: 1

      Hey, I've been looking for this! However, when I click the link, the post is now gone! Can you re-post in a more permanent location? Or maybe just email it to me? Thanks in advance!!

  96. Graham Nelson by Vidar+Leathershod · · Score: 1

    This is not surprising to me. If you play Graham Nelson's game "Curses", you can see that the man has a crazy ability to keep lots of things happening without making it look like a mess. His brain, and what he does with it, is amazing.

    --
    The brains of a chicken, coupled with the claws of two eagles, may well hatch the eggs of our destruction.
  97. Postgres, of all things. by Anonymous Coward · · Score: 0

    Sometime around 2000 I was asked to make a change to the way Postgres did something. At first I thought it would be difficult, given the size of the code and the amount of time I could realistically spend on it. It turned out that I could basically make the change blind -- the affected area of the program was nicely segregated from the rest.

    This isn't really a "pretty code" scenario. It's actually a "pretty design" scenario. The difference being that the program was very easy to change once the affected area code was understood (which didn't take long either), rather than just having easily understood code. I've seen code that was so easy to understand that it read like english, but was so self-involved that, with only 150 lines, I didn't know how the program worked before spending a few hours on it.

  98. Sure thing by Anonymous Coward · · Score: 0

    10 PRINT "HELLO"
    20 GOTO 10

    It's pretty basic.

  99. no pretty code by DuctTape · · Score: 1
    This is posted so late in the game, it'll never get read. So it goes.

    My experience has been that I've never seen pretty code outside an academic environment, where (surprise, surprise) you're sometimes graded on making your code (a) readable and (b) follow some sort of coding standard.

    In the real life, which includes innumerable projects and as many customers, I've never seen pretty code. I've noticed that if there has a choice between prettifying the code and putting in more functionality or unit tests or making the interface more consistent, the team has not gone for the first choice.

    I even had a project manager that answered me, when I wanted to spend time to make the code "better" and more manageable, told me to prove with numbers that it would give a positive ROI to refactor (we didn't have that word back then) the code. Otherwise, it was on to the next segment. Essentially it would have taken me longer to prove that I needed to refactor the code than it would have taken me to refactor it.

    Of course, the next reply to this post would be, then why didn't you just refactor the code, then? Because (a) I still would have had to come up with the justification, not the code; and (b) I wanted to keep my job.

    Aside: this is also the same project manager that told me to customize the process for the segment, then when it was late and didn't work correctly, because we were given a small amount of time to do it, he said we failed because we didn't follow the process.

    Go figure.

    DT

    --
    Is this thing on? Hello?
  100. DTN reference implementation rocks! by Anonymous Coward · · Score: 0

    Check out the Delay Tolerant Networking reference implementation at DTNRG -- maybe not consistently formatted through and through, but overall design is solid. Full Disclosure: I am not one of the primary authors, but I have contributed a few items.

  101. Entropy by Anonymous Coward · · Score: 0

    Having read some of Gregory Chaitin's stuff and having a background in electrical engineering Com stuff, I would imagine that the smallest and most efficient algorithm for any particular task would unfortunately be one that exhibits no patterns or regularity. Otherwise, further reductions could be made. Just as in data compression, the smallest representation is irreducibly complex for its size. In other words, the cleanliness of the code might often come at the expense of computational efficiency in order to abstract the process in a way that is clear to the reader/writer.

  102. filling up the symbol table by r00t · · Score: 2, Informative

    I can well imagine that a linker would choke on Boost.

    For those with a Linux/BSD/Solaris system, try running the "nm" command against a solidly Boost-infected project. You're likely to find function names that are THOUSANDS of characters long.

    Think about what that means for program start-up, at least if you call into a library. The runtime linker has to chew through all that gunk. I've run a profiler on this kind of code, and sure enough the start-up time was dominated by looking up all those giant symbols.

    1. Re:filling up the symbol table by Hawke · · Score: 1

      I ran into a linker bug because of symbols that were too long ... just by using STL. Boost isn't required.

    2. Re:filling up the symbol table by Anonymous Coward · · Score: 0

      GCC 4.x has a new "C++ visibility" feature which can hide all of those symbols after linking. Which means that dynamic linking won't have to resolve all of them. I'm pretty sure this optimization was made especially for templated C++ code.

      Now, I'm not sure if anybody is using this... Although I think Apple's xcode now does it by default.

    3. Re:filling up the symbol table by r00t · · Score: 1

      It helps. The problem doesn't go away.

  103. Anything posted to the IOCCC contest.. by Anonymous Coward · · Score: 0

    So ugly it's pretty.

  104. pretty colours by Anonymous Coward · · Score: 1, Interesting

    REM grab http://download.microsoft.com/download/win95upg/to ol_s/1.0/W95/EN-US/olddos.exe
    REM for the qbasic.exe

    SCREEN 13
    WINDOW (-2, -2)-(2, 2)

    FOR x = -2 TO 2 STEP 4 / 320
    FOR y = -2 TO 2 STEP 4 / 200
    u = 0
    v = 0
    FOR i = 0 TO 256
                    REM (u+vi)^2=u*u-v*v +2uvi
                    ut = u * u - v * v + x
                    vt = 2 * u * v + y
                    u = ut
                    v = vt
                    c = i
                    IF (u * u + v * v) > 4 THEN i = 256
    NEXT i
    PSET (x, y), c
    NEXT y
    NEXT x

  105. Shameful behavior from Posfix or qmail author by Anonymous Coward · · Score: 1, Interesting
    Before praising postfix's code again, you might want to read this.

    First, compare the way each author handled security disclosures.
    Found nothing shameful? Did you see this about Postfix? http://cr.yp.to/maildisasters/postfix.html

    Next, compare the number of false public statements made by each author.
    Found nothing? Did you see this about Postfix's author? http://cr.yp.to/qmail/venema.html

    And finally, compare the number of security flaws and their severity in Postfix compared to qmail.

    Ultimately, do you support or condone the behavior documented at http://cr.yp.to/maildisasters/postfix.html

    -- begin quote http://cr.yp.to/maildisasters/postfix.html --

    IBM released Postfix with massive hype in mid-December 1998. ``IBM software to shield email from hackers,''
    blared the Reuters headline. ``This will make IBM's and everyone's Internet activities more secure,'' IBM's network security research manager said in a prepared statement.

    A few days later I glanced at the Postfix security documentation. ``No Postfix program is set-uid,'' the Postfix author wrote. ``Introducing the concept was the biggest mistake made in UNIX history. Set-uid (and its weaker cousin, set-gid)
    causes more trouble than it is worth.''

    This set off alarm bells in my head. ``Does postfix really use a world-writable directory
    for people to drop off mail?'' I wrote in a 19981217 email message to another security expert.
    ``Is there anything that stops a user from making a hard link to another user's message, preventing postfix from delivering the message?''

    In fact, when Postfix saw an extra hard link, not only would it fail to deliver the message, but it would actively remove the hard link, Any local attacker could trivially exploit this to anonymously destroy other users' incoming or outgoing messages. There was no way for the system administrator to find the culprit, and no way to recover the messages.

    The Postfix author's reaction to my first public comments was outright denial.
    ``Bernstein is wrong on all points,'' he said in a public statement in response to a summary of the problems. ``Bogus. ... Bogus. ... Bogus. ... Bogus.'' He continued by giving an example of how an incompetent attacker might fail to destroy a file.
    Several people pointed out his mistake, but he continued to deny the problem. ``In my opinion, no-one has brought forward a vulnerability worth mentioning,'' he said in a bugtraq message titled ``Claimed Postfix Vulnerabilities.''

    I sent a detailed description of the vulnerability to bugtraq.
    The Postfix author finally admitted that the attack would destroy mail. However, he didn't post a security alert on the Postfix web pages. Instead he added a brief note to the middle of the ``Postfix Errata'' page:

    A local user can hard link a maildrop queue file to another
    directory within the same file system, causing the mail to not be
    delivered. Workaround: chmod 1733 /var/spool/postfix/maildrop, and
    edit /etc/postfix/postfix-script, replacing 1777 by 1733.

    When I saw this, I posted a note to comp.security.unix, explaining that this ``workaround'' simply didn't work. Any user could still anonymously destroy messages.

    The Postfix author followed up, using the subject line of ``DAN BERNSTEIN'S CLAIM'' without admitting that my claims were correct, summarizing the problems as ``local users [can] play games with hard links'' without mentioning that these games

    1. Re:Shameful behavior from Posfix or qmail author by poopdeville · · Score: 0, Troll

      I've been thinking about this topic a lot recently. I do a lot of work with ancient COBOL code that by all rights should now be in the public domain. Sometimes I find that code from one project will take care of issues in another, but the threat of a lawsuit for using code this way is just too high. So I'm in a bit of a pickle -- if company A ever found out that Belatrix Lestrange kills Ron Weasley for Company B, I'd have to argue that my recollection and reconstruction of that code does not constitute a derivative work, or that the code in question was part of the public domain anyway. A sticky wicket indeed.

      --
      After all, I am strangely colored.
    2. Re:Shameful behavior from Posfix or qmail author by mackyrae · · Score: 1

      This place is turning into Hogwarts left, right, and center!

      --
      look! it's a bird, it's a plane, it's....a girl? yes, a girl browsing Slashdot on Linux
    3. Re:Shameful behavior from Posfix or qmail author by Bandman · · Score: 1

      Lets see if I can channel DJB and come up with an appropriate response

      Anyone who runs postfix on a multiuser machine machine is doing it wrong.

      Was I close? If you don't like the results, claim the conditions under which they exist to be incorrect. Right?

  106. Pretty code can be found here by Okian+Warrior · · Score: 5, Insightful

    Phoenix Technologies used to make both BIOS and printer software. The printer software department split off and became a different company, and then I lost track of them...

    They made printer software that went into virtually every printer not made by HP at the time. Canon, Ricoh, Lexmark, or whoever would come out with new hardware and license the software from Phoenix. Yep, some of my code is in every Lexmark printer right now.

    They had a couple hundred thousand lines of code that did PCL, GL, and Postscript for the consumer market, and it was the most readable and well developed code I have seen. Comments were explanatory, variables were well named, and execution paths were well defined and easy to follow.

    They really had their act together for testing as well, with an elaborate and comprehensive regression suite that checked *every* aspect of all of the [printer] languages, and a team of QA people who would go over the results nightly. I'm not making this up - you would come in to work in the morning and there would be maybe 5 E-mails from QA outlining bugs which were either in your code or assigned to you for reasonable reasons.

    We did the software for the first Lexmark printer. The first internal release gathered 900 bug reports from QA. When we went to market there were 7 remaining, all of which were deemed inconsequential.

    When you are in the commercial market making fixed-program computers (dishwashers, printers, cell phones, VCRs) you don't have security updates and new versions, and a recall is usually out of the question. It's much cheaper to do all of your QA up front and ship a quality product.

    In my opinion we've grown sloppy in the programming business. I've been a contractor for the past 30 years and I haven't seen anyone else who comes close to true quality procedures. Even FAA safety certified stuff is usually hokey and obscure. Thank god we've still got human pilots.

    Having seen the procedures firsthand I have an appreciation of how easy and valuable it all is. No one else seems to understand that, and so everyone keeps running around putting out fires and slipping deadlines.

  107. Re:BOOST::Python, but you haven't seen the source? by WilliamSChips · · Score: 1

    There's a difference between a problem being difficult(anything NP-complete) and the language making a problem difficult.

    --
    Please, for the good of Humanity, vote Obama.
  108. Interfaces by Paxton · · Score: 1

    The interfaces are important to me. How well are they designed? Is the implementation clean yet expressive enough to expose all the necessary functionality?

    Underneath, you can connect to the OS-dependent -- and often hideous -- code. What you provide as an API is what's important: the interface. Compare, for example, Be's API and the Windows API or X.

    Of course, maintainability for what's underneath that interface is another issue altogether. I've had managers say, "Don't reinvent the wheel!" To which I want to reply, "Well, if you'd managed this properly before I got here, the wheels wouldn't be fucking square and I wouldn't have to reinvent them..."

  109. 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.
    1. Re:Bourne Shell by ls671 · · Score: 1

      Fine with me ! I suggested the JVMs as candidates but I use sh scripts for quite a lot of stuff and I find it quite nice and extremly powerful. I never looked at the sources although...

      --
      Everything I write is lies, read between the lines.
    2. Re:Bourne Shell by sinserve · · Score: 1

      you should see the source for CLISP; the light-weight and super-fast Common Lisp implementation, now part of GNU.

  110. STL by Nazlfrag · · Score: 1

    SGIs Standard Template Library is always memorable to me as being written in a concise, pragmatic and elegant way. It's the sort of code that is self-explanatory, requiring very little comments. Sorry it's not a larger project, but it left quite an impression on me when I first went through it all those years ago.

    1. Re:STL by anomalous+cohort · · Score: 1

      IMHO, STL is the best thing that has ever happened to C++. It really fills in some important gaps in C++, making it almost as easy to code in as Ruby, Python, Java, or C#. I have blogged on this previously.

  111. Lay-TeX by Anonymous Coward · · Score: 0

    Inside every beautiful person, there's an ugly person trying to get out.

  112. Why Old Code isn't pretty by Cassini2 · · Score: 2, Interesting

    Many pieces of old code aren't pretty for a fairly defined set of reasons:

    1. a) Debugging Ensure you actually have an appropriate way of debugging the code. The systems I work with are embedded and run 7x24. People will say: it failed last week on Wednesday at 3:00 A.M., we got it working, but can you fix the problem? The problem may not actually be your code, it could be another piece of equipment. In any case, you need to figure this out from the logs. In my experience, many "pretty" programs are too small to justify extensive logging. After logging is included, the programs become less "pretty" but much more maintainable.

    1. b) Refactoring after Debug Sometimes the results of the debug will show a major design error in the program. You now need to implement a major architectural change that really was not originally intended. You have good modular code when it can withstand these major design changes in a relatively smooth manner.

    2. Failure to handle common areas of problems well These include:

    2. a) Strings Does your program have the ability to smoothly handle unicode/UTF/HTML/locale specific strings? Every different language you port your application too, and every different program you talk with, will all have differing definitions of what is a string. My favorite test case is CNC (Computer Numerically Controlled) machinery. Some CNC machines expect embedded nulls inside the strings. The embedded null requirement affects a surprisingly large number of string libraries.

    2. b) MessageBox() Invariably in a big program it will be unacceptable to allow it to hang on a modal dialog box like MessageBox(). How are you going to handle it? What if a library call executes a modal dialog box?

    2. c) Handling Exceptions For a simple prototype program, handling exceptions is not a big deal. In a production application, all the exceptions must be handled appropriately and the program must be able to continue when exceptions occur. The error handling code often exceeds the size of the original program.

    2. d) Third Party Libraries / Operating Systems (Windows) The amount of code devoted to covering up mistakes in other code is amazing. Unfortunately, unless coding on an open platform, one must accept the costs of the additional code. When starting a new project, I recommend thoroughly stress testing any new libraries that will be used. Thus one can find the killer bugs that significantly affect design decisions.

    I would appreciate any feedback/additions to the items on this list.

    1. Re:Why Old Code isn't pretty by Bill,+Shooter+of+Bul · · Score: 2, Interesting

      Thats a good list, but I would add a third.
      3) Failure to define the problem space/ failure to refactor
            If you are using the agile programming approach in a haphazard way, or even if you are using a waterfall in a rapidly changing, unpredictable area of problems. You design your code to do what it needs to do in the most efficient way possible to do what needs to be done now, without worrying about what might happen in six months.

      Sometimes six months later the basic assumptions you made turn upside down and you have to make it work NOW. so you write complicated ugly code to make it work, and plan on refactoring it later. Then later never happens, because it doesn't need to be changed because it just works.

      --
      Well.. maybe. Or Maybe not. But Definitely not sort of.
    2. Re:Why Old Code isn't pretty by axl55aa · · Score: 1

      because it doesn't need to be changed because it just works

      This sentence alone shows why there is ugly code everywhere. Because many people think "hey it works, time to go home" the nice code is never written. The following extra 30% development time to make it really good structured, readable and commented just do not happen. Which leads to a vicious circle: 1) The beautify does not happen 2) The time is not recorded 3) The time is not expected to be necessary or payed for ...

      It would require another ground breaking revolutionary boom in programming, like "beautiful coding" or sth.

      Which will not boom, since we are all lazy a...

  113. Admirable ground up non-trivial FOSS C++ examplar by owlorc · · Score: 1

    The code at http://www.trading-shim.org/ is 'admirable code, both high-level architecture and in-the-trenches implementation.'

    For the last couple of years I have worked closely with the lead architect (and implementer) on this FOSS project; full GPLv3 C++ sources; TeX documentation sources and architectural notes (in ongoing buildout and revision), mailing lists, bug tracker, project domain, and availablity of the code author for clarification and feedback all make for an admirable solution set in a non-trivial problem space.

    That author, Bill Pippin, is a PhD in computer science (his earlier disseration, and the project's PDF are at: http://www.trading-shim.org/pdfs/), and his strong views on 'the singletree', as a method to drive a clean implementation. As explained at p 67 of the current documentation PDF, 'the singletree' represents a single root object, which permits avoiding the mess which the more common multiple static variables brings with it. As he notes:

    Applying the singletree pattern eliminates the global, class, and local static variables that infest most programs, and allows the designer to restrict access to global state.

    This has permitted fast development of very clean (and maintainable and extendible) C++ code in the complex problem domain of 'a command-line and dbms controlled interface to a socket-based API' upstream, which in turn probides access to comprehensive feeds and archives for tick and history data, and computer assisted financial market trading through the premiere electronic brokerage in its class.

    The code is not for the faint of heart, nor for who are not yet fluent in C++, but its elegant software engineering techniques are used here and in his prior disseration work to control program complexity: in particular by demonstrating a non-trivial instance of the single-tree pattern, whereby all singleton types are parameterized and then stratified by their binding pattern. (from the README)

    -- Russ Herold

  114. Comments lie. Code never lies. by rs79 · · Score: 2, Insightful

    "And don't forget that postfix is well-commented,"

    In all fairness, nobody has ever cashed in on Bernstein's security guarentee. There have been some oopsies with postfix.

    I think Bernstein's code is as nice as it gets. Course, Dan is polite to me too; so maybe I live in an alternative universe.

    --
    Need Mercedes parts ?
    1. Re:Comments lie. Code never lies. by schon · · Score: 1

      In all fairness Hmm... you seem to have an odd definition of fair.

      nobody has ever cashed in on Bernstein's security guarentee Only because DJB won't honor it. People have found bugs in his code, but he refuses to acknowlege them.

      Dan is polite to me too; so maybe I live in an alternative universe. That would certainly explain your usage of the word "fair".
    2. Re:Comments lie. Code never lies. by hey+hey+hey · · Score: 1
      I think Bernstein's code is as nice as it gets.



      Different strokes I suppose, I thought it was hideous. From memory (it has been awhile):

      • Hard coded file and folder names (it must be in exactly one location, too bad if you have a need for two outgoing SMTP servers running on the same box with different configurations)
      • Strange homegrown replacement for the standard C library
      • Memory deallocation done by exiting the program
      • Odd preprocessor "template" functions
      • A seeming hatred of descriptive variable or function names

      I don't have fond memories of the experience.

    3. Re:Comments lie. Code never lies. by cburley · · Score: 4, Informative

      I'll comment (inline) as someone who has come to appreciate certain of qmail's strengths even while tolerating (to varying degrees) its weaknesses:

      I thought it was hideous. From memory (it has been awhile):
      • Hard coded file and folder names (it must be in exactly one location, too bad if you have a need for two outgoing SMTP servers running on the same box with different configurations)
      That's annoying, but basically a security feature — you can be reasonably assured that a given qmail executable, especially qmail-queue (which is the only setuid-root program in qmail), is hard-coded to operate on only certain directories (aka folders) and files. And it's not "too bad" if you need to run a second SMTP server; just configure, build, and install as many distinct qmails as you need, with the configuration files (such as conf-qmail, normally /var/qmail) set as you want them. But I think it could be more flexible without sacrificing security assurances.

      • Strange homegrown replacement for the standard C library
      I gather djb's perception of the situation (at the time he wrote qmail and related software) was such that he'd substitute "Secure" for "Strange" above, but I don't personally know of exploitable bugs in contemporary C libraries, so I can't vouch for that. However, exploitable bugs in C code that uses standard C libraries are well-known, which is another reason I believe he grew his own C library.

      • Memory deallocation done by exiting the program
      Definite win for security and speed, if you don't have memory-leak problems as a result (and I don't think any qmail component does, modulo known issues with requiring per-process VM limits on Internet-facing components such as qmail-smtpd). As soon as your program starts down the path of calling free(), or, hey, even malloc(), if it can reasonably avoid them, it gets much more complicated and bug-prone, something you don't want in a system as crucial to have working correctly with no exploitable bugs as an email server.

      • Odd preprocessor "template" functions
      Haven't studied this enough to quite "get" what he was trying to accomplish vs. other approaches that could have been used, but they are doggone annoying to deal with at times.

      • A seeming hatred of descriptive variable or function names
      Agreed.

      I don't have fond memories of the experience.

      qmail code is pretty ugly when looked at closely enough, and can seem unnecessarily "different" from a more-distant perspective.

      However, pull back far enough and look at it, and you might be able to appreciate that it is, in its own way, a work of art: a reliable, secure, powerful email system — just as pretty much any sufficiently large and beautiful work of art can look pretty flawed when scrutinized closely, especially without an awareness of the "big picture".

      So if I wanted to play around with an email server and make it do all sorts of slick stuff, I wouldn't pick qmail.

      But if I wanted to improve a mail server in some fashion while still being reasonably assured the resulting (modified) system wouldn't have remotely exploitable bugs in it, based on what I know right now, I wouldn't pick anything but qmail.

      --
      Practice random senselessness and act kind of beautiful.
    4. 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.
    5. Re:Comments lie. Code never lies. by rs79 · · Score: 2, Insightful

      It's not clear to me an actual case has been made that warrents the $500.

      Moreso, the "bugs" describes above can be "features" to somebody else. I appreciate the brevity of Dan's code; C++ LongVariableNames make me throw up a little in my mouth.

      What's wrong with replacing the Standard C Library? Now you know what you're dealing with. Exactly.

      If your C program exits and doesn't deallocate memoru your O/S is broken.

      Given the number of sites that run djbdns and qmail and the number of CERT advisories against them (zero) I really can't fault it too much.

      The BIND code has lots of descriptive stuff in it. And lots of CERT advisories.

      You might find when you've written a very large amount of C code that it has to make sense to you; in the context of the code itself the names do mean something, just not to the casual observer.

      --
      Need Mercedes parts ?
    6. Re:Comments lie. Code never lies. by fimbulvetr · · Score: 2, Interesting

      Guninski's code works for any default qmail installation figuring the right arch and memory. Depending on your org, most currently shipping machines are capable of fostering said environment. An AMD64 with 8GB+ of ram is not uncommon. I have 4 of them and work for a small company. My previous company had several dozen (Sun 4100s).

      These exploits can be performed by any user who owns such hardware, and can read. They are not theoretical. Many bugs have existed in linux kernels that only manifest themselves under extreme circumstances, and I don't see Linus or anyone else of respectable programmer status that attempts such dismissals with a handwave. Maybe it's because pride doesn't get in their way?

    7. Re:Comments lie. Code never lies. by fimbulvetr · · Score: 1

      It's not clear to me an actual case has been made that warrents the $500.

      Moreso, the "bugs" describes above can be "features" to somebody else.


      Was it the privilege escalation, root privlege escalation or remote crashing that you consider features?

      http://www.guninski.com/where_do_you_want_billg_to _go_today_4.html

    8. Re:Comments lie. Code never lies. by cburley · · Score: 1

      These exploits can be performed by any user who owns such hardware, and can read.

      Not if qmail-popup, qmail-pop3d, and qmail-smtpd are run with VM limits set low enough (say, 1GB or less), and the OS enforces those limits, which is how qmail is normally installed (that is, installed as directed by various sources other than just the qmail-1.03 sources themselves).

      But the installation instructions that qmail-1.03 itself provides don't really inform the sysadmin of that necessity and, as I suggest on my web page about the problem, no developer should rely on the OS and sysadmin to enforce VM limits in order to prevent coding bugs being turned into actual exploits.

      (Hmm, at this point I think it's safe to say that I've spent more time publicly commenting on the as-yet-unfixed Guninski qmail bugs than it would have taken me to fix them and publish the patches! I'm not sure what conclusions to draw from that, if any....)

      Does anyone know of a similarly-capable, widely-deployed MTA with as good a security track record as qmail? Or, for that matter, of any actual qmail exploits in the wild, or in the lab?

      --
      Practice random senselessness and act kind of beautiful.
    9. Re:Comments lie. Code never lies. by Kjella · · Score: 1
      Comments lie. Code never lies.

      Lie by not telling the truth, no. Lie by deception, most certainly. Let me give you a trivial example:

      int a = 0;
      increase( a );
      // do something with a
       
      void increase( int a )
      {
          a++;
      }
      Of course, anyone remotely literate in C++ wlll spot that we're actually increasing the local copy because we pass by value instead of reference but the code "lies". Or you can have completely misleading function names, that's bad too. Or what's supposed to be const functions missing the keyword and actually modifying data (often because the programmer doesn't know how to use the mutable keyword), or any other number of circumstances. Good code does what it appears to do. Bad code can be absolutely horrible, often you get a "wtf are you TRYING to do!?!", in which case comments, even incorrect, may be useful.
      --
      Live today, because you never know what tomorrow brings
    10. Re:Comments lie. Code never lies. by ultranova · · Score: 2, Interesting

      As soon as your program starts down the path of calling free(), or, hey, even malloc(), if it can reasonably avoid them, it gets much more complicated and bug-prone, something you don't want in a system as crucial to have working correctly with no exploitable bugs as an email server.

      You know, you could just code the thing in Java and eliminate this issue outright, as well as all possibility of buffer overruns... C is the worst possible language for Internet-facing servers.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    11. Re:Comments lie. Code never lies. by cburley · · Score: 1

      You know, you could just code the thing in Java and eliminate this issue outright, as well as all possibility of buffer overruns... C is the worst possible language for Internet-facing servers.

      I made a similar point (about C) in my writeup on the Guninski bugs (and DJB's response).

      However, I'm not sure Java, or C++, Perl, Python, Ruby, Lisp, Scheme, Haskell, etc., are the right response to the problem, because they (the interpreters, or the code the compilers generate) make generous use of malloc() and free(), the resulting executables thereby being much more difficult to predict and thus validate in terms of security, and probably more resource-intensive than DJB's hand-coded C, therefore easier to DOS, which is still a problem for qmail components such as qmail-smtpd.

      Writing secure, reliable, efficient code is not just about selecting a language in which it's hard to code bugs — it's about selecting an environment in which there are likely to exist bugs (including taking substantially more resources to do something than the coder reasonably expected).

      I don't know how well various programming environments (such as Java) meet those requirements today, never mind how well they did, if they existed as sufficiently-widely-ported environments, back in the late 1990s when DJB started offering qmail.

      (Lots of qmail enthusiasts use qpsmtpd, a Perl-encoded replacement for qmail-smtpd, to get spam-fighting and other features. I'm under the impression they are comfortable doing that because the component still fits within qmail's security-obsessed architecture, thus severely limiting the negative effects of any exploit, and they've made a conscious decision to accept the substantial increase, often unpredictable, in resource utilization for each incoming SMTP connection. I gather Perl handles all the memory-allocation issues for them, making code modification much easier, and avoiding the kinds of bugs that Guninski found in qmail entirely, unless they're in the Perl interpreter itself. I wonder who out there uses mail-server components written in other languages, and how well they do with that?)

      --
      Practice random senselessness and act kind of beautiful.
    12. Re:Comments lie. Code never lies. by ZephyrXero · · Score: 1

      Hard-coded paths....

      "It's not a flaw, it's a feature!"

      Honestly, using hard-coded paths for "security" reasons is about as valid as the argument for security through obscurity. There's no excuse for ever using hard coded paths in a modern application these days. All it really accomplishes is making your software harder to administrate.

      --
      "A truly wise man realizes he knows nothing."
    13. Re:Comments lie. Code never lies. by cburley · · Score: 1

      There's no excuse for ever using hard coded paths in a modern application these days.

      How do you define "a modern application"? Or do you mean "an application compiled into a modern executable-file format"?

      In my experience, it's a lot harder to exploit (hack into) read-only portions of executables, which can include constant strings (like "/var/qmail") as well as code.

      Any mutable object, whether data or especially code (such as thunks), offers an opportunity for exploitation that might not otherwise be present. E.g. mutable data and code can't typically reside in read-only VM that's backed up by a DVD or CD-R instead of a large writable store (like a hard drive).

      Now, maybe modern executable-file formats (ELF, or what-not) no longer usefully make these distinctions — in which case the OSes on which they're built have perhaps sacrificed a historically useful additional barrier against intrusion, especially of the undetected or undetectable variety. But I doubt all modern OSes have eliminated that capability, and qmail was designed to run on, and leverage certain security features of, a variety of Unix-like OSes.

      All it really accomplishes is making your software harder to administrate.

      Yup. In my experience, qmail definitely makes for harder "interesting" configurations than it might have otherwise — though not as hard as it might have been, had DJB not provided for files like conf-qmail (while at the same time somewhat obscuring the actual path it sets within the *.h and *.c files generated from it, definitely an example of security by obscurity), which make generation of multiple qmail configurations a SMOS (Small Matter Of Scripting).

      Whether that's worth the time saved by learning, at 2am on a weekend, that your system has been rooted via an exploited mailserver (such as insert-your-favorite-MTA-other-than-qmail), and spending hours, days, or even weeks trying to recover from that, is worth considering.

      --
      Practice random senselessness and act kind of beautiful.
    14. Re:Comments lie. Code never lies. by ZephyrXero · · Score: 1

      I honestly don't see how you can argue that read-only and hard-coded paths are analogous. Whether your code says "/usr/lib/something" vs. "././something" or "$library_path/something" doesn't determine this. Plus proper permissions seem to be what you're really talking about, which can be set per file, not just by directory ;) ...by modern application, I mean something that's not low-level, like a library or compiler, and written within the last few years

      --
      "A truly wise man realizes he knows nothing."
    15. Re:Comments lie. Code never lies. by cburley · · Score: 1

      I honestly don't see how you can argue that read-only and hard-coded paths are analogous. Whether your code says "/usr/lib/something" vs. "././something" or "$library_path/something" doesn't determine this. Plus proper permissions seem to be what you're really talking about, which can be set per file, not just by directory ;) ...by modern application, I mean something that's not low-level, like a library or compiler, and written within the last few years

      A read-only path that isn't absolute (such as "./queue/" or "$QUEUE/") isn't much of a read-only path once an executable has been convinced to execute malicious code, since that code could easily do a chdir() or setenv() to a different directory, whether that executable is the qmail component in question (say, qmail-queue, the only setuid-root program in qmail) or another component (such as qmail-inject, /usr/lib/sendmail, or qmail-smtpd) that invokes it. (E.g. qmail-smtpd is untrusted within qmail's security-obsessed architecture, and could be exploited by the Guninski bug, but since it can't convince qmail-queue to inject mail into a different directory via chdir() or setenv() before calling it, the exploitability is severely constrained.)

      So you're right that just having the path encoding be read-only isn't enough; the effective path (after applying transformations such as "./" -> "/foo/bar/", "~" -> "/home/luser", and "$QUEUE" -> "/var/qmail") must be hard-coded — which is another way of saying it must be absolute, as well as constant, for maximum protection against an exploit (but that doesn't necessarily assure that pointers to it, and the like, from within the executable are, themselves, read-only!).

      As someone else pointed out in this thread, chroot() can still change that effective path, but that normally would just further limit the damage that could be caused by a misdirected (via exploited calling program) or exploited qmail-queue — at that point, the change definitely occurs only at the top level of the path (than by, say, an encoded path of "/var/qmail$QMAILID/", which opens a hole if "$QMAILID" -> "/../..[...]"), is more tightly controlled by the OS (chroot jails are presumably more carefully audited for security flaws than the other substitutions described above), etc.

      Proper permissions are not sufficient protection; as you can imagine, file and dir protections are often incorrectly set, improperly changed, or maliciously changed, by sysadmins or others. And permissions apply to passive objects (files), not active ones like executables, which is (partly) why qmail also exploits multiple user IDs (UIDs) as well as group ID (GIDs) in Unix to achieve protection between components.

      For example, qmail's log output is not just logged to directories and files with the appropriate permissions; they also are owned by a distinct user, qmaill, which is just for logging, and the logging daemons run under that UID, accepting input from whatever other daemon is doing the work. So if that other daemon, say, qmail-smtpd, gets exploited somehow, the fact that it's running as user qmaild, not qmaill, means that whatever log output was generated before, during, or (if you're lucky) after the exploit succeeded will still get logged, and cannot be deleted, unless the OS itself allowed one (non-root) user to delete another user's files.

      Note that I'm hardly "up to speed" on all the different ways Unix apps (like sendmail) have been exploited over the past 20 years, so I'm doing some guesswork here as to what DJB and others learned from such exploits. But I've had plenty of experience with exploits (as well as bugs of varying degrees of nastiness) on various other OSes over the decades, and, as a compiler expert of sorts, I really don't "see" source code so much as I see the machine code that might get generated from it (at an abstract level, anyway; been awhile since I ac

      --
      Practice random senselessness and act kind of beautiful.
    16. Re:Comments lie. Code never lies. by Bandman · · Score: 1

      Not if qmail-popup, qmail-pop3d, and qmail-smtpd are run with VM limits set low enough (say, 1GB or less), and the OS enforces those limits,

      My software isn't remotely exploitable either, so long as it's only running on 127.0.0.1. Doesn't mean the hole doesn't exist.

    17. Re:Comments lie. Code never lies. by cburley · · Score: 1

      Not if qmail-popup, qmail-pop3d, and qmail-smtpd are run with VM limits set low enough (say, 1GB or less), and the OS enforces those limits, My software isn't remotely exploitable either, so long as it's only running on 127.0.0.1. Doesn't mean the hole doesn't exist.

      So, does your software run, under that restriction, as designed (and expected) on many thousands (or more) servers around the world?

      qmail-popup, qmail-pop3d, and qmail-smtpd do. In practice, most installations limit their per-process VM usage to substantially less than 1GB. (My qmail-pop3d server runs with a per-process VM limit of 2000000, or 2M, bytes.)

      Despite such widespread usage, I'm not aware of any installation that includes fixes for all the qmail bugs Guninski found. (They might be fixed in-house at one or more installations; but, aside from my own patch for one of them, no fixes seem to have ever been published. Just not worth the trouble, apparently.)

      Even with the Guninski and related bugs fixed, such VM limits would still be a good idea, and probably widely recommended.

      But, yes, the holes do exist. Still, with suitable VM limits enforced by the OS (which do not in any way interfere with how the services operate), there appear to be no ways to actually exploit them.

      That's a credit to qmail's (DJB's) archicture, not the quality of its code.

      --
      Practice random senselessness and act kind of beautiful.
    18. Re:Comments lie. Code never lies. by demi · · Score: 1

      Proper permissions are not sufficient protection; as you can imagine, file and dir protections are often incorrectly set, improperly changed, or maliciously changed, by sysadmins or others. And permissions apply to passive objects (files), not active ones like executables, which is (partly) why qmail also exploits multiple user IDs (UIDs) as well as group ID (GIDs) in Unix to achieve protection between components.

      Yes. There's a whole discipline of structure and code that must be applied when reading a run-time configuration in a privileged program: for the dual purpose of ensuring that the configuration is "proper", that is, could never have been changed by an attacker, as well as to make sure that the privileges are not being used to read something that isn't supposed to be read. In its most basic rendition the file and directory permissions from the root down to the file need to be examined and compared to a (hardcoded!) standard to make sure they are correct. And even that's not right, because there's no way in most systems to ensure there isn't a race between the various checks and the reading of the file; and there's no way to make it portable, because filesystem permissions and semantics vary from system to system and filesystem type to filesystem type (consider, for example, what AFS does with Unix permissions).

      So you have all this code and structure (all inapposite to the task being addressed by the program--that is, unnecessary) which is unlikely to ever be well-tested, and can't even be correct. For what? To turn a compile-time parameter into a run-time parameter? Sometimes that's the right call, but not always.

      --
      demi
    19. Re:Comments lie. Code never lies. by cburley · · Score: 1

      So you have all this code and structure (all inapposite to the task being addressed by the program--that is, unnecessary) which is unlikely to ever be well-tested, and can't even be correct. For what? To turn a compile-time parameter into a run-time parameter? Sometimes that's the right call, but not always.

      Yup. The complete ins and outs of Unix (and "Unixy") FS semantics are not currently within my area of expertise, whereas security is well within my area of concern.

      So, all things considered, I find certain "surprising" design decisions exemplified by qmail to be rather comforting after all. I'd want to come much more up to speed on the pertinent issues (including the risks) before I started mucking around with those decisions (mainly, making things more flexible, such as turning compile-time into run-time parameters, as has been done by some patches to qmail, less or more "worrisome" from a security and reliability POV).

      I'm far more confident when it comes to fixing (or prettying up) qmail code, because that's well within my area of expertise. Not that I haven't made misteaks!

      --
      Practice random senselessness and act kind of beautiful.
  115. A bit of unsolicited advice... by SanityInAnarchy · · Score: 1

    I know you don't want to hear this. Really, I understand. But...

    Just about everything is going to be a "fucking mess". And yes, every now and then, you'll find something truly elegant -- and every now and then, you'll find something that you're amazed even compiles (if it does). But right there in the middle, it's always a fucking mess.

    And, someone ran a study -- I forget when, or what study, but what they found was, essentially, the ratio of bugs to lines of code was about constant, no matter what the programming language. That means languages like C++ and Java, which tend to be verbose, are likely to have more bugs than a language like Python, simply because Python will get it done in less code. (Incidentally, it also means libraries are better, especially if you don't have to write them yourself, because that one function call counts as one line of code for your project.)

    In short, the most reliable way to reduce the number of bugs in your code is not to write more elegant code (which, sometimes, just means more obscure bugs), but to write less code.

    It's not always an option, because frankly, I haven't found a language out there that doesn't suck in some way. It seems to pivot around Java -- either things are easier and more abstract than Java, but lack low-level features, the most annoying being real OS-level threading (Python pretends, but the GIL kills it) -- or they're harder and less abstract, like C and C++, but suddenly vulnerable to stupid things like memory leaks (uncommon in high-level languages) and segmentation faults (actually impossible, except by a serious bug in the language itself or a C library you link to).

    --
    Don't thank God, thank a doctor!
  116. Hydranode by Cyko_01 · · Score: 1

    Hydranode is extremely modular!...And that is why it died, there was no fixing to get the n00bs involved

  117. Good things by Tony · · Score: 0, Flamebait

    Why can't they just leave a good thing alone?

    Someone hit C with an ugly stick and called it a language. C++ was *never* a good thing.

    --
    Microsoft is to software what Budweiser is to beer.
    1. Re:Good things by Bryan+Ischo · · Score: 1

      You can limit yourself to a subset of C++ that is actually pretty nice. When I write C++ code I try to make it look as much like Java as I can; you can get pretty close and end up with something pretty readable and maintainable. But if you use every feature of the C++ language you will indeed end up with a mess.

      Heavy use of templates, especially with template meta-programming, goes in the opposite direction, of trying to use every nuance of the most complicated features in C++, which is why I find it to be intolerable.

    2. Re:Good things by JNighthawk · · Score: 1

      Implementation independant interfaces are a *fantastic* thing. C++ is a good thing, but some people take OO way too far.

      --
      Wheel in the sky keeps on turnin'.
    3. Re:Good things by TheRaven64 · · Score: 1

      I'd take Objective-C over C++ any day. A nice simple language, where every developer can understand the whole language (although not the library) after a couple of hours. You get all of the nice flexibility of dynamic dispatch (delegates and proxies become trivial), at the cost of some overhead when performing invocations (20 cycles for an Objective-C message send vs 10 for a C function call on x86 with the GNU libobjc). And if your code is in a really tight loop then you can cache the IMP and get C performance when calling the same method.

      --
      I am TheRaven on Soylent News
    4. Re:Good things by Bryan+Ischo · · Score: 1

      I read up on Objective-C once, thinking it sounded like it would be really good.  The thing I can't understand is, why they deviated so much from the "standard" C syntax.  I can't remember all the details, it's been years since I read a tutorial on Objective-C with an eye towards starting to use it for my projects, but I remember being very turned off by the fact that the language, for no apparent reason, completely changes the way method invocations are written.

      Here I looked it up on Wikipedia, here's an example of what I mean:

      A function in both C and Objective-C follows this general form:

      int do_something(int i)
      {
         return square_root(i);
      }

      with int do_something(int) as the prototype.

      When this is implemented as a method, this becomes:

      - (int) do_something: (int) i
      {
         return [self square_root: i];
      }

      What the heck?  Why throw C syntax out the window for methods?

      To be honest, this was enough to make me pass on Objective-C.  If I had a pressing need to use Obective-C over C++, I would take the time to become good enough with Objective-C's wonky syntax to make this a non-issue.  But it was enough of a barrier that I gave up on Objective-C and stuck with C++.

    5. Re:Good things by TheRaven64 · · Score: 1
      Objective-C doesn't throw C syntax out of the window, since it is a pure superset of C. Anything that is valid in C is valid in Objective-C. The reason 'method invocations' are different from C is twofold:
      • C doesn't have methods, it has function. In Objective-C, you call functions, but you pass messages to objects. There's a crucial semantic difference, which the different syntax helps to highlight.
      • Objective-C inherits its procedural semantics from C and its OO semantics from Smalltalk. Because of this, it also inherits its procedural syntax from C and its OO syntax from Smalltalk.
      After a day or two, most people find the Objective-C syntax more readable, since you have a name associated with each parameter. Consider the following two examples:

      [array insertObject:foo atIndex:bar];
      CFArrayInsertValueAtIndex(array, bar, foo);
      In OS X, Carbon and Cocoa are toll-free bridged for some classes, meaning that you have C (Carbon) and Objective-C (Cocoa) interfaces to the same classes, with the class being an opaque data type in the C version. The above snippet does exactly the same thing, but in the first example it's obvious which of the arguments is the index and which is the value, without having any other context. In the second, it's not. Considering that Objective-C only adds around a dozen syntactic elements to C, it doesn't really take long to learn. A half-decent programmer who already knows C can pick up the language in an afternoon.

      The other reason for the difference is, as I mentioned, to highlight the different behaviour. The destination for a C function call is defined at compile time. In Objective-C, you can add methods to objects at runtime using categories. This is quite commonly used to extend objects in the standard library. You want some extra behaviour, and so you add some other methods which you can use. This works because Objective-C messages are sent using a dynamic dispatch mechanism.

      When an object is sent a message that it does not have an explicit handler (method) for, it is wrapped up in an invocation object. This encapsulates the receiving object, the selector (method name) and the arguments. This is then delivered to the forwardInvocation: method of the object (which, by default, just throws an exception). You can then use this to deliver the method to a delegate, for example. The Distributed Object mechanism uses this to allow communication with objects on remote systems, including dynamic discovery of what methods they support, at runtime.

      The difference is partly philosophy. C++ tries to build a better C (and, I believe, fails). Objective-C views C as being good at what it does, and provides some other tools for C programmers to use when C doesn't do what they want. If you want static dispatch, you've got C functions. If you want dynamic dispatch, you've got Objective-C messages.

      --
      I am TheRaven on Soylent News
    6. Re:Good things by EvlG · · Score: 1

      What happens when a function parameter is renamed?

      In your example:

      [array insertObject:foo atIndex:bar];

      If someone changed atIndex to insertionIndex, I don't know if I want to go and change all the references to the old name.

      Does ObjectiveC handle this?

      On the one hand I can see it being very annoying, but then I can also see how it would force you to update code that may be broken. For example if atIndex became afterIndex, a C-style argument passing scheme would allow a bug to be introduced.

    7. Re:Good things by TheRaven64 · · Score: 1

      If someone changed atIndex to insertionIndex, I don't know if I want to go and change all the references to the old name. The way you would probably handle this would be to do this:

      @implementation NSMutableArray (LegacyCompatibility)
      - (void) insertObject:(id)anObject atIndex:(int)anIndex
      {
      [self insertObject:anObject atInsertionIndex:anIndex];
      }
      @end
      This is a category on NSMutableArray, which responds to the old interface and calls the new one. It's loaded at runtime and adds the method to the class. Then, if you send the old message, it will bounce it to the new one automatically. Since it's a category, it will also apply to any subclasses of NSMutableArray (which is useful, since NSMutableArray is implemented as a class cluster).

      This is no different, however, from changing a C function from ArrayInsertObjectAtIndex() to ArrayInsertObjectAtInsertionIndex(). You'd need to change all of the calling code in both cases, and in C you'd probably do exactly the same thing; define a trampoline that bounces from the old interface to the new one.

      If you change a method name, you change the selector that identifies the method, in this case from @selector(insertObject:atIndex:) to @selector(insertObject:atInsertionIndex:). The parameter names are not separate from the name of the method, they are part of it. If you change the name of a method in any language, you are going to need to modify the calling code so that it corresponds to the new interface, or provide a compatibility layer.

      --
      I am TheRaven on Soylent News
  118. Pretty != Elegant, Functional, or easy to debug by caseih · · Score: 1

    Some of the most elegant and functional code I have ever seen was done in Python. Anything pythonic is rather elegant and beautiful. But whether it's pretty is in the eye of the beholder. I happen to think large parts of the GTK+ source code tree are very elegant, functional, and fairly easy to debug. But they are in C; they aren't pretty. Lots of cruft to make object-oriented construcs. But once you recognize the patterns, you'll see real elegance. The same for any language.

    It's kind of like how the world is full of hot women, but very few of those are beautiful.

  119. keeping code clean is like battling entropy by 1iar_parad0x · · Score: 1

    Keeping any sufficiently complex code base 'clean' is like battling entropy. Eventually any code base given enough changes becomes 'messy'.

    I've found the best code is planned code. Code is best, when it's created by following a methodology. It's best when the code has been written in requirements and design documents and merely typed into source code. Code is best when it's been written twice. Code is often at it's worst when it's adversely affected by scope creep, programmers stumbling over a new architecture, or poor management.

    Reading code is hard. Ever try to 'debug' a mathematical proof. Sure natural language is too ambiguous for most math.* That's why logic was invented (see the chapter on Leibnitz). Going from symbolism to natural language is hard, understanding context is even harder. Just ask anyone doing research in NLP.

    *I'm not a logician, but as a side note, I've always found Raymond Smullyan's books on formal logic to be the 'prettiest' math books around. He has a naturally recursive mind.

    --
    What do you mean my sig is repetitive? What do you mean my sig is repetitive? What do you mean....
  120. Gnumeric is nice by mpsheppa · · Score: 1

    I've briefly played with Gnumeric a while ago and actually added a couple of minor features to it. Despite being an OO application written in C (Yes, this is possible, but the language doesn't help you at all), it was the most easy code that I've ever worked with. It was extremely easy to understand and find your way around.

  121. Re:BOOST::Python, but you haven't seen the source? by niteice · · Score: 2, Informative

    However, the thread issues are with Python, not Boost. There's a more detailed description in the Python docs, but basically the Python interpreter isn't designed to run more than once in the same process.

    --
    ROMANES EUNT DOMUS
  122. You heard wrong. by Anonymous Coward · · Score: 0

    Drupal may be slightly less horrible than some other common PHP apps, but its still absolutely terrible.

  123. Best Example Ever Was On Slashdot... by Anthony+Boyd · · Score: 1

    ...but I lost it. There was an article from 2 to 4 years ago in which clean code was discussed. This one guy wrote in to brag not about his own code, but about the code of the first seasoned developer he worked with. The guy was using some old language, but it had "if" statements and the like. Anyway, the guy had named his variables beautifully so that any given line of code read like a normal English sentence (almost). I discounted his implication that code could be "prettified" just by variable naming, but then the guy posted an example -- maybe 20 lines -- that he had kept all those years. And it REALLY WAS beautiful. It was so clean that a year or so ago I searched Slashdot to try to relocate that sample code. Never did find it.

  124. Design patterns by betterunixthanunix · · Score: 1

    Read the Gang of 4 design patterns book...

    --
    Palm trees and 8
  125. 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
  126. Step away from the crack pipe. by Anonymous Coward · · Score: 0

    Linux is nowhere close to clean, good code. Some parts are pretty good, but overall its rather poor. Compare the code of any hardware driver for instance between linux and say, netbsd. The linux version will be 2-5 times larger, and contain all sorts of non hardware specific functionality that should be seperated out and shared between all the similar drivers instead of being re-implimented 10 times.

  127. 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
    1. Re:We just published a book called Beautiful Code. by LearnToSpell · · Score: 1

      Perfectly timed indeed. I was lying in bed this morning thinking about some early stuff I'd written that (of course) took on a life of its own and grew into a hoary mess. As I was composing an "ask /." in my head, I stumbled across this. Looks like a nice one to have while I'm in the woods for the next six weeks.

    2. Re:We just published a book called Beautiful Code. by PotatoMan · · Score: 1

      The book should have included the original FORTRAN IV source for Colossal Cave. This code is the closest thing I've seen to the proverbial "brandy and cigar" standard for readable source. This code is readily available on the Web, and should be studied by anyone who says, "But in language X you can't Y." FORTRAN provided essentially zero support for structured code or data abstraction. Yet you can quite easily read the data files and algorithms and easily understand it.

      Perhaps Andy would include this in a second edition? Or as an online extra? I could write a commentary... ;)

  128. Coding standards by zullnero · · Score: 1

    First, create a code standard. This takes a whole team, and not one developer who has personal preferences they cannot back up with reasonably sound advantages.

    Second, establish code reviews. If your code does not meet standard, you highlight the section, function, object, etc. and you schedule a refactoring task.

    If you're not doing either, then sure, you're going to produce "cruddy" code. I'd say if you're not doing those two things, either you have a really small team that is just magically on the same page, or you're basically working without a real structure.

    Code that someone, anyone, on the team is not going to like will occur under a lack of a proper team system. What is pretty to one developer is a kludge to another, I've found (over and over again). What is sleek and efficient to a developer with an embedded background, may be perceived as inflexible by someone with a web/server side or modular applications background. Also, just because a junior developer doesn't like some code, does not always mean he has headlights in his eyes, so to speak. If a developer wants to rewrite something because he doesn't understand it, sitting down and working out coding standards will prevent them from rewriting it some way that someone else won't like. It will help them get a better grasp of the code. But most importantly, if the code IS a kludge, then the team will have their attention brought to it.

  129. Not C++ by kjs3 · · Score: 1

    Symbolics Genera.

  130. Code Reading by sohp · · Score: 1

    Sure, there are many examples, however I will tell you that there's little or no universal agreement. For example, I know some folks that consider qmail to be a terrific program, at least in design and coding, but there are plenty of criticism of qmail.

    I suggest getting a copy of Code Reading: The Open Source Perspective by Diomidis Spinellis. He at least will introduce readers to a number of different criteria by which code can be judged.

  131. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  132. Sun Projects - Solaris in particular by Anonymous Coward · · Score: 0, Troll

    Not a C++ project, but Solaris code is beautiful. Sun writes very concise and clear code. I've done work with the Solaris, BSD (several "modern" flavours) and Linux kernels. BSDs are pretty nice, but Solaris is simply a joy to work with. Everything is where you'd expect it, and when you get there, you see nothing more and nothing less.

    Linux kernel code is like a pile of vomit with contributions made by a communist drinking game including someone every UN reconised country. Even worse, the Finn who started it couldn't hold his liquor.

    And my experience was dealing with the rather messy job of packet capture and assembly.

    -Former Linux Zealot.

    1. Re:Sun Projects - Solaris in particular by Anonymous Coward · · Score: 0

      Solaris OS/Net runs a tight ship. I worked at Sun for a number of years and there is some very well written code. I think there a lots of folks that can and want to write elegant code. Those dang schedules just keep getting in the way. Open Source projects don't have to deal with those pesky schedules, so if an open source project puts elegance as a top priority they should not have any constraints. How come some of the worst designed and written open source software is the most popular? Interesting how critical our industry is, and the we turn right around and use really bad stuff...

  133. Pretty code by Nirex · · Score: 1

    I must say that if you want to see how code should be written take a look at Micrium uC/OS-II. Its beautiful! To bad the owner is a prick.

  134. Maybe a perfect example of Academia vs Real World by Anonymous Coward · · Score: 0

    Another thing to consider is that for new/fresh programmers who just recently graduated college, many of them have spent the last 4 or more years studying the ideals of software (and database) design. In the "real world" things aren't always going to live up to the ideals taught in academia. For example the programming team may been required to sacrifice elegance to meet critical deadlines.

  135. Nice three things ya got there. by Tim · · Score: 1, Troll

    Ah, yes...the flamebait comment from the "expert" who doesn't understand how to use a powerful language feature. It never dies....

    "(1) It's impossible to debug. You can't read the code. The debugger can't unravel the templated variables and stuff in any meaningful way for you. You can't even step through code, that's doing a supposedly simple operation like memory allocation!"

    Well, rather than getting into a childish "can too!" debate with you, I'll posit that it must have been pretty damn hard to develop boost, if all of the things you mention were actually "impossible".

    Better explanation: you don't know how to debug template code. Sad for you, but not a strike against the language.

    "(2) Some compilers will choke on the code, or compile it wrong in subtle ways due to differing interpretations of some obscure section of the enormous C++ language spec."

    Oooh...scary! Guess what, mate: some FORTRAN compilers choke on legitmate F77 code for the same reasons. This is nothing but a FUD tactic, dressed up as informed criticism.

    Boost is well-tested against the major C++ compilers, and you can always find out the status of the various sub-libraries by going here.

    "(3) The error messages from the compiler are useless. You have to run them through a filter to even figure out what they mean."

    See #1, above.

    "(3) Bugs in the library are very difficult to fix. Template metaprograms are essentially programs written in a functional language, except one that has horrible syntax. This is not the stuff that normal C++ programs are made of."

    I think your second, third point says volumes about your problems: if you don't know how to use it, then it isn't "normal".

    Sometimes, you have to learn new things to be productive in a new programming style. I could spend a great deal of time proving to you that there are many thousands of expert C++ developers who know how to do all of the things that you claim to be "impossible", but it isn't worth my time. I'm just hoping that a few knowledgeable developers will see this, and remove the ridiculous "Insightful" moderation from your rant....

    --
    Let's try not to let fact interfere with our speculation here, OK?
    1. Re:Nice three things ya got there. by Bryan+Ischo · · Score: 2, Informative

      I consider myself to be an "expert C++ developer" and I agree with the GP's comments on Boost.  Your "my truths are self-evident except to the lazy" arguments do not convince me.

      I have not seen anything that template metaprogramming can do that can't be done using other "saner" (in my opinion) techniques.  Perhaps the template metaprogramming approach can at times produce *terser* solutions, but I don't think that they are any better than more verbose non-template-metaprogramming-based solutions.

      Terse solutions are in my opinion often *less valuable* than more verbose solutions, because the latter are generally more approachable.  Of course verbosity can be taken too far, and there's definitely a balance to be struck.

      Here is an example of template metaprogramming code straight from Wikipedia:

      template <int N>
      struct Factorial
      {
          enum { value = N * Factorial<N - 1>::value };
      };

      template <>
      struct Factorial<0>
      {
          enum { value = 1 };
      };

      // Factorial<4>::value == 24
      // Factorial<0>::value == 1
      void foo()
      {
          int x = Factorial<4>::value; // == 24
          int y = Factorial<0>::value; // == 1
      }

      (this code defines a template which forces the compiler to compute factorials instead of computing them at runtime)

      I don't see anything about this that is in any way more readable or maintainable than the non-template-metaprogramming solution also posted on Wikipedia:

      int factorial(int n)
      {
          if (n == 0)
             return 1;
          return n * factorial(n - 1);
      }

      void foo()
      {
          int x = factorial(4); // == (4 * 3 * 2 * 1) == 24
          int y = factorial(0); // == 0! == 1
      }

      (interestingly, this exact question was given to me recently on an interview programming test (write C++ code to compute factorials at compile time instead of runtime); it was the only question on the test that I couldn't answer; I said basically "I know the solution has something to do with templates and partial template specialization but I don't know the syntax of partial template specialization well enough to write this" - I'm still waiting to hear if I got the job, and hoping that not knowing partial template specialization very well won't be the deciding factor, but to be honest, if this is the kind of stuff they're doing, I don't really want to work there anyway)

      I find the recursive implementation much easier to read and understand.

      And this is a simple example.  Really hairy template stuff like this:

      BOOST_STATIC_ASSERT((
          boost::is_same<
               twice<add_pointer_f, int>::type
             , int**
          >::value
      ));

      (taken from some Boost template metaprogramming documentation)

      ... that stuff is completely unreadable and I would never want code like that in any project I worked on.

      Note that I have absolutely no problem with people using solutions like this in their code, I would never try to limit someone from solving a problem in a way that was best for them.  The thing that bugs me, is that Boost and its techniques look like they are going to become "standard" C++, which means that anyone who writes C++ code in the future is going to have to deal with this stuff.  I would like template metaprogramming much more if it wasn't something looming on the horizon that the C++ standard and common usage of C++ is eventually going to force upon me.

    2. Re:Nice three things ya got there. by Bryan+Ischo · · Score: 2, Insightful

      By the way, your response is ridiculous in many ways. I don't feel like I should have to point these obvious things out to you but I guess I do:

      1. The GP sounds like he understands template metaprogramming very well. Nothing about his post suggests that he either a) says that he is an "expert" (as you are suggesting he does), or b) *isn't* enough of an expert to have formed a valid opinion on the subject.

      2. Clearly the GP used the word "impossible" to mean "very difficult". You're being pedantic by suggesting that he literally meant it is impossible to debug.

      3. It's only because of lots and lots of dedicated effort by Boost developers that Boost's very-complex template metaprogramming techniques work on a wide variety of popular compilers. I would be willing to bet quite a bit that they had to jump through many hoops to find least-common-denominator solutions that worked on all compilers. I believe that this makes the GP's point perfectly. This kind of programming relies too much on subtle complexities of the language definition and while the Boost authors were willing to put lots of work into making these things work on various C++ compilers, I wouldn't want to do that and wouldn't choose to use a library that may force me to do the same (which might happen if I decide to extend Boost's implementation).

      4. Once again by "useless" the GP clearly meant "requiring much more work to decipher than other more conventional error messages". Once again you dismiss his point by interpreting it completely literally.

      My rule of thumb as a developer: whatever you do, make sure that the next guy who wants to work with it doesn't have to get a Ph.D. in the subject in order to continue your work. In other words, keep your implementation simple and as mainstream as possible, so that it can easily be picked up by anyone. Template metaprogramming fails this utterly.

    3. Re:Nice three things ya got there. by JNighthawk · · Score: 1

      Hm. As far as maintainability/readability/debugability, the non-templated version wins (though, your use of recursion there is so unnecessary). As far as speed goes, the templated version wins (compile-time is usually preferred to run-time). Even with a good amount of comments on the templated version, the first would be preferred. It doesn't matter if it's fast if it can't be maintained/debugged.

      But that static assert is a perfect example of unintelligible templating. That code means exactly nothing to me.

      --
      Wheel in the sky keeps on turnin'.
    4. Re:Nice three things ya got there. by Tim · · Score: 1

      "The GP sounds like he understands template metaprogramming very well."

      Really? He was complaining about being unable to read the error messages.

      "Nothing about his post suggests that he either a) says that he is an "expert" (as you are suggesting he does), or b) *isn't* enough of an expert to have formed a valid opinion on the subject."

      You can't have it both ways: either the guy is informed enough to have an opinion on the matter, or he isn't. He made a post claiming that template metaprogramming is not "normal", while simultaneously making it absolutely clear that he didn't understand enough of what he was talking about to be even remotely qualified to advance a criticism.

      Like it or not, there are quite a few C++ programmers out there who know how to work with complex templates. You may not know how, the GP poster may not know how, but that doesn't make the boost library "bad".

      "It's only because of lots and lots of dedicated effort by Boost developers that Boost's very-complex template metaprogramming techniques work on a wide variety of popular compilers."

      Straw-man. Any good library represents "lots and lots of dedicated effort" by developers, and almost by definition, wouldn't be good without that effort. Yet I doubt you're willing to abandon every domain-specific library, simply because you don't understand the code. Whether you realize it or not, your whole argument rests on that premise.

      Keep in mind that the point of the Boost library is that it makes relatively complicated (yet powerful) template-based tools available to average developers. Which brings us to:

      "This kind of programming relies too much on subtle complexities of the language definition...I wouldn't want to do that and wouldn't choose to use a library that may force me to do the same (which might happen if I decide to extend Boost's implementation)."

      With every new language or paradigm, you'll find a group of stubborn people who refuse to adopt new techniques because it's "too much" of something for their tastes. For years, C programmers refused to adopt C++, because the code was "too abstracted" from the hardware. The same was said of C, by the assembly gurus. Now, you're giving iteration N+1 ("I'll never use it because the code syntax is too complicated"). It's just another form of Luddism.

      "My rule of thumb as a developer: whatever you do, make sure that the next guy who wants to work with it doesn't have to get a Ph.D. in the subject in order to continue your work. In other words, keep your implementation simple and as mainstream as possible, so that it can easily be picked up by anyone."

      Well then, I hope you're writing your code in BASIC, because there isn't another language in existence that is "simple" and "mainstream" enough to be "easily picked up by anyone".

      And before you accuse me of being too literal, let me just pre-empt you: I get your point. You think C++ template code is too complicated. Fair enough. But you should realize that you're drawing a relatively arbitrary line in the sand, and your conception of "complicated" is likely to be eclipsed by whatever the next generation of programmers thinks is easy. And I can assure you that there are plenty of smart young programmers right now who are proficient and productive with tools like template metaprogramming and the boost library.

      I'm not an idealist; there are plenty of things to complain about when it comes to C++, and any experienced C++ developer can rattle them off for an educated debate. The point is, dismissive rants by developers who simply think that the error messages of today's compilers are "too hard" are neither "insightful" nor "interesting" -- they're just whiny.

      --
      Let's try not to let fact interfere with our speculation here, OK?
    5. Re:Nice three things ya got there. by Anonymous Coward · · Score: 0

      It is funny how you dismiss metaprogramming because most of the time people don't need it and because you find it hard. Now, if we were to dismiss everything that someone finds useless and complex, we wouldn't have much left in the world then.

      Seriously though, the factorial example you gave is a typical metaprogramming example, but not very representative of real world code. Summarizing metaprogramming just around that example is kind of narrow minded. The whole idea behind metaprogramming is to use the compiler to compute parts of the program at runtime. Using the computer to automate tedious and repetitive tasks. This is a very powerful concept! Yes, it's harder than typical the "C with classes" code. Yes, it is to be used carefully. Yes, it can be very useful when needed.

      Coming back to the factorial example you gave. Again it is just an example. I'm heavily using Boost and I have yet to use such a factorial function.

      "I find the recursive implementation much easier to read and understand."

      If you look carefully, you'll see both implementations are recursive.
      Also, as other people have already pointed out. Using recursivity for the runtime version is quite suboptimal when a simple loop does the trick.

      On a more global note, I like the way you guys are picking up on Boost because of metaprogramming, when actually pure metaprogramming is like only one of the ~50 Boost libraries! I also like the way you post code segments from Boost implementation to indicate that using Boost is complex. Implementing and using a library are two different things (to push an analog example to the extreme, it would be like posting code from the Linux kernel to explain that one should not use a Linux distro to develop an application).

      As for the so called experts...

      We have been heavily using Boost for three years now to develop cross-platform (i.e. Windows and Linux, 32 and 64 bits) projects. Sincerely, the quality of the projects has increased a lot: there are significantly less bugs, the code is significantly smaller (2 times smaller at least) and more maintainable.

      In my experience, Boost is harder to learn and use at the beginning, but quite worth it. Part of it is often because the concepts it tries to solve are indeed more complex than one would think at first.

    6. Re:Nice three things ya got there. by fatphil · · Score: 1

      Don't use recursion, and let good old fashioned C work things out at compile time:

      """
      static inline int fact2(int n)
      {
            int r=1;
            while(n>1)
                {
                      r*=n; n--;
                }
            return r;
      }

      int foo()
      {
            return fact2(4); // == (4 * 3 * 2 * 1) == 24
      }
      """

      Which becomes

      """ .globl foo .type foo, @function
      foo:
                      movl $24, %eax
                      ret
      """

      Personally, I hate languages within languages, or should I say languages around languages.

      So doing stuff with excessive C pre-processor is evil _unless_ there's a clear automatic code generation phase for separate modules which are written only in the pre-processor macros. The fact that they become C is then pretty much irrelevant, it's as if you're just using 2 different languages (or 3 if you also have soms asm components too, say), nothing wrong in mixed-language development. It's just the merging of C stuff with pre-processor stuff that turns ugly.

      Ditto templates and C++, but of course, the problem with them is you then physically cannot avoid merging the template meta-programming with the plain C++ programming. Yeugh.

      Anyway, to contribute to the original topic - for _beautiful_ code, utterly transparent C, and a joy to work with, I'd have to point to the Texas Instruments Multitasking Executive (TI-ME), a real-time micro-kernel, which came bundled with their DSP development kits back in the 90s. I can say that now, as I no longer work for their main competitor in the DSP market!

      --
      Also FatPhil on SoylentNews, id 863
    7. Re:Nice three things ya got there. by Peter+La+Casse · · Score: 1

      With every new language or paradigm, you'll find a group of stubborn people who refuse to adopt new techniques because it's "too much" of something for their tastes. For years, C programmers refused to adopt C++, because the code was "too abstracted" from the hardware. The same was said of C, by the assembly gurus. Now, you're giving iteration N+1 ("I'll never use it because the code syntax is too complicated"). It's just another form of Luddism.

      The statement "I'll never use it because the code syntax is too complicated" is not necessarily Luddism, and is not analogous to your examples (which are valid). Complex syntax hinders communication between developers and increases defects. If everything else is equal (and it usually is), simpler syntax is better.

      I use C++ regularly, and if I didn't restrict myself to a subset of its features I would go nuts. Maybe that means I have a small brain, but if so that makes me part of the majority.

      And before you accuse me of being too literal, let me just pre-empt you: I get your point. You think C++ template code is too complicated. Fair enough. But you should realize that you're drawing a relatively arbitrary line in the sand, and your conception of "complicated" is likely to be eclipsed by whatever the next generation of programmers thinks is easy.

      Fortunately, the next generation of programmers has many languages available that are not as complicated as C++. Progress in programming language design is indicated by syntactical simplicity, not complexity. C++ is the most syntactically complex language I use regularly, which is why I avoid it whenever I can.

    8. Re:Nice three things ya got there. by Tim · · Score: 1

      "Complex syntax hinders communication between developers and increases defects. If everything else is equal (and it usually is), simpler syntax is better."

      Granted, but the question remains: complex to whom?

      I write template code (and use boost) on a regular basis, and I am familiar with the syntax. Once I got over the initial learning curve, I didn't find C++ template metaprogramming syntax to be particularly bizarre or difficult. I'm not trying to brag; I'm just pointing out that there is nothing inherently wrong with template code. It's understandable (and incredibly productive) if you take the time to learn to use the tool.

      Again, this entire debate boils down to the question of what you find familiar and comfortable. If it were impossible for a programmer of normal intelligence to learn how to use boost, you might have a point; that's clearly not the case. In my experience, most complaints about C++ tend to be made by programmers who believe that their understanding of ALGOL-derived syntaxes should carry them comfortably through their programming careers. These types of people tend to get cranky and dismissive when they can't pick up a language in an afternoon.

      "Fortunately, the next generation of programmers has many languages available that are not as complicated as C++. Progress in programming language design is indicated by syntactical simplicity, not complexity."

      Demonstrably false. Progress in programming language (if it has been defined by a single metric at all), has been defined by increases in expressiveness, not simplicity. Cases in point: Java, Perl, Python and C are all significantly more syntactically complex (and expressive) than FORTRAN 77 and PASCAL.

      --
      Let's try not to let fact interfere with our speculation here, OK?
    9. Re:Nice three things ya got there. by Tim · · Score: 1

      Well said, AC. I am perpetually annoyed by the number of people who bash on C++ simply because they don't want to take the time to learn a language that is more complicated than the ones they already know. There is more to the programming universe than Java and Perl!

      Some goon gets a +5 moderation for admitting that the doesn't know C++ well enough to understand the compile errors he obtains, but the posts calling him out on his ignorance are met with "Troll" moderation. Welcome to slashdot.

      --
      Let's try not to let fact interfere with our speculation here, OK?
    10. Re:Nice three things ya got there. by Anonymous Coward · · Score: 0

      I, too, write template code and use Boost for a living. Even after getting over the learning curve, and appreciating that there are some cool concepts involved, I cannot help feeling that there has to be a better way than the mess that current C++ is.

      I've spent days where over 90% of the work was creating solutions to problems that, in hindsight, were caused by the complexity of the language and Boost libraries, and only a small fraction of the fine end result could be characterized as productive towards actual project goals.

    11. Re:Nice three things ya got there. by andy55 · · Score: 1

      I've considered myself a C/C++ expert for a while now and I didn't realize that a static inline proc would always be collapsed by the compiler. I guess I've just always been pessamistic that a compiler would be that smart (we've all seen compiler do dumb things). How confident are you that most modern compilers (namely, gcc4, MSVS8) will be smart enough? I just gotta believe most compilers wimp-out on collapsing when they encounter a loop.

    12. Re:Nice three things ya got there. by fatphil · · Score: 1

      That used to be the logic: loop = complicated => don't inline.
      I think since 3.x days, gcc has realistically evaluated sizes of potentially-inlinable functions and won't barf arbitrarily at loops any more. However the example I gave wasn't so much an example of that, but more an example of constant folding. fact2(4) is nothing more than a deterministic sequence of operations on constants with known arithmetic properties (floating point values have run-time-dependent behaviour so are harder to safely deal with) which can be evaluated entirely at compile time. I have no idea what level of tech MS compilers have reached, I've not touched one for ever and a day.

      --
      Also FatPhil on SoylentNews, id 863
    13. Re:Nice three things ya got there. by Peter+La+Casse · · Score: 1

      Sorry for the late reply.

      Granted, but the question remains: complex to whom?

      Syntax complexity can be independently measured. Someone could memorize every syntactical element of the most complex language ever devised, and it would still be the most complex language ever devised. Ideally programmers will focus on design rather than syntax.

      Progress in programming language (if it has been defined by a single metric at all), has been defined by increases in expressiveness, not simplicity.

      The most expressive language in the world is not very useful if its syntax is confusing, complicated and error prone. Some examples of those things:

      Confusing: using the same or very similar syntax for very different operations, such as defining = to mean different things in different contexts.

      Complicated: having lots more than one way to do something; having a relatively large number of different kinds of syntactical elements; having verbose syntactical sugar.

      Error prone: see confusing; also, having different operations be so similar syntactically that adding or omitting a single character produces a valid operation (such as = and == in C, or the original FORTRAN loop syntax)

      Syntax simplicity is certainly not the only way to measure a language (you noted expressiveness; there are others also), but it is extremely important.

  136. MS's .Net by Bellum+Aeternus · · Score: 1

    I know this really isn't code, but APIs mean a lot to - and I hate to say it but M$'s .Net APIs are really well laid out and designed. It allows for the code developed using them to be a lot cleaner and easier to read. Also, if you stick with their naming conventions the code is easy to read as well.

    The Java API seems to have similar benefits, but I'm a lot less experienced with it, so I'm not a good source when it comes to Java.

    Yeah, yeah - I said something pro M$, mod me down.

    --
    - I voted for Nintendo and against Bush
  137. Of course! *My* code is the prettiest. by CoderDude · · Score: 1

    At least it is where I work. :-)

    Here's an example of a recent SQL Server 2005 stored procedure named pivot_table.

    CoderDude
    1. Re:Of course! *My* code is the prettiest. by Anonymous Coward · · Score: 0

      SQL programming is never pretty. What the f*** is pretty when you need to do shit like this?

            set @where_clause = ' 1=1';

    2. Re:Of course! *My* code is the prettiest. by CoderDude · · Score: 1

      That was done specifically to enhance the readability of the code.

      I check for the existence of a "where clause" sent in the arguments once at the top of the procedure and explicitly define one ( 1=1 ) if there wasn't one sent in.

      That way in the next 5 spots in the code where I need to use that variable to build an SQL statement to exec, I can write simply:

      ... + 'where ' + @where_clause + ...

      instead of having to have additional code in each of those 5 spots to check if I have a where_clause or not.

      Looking at it now I suppose I could have just pre-pended the 'where ' onto the clause itself or left it set to '' and it would have worked just as well.

      I blame the wine! :-)

      CoderDude

  138. SQLite by knukkle · · Score: 1

    SQLite has very good architecture, code (fully and relevantly commented), documentation and tests. Its bug tracking is also very good. Sure, it is not a very large code base with lots of developers but it is keeping clean in its evolution. Just compare it with Firebird (which has admittedly more features): Firebird code is such a mess, from top (architecture) to bottom (name of variables). I'm not advocating one software above the other, but just saying that comparing both is interesting and shows that it is possible to make good software robust and clean instead of poor and messy.

  139. LLVM by Powder · · Score: 2, Informative

    http://llvm.org/ is one of the better C++ projects I've seen. Quite large, but also clean and tidy.

  140. You are clearly not qualified to comment. by Anonymous Coward · · Score: 0

    Your code sucks, drupal is a mess. Being not quite as messy as phpbb doesn't make it "good". Mangling SQL with regexs? Really poorly written regexes at that! Drupal doesn't even have a seperation between display and database code, there's HTML pieces floating around in the database layer. That's the kind of thing that would get a junior code monkey fired here, its as far from good code as you can get.

  141. Here are a few things I give out by Animats · · Score: 1

    Here's some code of mine.

    • mutexlock.h - queuing and locking primitives in C++ for QNX. Little primitives that have to be right, and are hard to code correctly. These ran on our DARPA Grand Challenge vehicle.
    • algebra3.h - basic functions for 2D, 3D, and 4D matrices and vectors, all in C++ and all inline. The basic code is from Graphics Gems, but it's been rewritten to be 100% inline. Useful for game and graphics work. Used as part of Falling Bodies.
    • obvious.c - the original obvious password detector, from 1984. Use this to decide if a password is "strong enough". Rejects all English words, yet doesn't require access to a dictionary file. Note this is in K&R C; it predates ANSI C.
  142. Yes there is... by frank_adrian314159 · · Score: 1

    "Pretty bad" that is...

    --
    That is all.
  143. OpenBSD by Anonymous Coward · · Score: 1, Informative

    Most (if not all) OpenBSD code I have dealt with gives me a warm tingly feeling inside. It isn't C++, but they have their reasons.

  144. Pretty C++ An Oxymoron? by littlewink · · Score: 1
    All kinds of code popped into my mind until I read

    In particular I am interested in large user applications using modern C++ libraries...
  145. haskell by SolusSD · · Score: 1

    Haskell is very pretty. No junk characters like curly braces or semi colons. Also- being as it is a functional programming language, it is also very elegant.

  146. A chapter in "Beautiful Code" is on this topic... by kfogel · · Score: 2, Informative

    Laura Wingerd and Christopher Seiwald wrote an excellent chapter on this topic for O'Reilly's Beautiful Code book (just out). See Chapter 32, "Code in Motion". The code from their chapter is online here: http://www.perforce.com/beautifulcode/

    --
    http://www.red-bean.com/kfogel
  147. Re:BOOST::Python, but you haven't seen the source? by ignavus · · Score: 1

    Two interesting quotes:

    "BOOST makes decent programmers cry."

    - And as we all know: goatse.cx makes decent programmer's cry. Therefore, Boost *may* be like goatse.cx ...

    "BOOST is full of butt-ugly hacks. Check out the, uh [...] Eeeeeew!!!"

    - Yep, Boost is definitely like goatse.cx

    --
    I am anarch of all I survey.
  148. More comments then code... by FlyingGuy · · Score: 1

    When i was taking C courses at UC Berkeley the professor made a few rules:

    • 1. You will have more comments then code.
    • 2. If a function takes more then a page to write, split into two functions.

    As much as I thought this guy was a total asshole, he wrote damn good code.

    I am personally just sick to death of this notion that you should just get it. Well commented code means you have a comment for everything even things you think are obvious. If you write code that is of any consequence there will be someone coming along after you that has to either maintain it, modify it or re-write some portion of it. Additionally at some point if you are a good programmer you will have to come after someone else and maintain, modify or rewrite their code.

    Code style is another thing all together. Style Nazis have their place, an no its not sitting on the freeway tied up waiting for a semi to run them down. They exist to make sure code is clear and readable. I once worked on a project and there was a definite style Nazi working there. Her ONLY job was to enforce the style rules. She would check everything you wrote and would give you notes and your code would not be submitted for the nights build if you turned it in last minute or if your code didn't meet the style rules. Now this got me into the shit with my manager at least once, but I am a better programmer for it.

    Every #include, #define, everything had to have a comment stating WHY it was included and a general note as to what it was supporting. They even had boiler plate for stdio! I know that seems WAY over the top, but there was not a module of code that I couldn't understand the basics of what it was doing in about 5 minutes just by reading the comments.

    A lot of the code I see in CVS's and things like that is just pure garbage.

    Don't EVEN get me started on what some of these Java monkeys do. Oy!

    --
    Hey KID! Yeah you, get the fuck off my lawn!
    1. Re:More comments then code... by OrangeTide · · Score: 1

      So often I find developers modifying code at work and not updating comments to reflect those changes. I have very little trust in comments these days and tend to ignore them. Also there are good commments and bad comments.

      Bad: (you may think it is an exaggeration, but it's a real example)

              unsigned long hash(unsigned char *str) {
                      unsigned long hash = 5381;
                      int c;
                      while (c = *str++)
                              hash = ((hash 5) + hash) + c; /* hash * 33 + c */
                      return hash;
              }

      Good: /* hashing function for strings. string must be null terminated.
                * returns a hash of string str, result of empty string is 5381 */
              unsigned long hash(unsigned char *str) {
                      unsigned long hash = 5381; /* starting value for hash */
                      int c;
                      while (c = *str++) /* c is a temp value, loop until null terminator */
                              hash = ((hash 5) + hash) + c; /* hashing calculation used on every char */
                      return hash;
              }

      There is a reason professors are excessive with comments and style, it has more to do with making their lives easier. If TAs and the professors can't easily read through hundreds of programs to grade them, then either they won't bother really examining all of them (the normal) or they will have to work very very hard to figure out each student's "masterpiece."

      Outside of academics having comments is good, but excessive commenting of "obvious" things will result in a very negative reaction because programmers out in the real world are notoriously defensive when it comes to doing extra work. And writing lots of comments, and worse having to update and maintain those comments, is extra work. (just like going to meetings is extra work). If you strike up a happy medium, and if you integrate that work with comments with tools like javadoc or doxygen so that developers can directly benefit from the work on comments and people other than programmers can see those comments, you will find code quality will dramatically improve.

      The other issue with comments is that many people you will have to work with in the real world have less than ideal English abilities. spelling and grammar can be hard enough that some developers will feel uncomfortable except with the briefest and most simplistic of comments.

      80-90% of the time there is not a module of well written but uncommented C code I cannot understand by reading the source code for 15 minutes. and I suspect, but have no proof, that my level of understanding is far more detailed and complete than yours.

      --
      “Common sense is not so common.” — Voltaire
    2. Re:More comments then code... by Surt · · Score: 1

      Extent of commenting is a topic long debated by people with a huge amount of total experience.

      There are people who recommend commenting at this level: /* increment i */
      i++; //i is inremented here

      Fortunately, most experienced programmers agree that such comments make the code less clear, as they obstruct visibility, and potentially confound refactoring, which is a much better path to long term maintainability and clarity.

      So if you're not willing to comment at this level, then you're on a slippery slope: if some things don't need comments, what does?

      It becomes a matter of opinion, which of course leads to abuse in the other direction. Reaching a good, balanced point on comments is a strong sign of good experience in a software engineer.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    3. Re:More comments then code... by scotch · · Score: 1


      I'm confused - is the code you labeled good supposed to be an example of good commenting?  Those are some of the most worthless comments I've ever read.

      --
      XML causes global warming.
    4. Re:More comments then code... by OrangeTide · · Score: 1

      please give an example of a better way. to be honest my version of that code that I actually use looks more like this:
          unsigned strhash(const char *s) {
              unsigned hash=5381;
              while(*s) hash+=(unsigned char)*s+++hash*32;
              return hash;
          }

      with no comments. having a comment at the top of a function that describe its purpose, and keeping the function short (break it up into multiple functions if they get to be too long) seems to be all the commenting you really need. and things like javadoc and Doxygen really only work well with just those comments on the functions. the additional comments don't seem to add much.

      --
      “Common sense is not so common.” — Voltaire
    5. Re:More comments then code... by scotch · · Score: 1
      1. The function header comment was ok.
      2. Where does 5381 come from? Where does the algorithm come from? A comment on a hasher usually looks something like: "see Knuth ..."
      3. I doubt if this hasher is that great, but it may do well for the domain in which you use it; a comment is warranted.
      4. Non trivial code benefits from comments that describe the purpose, flow, intent, larger logic, preconditions, etc.
      5. Comments that echo the purpose of basic syntax elements are a good sign that you shouldn't quit your day job.

      --
      XML causes global warming.
    6. Re:More comments then code... by OrangeTide · · Score: 1

      2 & 3. it's DJB hasher. it's known to be good for strings. it's probably not nice to force people to google for 5381 to figure that out. you can find it described in DJB's cdb documentation, as well as many of his open source projects.

      4. I agree. I couldn't come up with anything interesting for my specific example though, perhaps you can do better?

      5. I agree. I certainly hate the repetition, but I did not do that in the comments I presented. I commented at a high level of what the syntax presented. .. do you have a specific example of what would be better?

      --
      “Common sense is not so common.” — Voltaire
  149. To answer the question... by blake182 · · Score: 1

    the short answer is "no."

  150. Website That i LOVE by nytrokiss · · Score: 1

    http://worsethanfailure.com/Default.aspx This site is very funny and all about bad code!

  151. Classic Beauty by chris_sawtell · · Score: 1

    using modern C++ libraries and techniques like exception handling
    eueueeee

    That's for weens. For examples from real coders, look at the Shuttle launch software and Don Knuth's TeX.
    They are both truly beautiful.

  152. No such thing as pretty code? by uvajed_ekil · · Score: 1

    So I see that everyone and their mother (right upstairs) has an example of ugly code, or why something is not written as well as it could be. Plenty of mentions here of why decent programmers hate this or that (mostly well-reasoned), but no examples of good code that everyone can agree on. I can't claim to be a "good" or even "decent" coder, but I will refrain from knocking everyone else's code if I am not good enough to contribute to it. Enough with "You want ugly, check out project xxx," what do you actually have to offer that IS easy to read, comprehend, and debug? I know the concept of "pretty" code should not be so subjective that we can not agree on anything, so where is the good stuff we can all learn from????

    --
    This is a hacked account, for which the owner can not be held responsible.
    1. Re:No such thing as pretty code? by mrjb · · Score: 1

      "Where is the good stuff we can all learn from?" -- It is Very Rare. There are some best practices we can all agree on (comment your code, don't use globals, use descriptive variable names, etc). The best we can do is to try to adhere to these best practices. The point is to make our code readable to others.

      But- if we are lone coders, there is not much point in making our private code readable to others. If we code in a team, there is a point, but there will always be team members that are less capable than others. There isn't always time to write code twice, so the suboptimal code will stick and infect the rest of the code base over time.

      IMNSHO I'm capable of producing fairly clean code- I still find it can use some cleaning up before being released to the public (comments, function descriptions etc). But structurally the design of the code is solid. Still, some code I wrote over a decade ago has gotten a bit hard to read by now.

      --
      Visit http://ringbreak.dnd.utwente.nl/~mrjb/growingbettersoftware to download your free copy of the book
  153. regression by Anonymous Coward · · Score: 0

    after 30 years in the software business in silicon valley... my observation is that with time to market getting shorter and shorter, work hours getting longer and longer, generally speaking developers do not have the time to become masters of engineering discipline. on the other hand... because there is so much information available, and code, todays young developers are able to perform quite well. there is a down side, new technology development teams (i.e not applications or web development) don't have chops to deliver the because of a lack of solid engineering fundmentals.

  154. Java is pretty, not C++ by Digeratist · · Score: 1

    10 goto 20 20 goto 10 http://worldwidewags.com/newdles/ Newdles is the prettiest code I've ever written, but I doubt anyone but me will see it before I die.

  155. Technical Debt by implicit · · Score: 1

    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.

    Has someone created such a law before?

    Ward Cunningham calls it technical debt. It's what you accrue when you don't mercilessly simplify the design of your application every time you check in.

    http://www.martinfowler.com/bliki/TechnicalDebt.ht ml

    1. Re:Technical Debt by JAFSlashdotter · · Score: 1
      Ah, according to Joshua Kerievsky, Cunningham calls it Design Debt. I probably should have gone to the source... Here's the earliest thoughts I could find from Cunningham on the subject (1992), I guess he called it neither of them:

      Another, more serious pitfall is the failure to consolidate. Although immature code may work fine and be completely acceptable to the customer, excess quantities will make a program unmasterable, leading to extreme specialization of programmers and finally an inflexible product. Shipping first time code is like going into debt. A little debt speeds development so long as it is paid back promptly with a rewrite. Objects make the cost of this transaction tolerable. The danger occurs when the debt is not repaid. Every minute spent on not-quite-right code counts as interest on that debt. Entire engineering organizations can be brought to a stand-still under the debt load of an unconsolidated implementation, object- oriented or otherwise.

      There is little doubt that Wyatt Software will continue to employ object technology. Thoroughly versed in the leading object-oriented languages, our only decision is how best to employ their advantages. The traditional waterfall development cycle has endeavored to avoid programming catastrophy by working out a program in detail before programming begins. We watch with some interest as the community attempts to apply these techniques to objects. However, using our debt analogy, we recognize this amounts to preserving the concept of payment up-front and in-full. The modularity offered by objects and the practice of consolidation make the alternative, incremental growth, both feasible and desirable (but not always comfortable) in the competitive financial software market.

      Apparently he's extended the metaphor over time, and used it to close a conference in 2001. Some wiki pages by others call Design Debt a type of Technical Debt. A small group of us where I work are trying to get the concept recognized -- we have a LOT of legacy code toting a US treasury sized debt around, but "it works".

      --
      We apologize for the preceding message. All those responsible have been sacked.
  156. Re:BOOST::Python, but you haven't seen the source? by zlogic · · Score: 1

    BOOST makes compilers run very very slow, and often breaks the optimizer anyway. This drives me nuts, a simple 200-line *.cpp file using boost::stateschart compiles for about 30 seconds, and syntax errors result in 400+ character lines with recursive template codes etc. In comparison, a 20-file (each file containing 100-400 lines of code) wxWidgets app linked with FIVE LIBRARIES compiles for about 1 minute 20 seconds and errors result in readable code.
    Oh, and boost::thread is also fucked up. If you want a thread to sleep for 1500 milliseconds, you have to
    1) get the current time with boost::xtime
    2) convert 1500 seconds into 1 second plus 500000000 nanoseconds (which takes about 10 lines of code and isn't included in boost libraries! WTF!) and add it to the time from 1)
    3) call boost::thread::sleep
    In comparison, in .NET and Java this is done using a one-liner like (I don't remember the exact syntax)
    Thread.sleep(1500)
  157. Clean Code by simontek2 · · Score: 1

    What about Clean code? You know the types that doesn't have errors, or memory leaks? Heck why does a printer driver take 300mb? I remember when things used to be small. Lots of things now are huge, that do not necessarily have to be big.

    --
    SimonTek
  158. KDE code by fishbowl · · Score: 1

    I've always thought the KDE code was beautiful. Not in terms of stuff like code formatting, but in terms of C++ design. Even if you hate KDE as a user, it might be worth browsing the source.

    --
    -fb Everything not expressly forbidden is now mandatory.
  159. Without a doubt by einhverfr · · Score: 1

    Often when I am trying to learn a new set of calls in C (such as Sys V IPC), I will write modified hello world progras to explore them. The code is small, simple, and easy to adapt to all sorts of things (like server/client connections over UNIX sockets).

    So... I am sure that some hello world programs do have security holes because they are inteded for testing purposes only. Of course, exploiting those are rather difficult...

    --

    LedgerSMB: Open source Accounting/ERP
    1. Re:Without a doubt by Mr+Teddy+Bear · · Score: 1

      Dude... if:

      #include
      void main() {
            printf ("Hello World!\n");
      }

      Has security flaws... then that isn't the fault of the developer. There's something seriously wrong with a complier that can't get that one right. (Or maybe the OS it runs on.)

    2. Re:Without a doubt by dctoastman · · Score: 1
    3. Re:Without a doubt by einhverfr · · Score: 1

      Dude--

      you are an even worse C programmer than I am.

      Asuming Slashdot ate your include specification (due to tags) you should still make main return an int return code.

      #include <stdio.h>
      int main () {
          printf("hello world");
          return 0;
      }

      The issue is not when you with that code, but could be an issue depending what you may be using it to explore.  As I say I use hello world as a template for tests of various concepts, and I am sure those test, not being as well debugged, may have security issues.

      --

      LedgerSMB: Open source Accounting/ERP
    4. Re:Without a doubt by baadger · · Score: 1

      ...and puts() would be a better choice than printf()

    5. Re:Without a doubt by Anonymous Coward · · Score: 0
      Dude--

      Please put the damn code between <ecode></ecode> tags, and leave the rest of your post proportionally-spaced. Otherwise, you look like somebody who doesn't know what he's doing. For example,

      <ecode>#include <stdio.h>
      int main () {
              printf("hello world");
              return 0;
      }</ecode>
      yields

      #include <stdio.h>
      int main () {
          printf("hello world");
          return 0;
      }
      .
    6. Re:Without a doubt by tehshen · · Score: 1

      /* What does 0 mean? What if my operating system returns 11 for success? */

      #include <stdio.h>
      #include <stdlib.h>

      int main()
      {
              puts("Hello, World!");
              return EXIT_SUCCESS;
      }

      --
      Guy asked me for a quarter for a cup of coffee. So I bit him.
    7. Re:Without a doubt by Ben+Hutchings · · Score: 1

      /* The C standard says both 0 and EXIT_SUCCESS are allowed as indication of success. It's up to the implementation to convert the return value if necessary. */

  160. Enlightened Programmers Will Say... by Anonymous Coward · · Score: 0

    All code is shitty code.

  161. Re:A chapter in "Beautiful Code" is on this topic. by Anonymous Coward · · Score: 0

    >The code from their chapter is online here:

    Oh boy, one of my pet peeves: The 80 column terminal combined with superfluous empty lines.

    And the brackets are misplaced, too. :)

  162. sqlite by lpontiac · · Score: 1

    The sqlite source code is clean, well documented, and you can pretty much understand the entire system by reading the one "internal structure" document followed by 10 - 15 files of source code in the right order end-to-end.

  163. Ogre3D, Botan by savuporo · · Score: 1

    These are the two well designed C++ libraries that i can always instantly remember.

    --
    http://validator.w3.org/check?uri=http%3A%2F%2Fwww.slashdot.org Errors found while checking this document as HTML5!
  164. 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...
    1. Re:The MacPaint code was donated... by gpuk · · Score: 1

      Any ideas on where these luminaries have disbanded to? Am I missing out on a great underground tech site that the script kiddies and Ruby evangelists have yet to destroy? I'd hate it if I was...

    2. Re:The MacPaint code was donated... by Stinking+Pig · · Score: 2, Informative

      What about me? I'm not important and I hardly ever post here any more, so... oh, wait.

      And to apologize for that lame joke, here's some research:
      The Computer History Museum has transcripts and interviews, but no source: http://search.computerhistory.org/search?q=macpain t&submit.x=0&submit.y=0&site=chm_collection&client =chm_collection&proxystylesheet=chm_collection&out put=xml_no_dtd
      Another interview with the original reference to putting MacPaint in there: http://www.pbs.org/cringely/nerdtv/transcripts/001 .html

      I agree that code written to the Tcl/Tk style guide is clean, though messy Tcl exists. Sort of like Perl, the language everyone loves to blame for their sophomore code.

      --
      "Nothing was broken, and it's been fixed." -- Jon Carroll
  165. Compiler problems by Per+Abrahamsen · · Score: 1

    1), 2) and the first 3) are really compiler problems, and not associated with the code as such. Kind of like when the FSF decided to target platforms with 32 bit flat address space, at a time where 16-bit segments were the norm. It made their code prettier and easier to read, but in the short run less useful. I have no problems with that.

    The second 3) is the real issue, template meta-programming tend to divide the user community into library users, and library writers. As losing as the users stay users, everything is fine, but in case of a bug in the library, users are suddenly writers.

    1. Re:Compiler problems by alexeiz · · Score: 1

      The second 3) is the real issue, template meta-programming tend to divide the user community into library users, and library writers. As losing as the users stay users, everything is fine, but in case of a bug in the library, users are suddenly writers.

      How is it different for any other library? Are you OK with a library only as long as it's bug free? So here's a surprise for you: every library has bugs. Boost is not the buggiest library I've ever used. I've probably seen more bugs in the VC++ standard library implementation than in Boost. Does it mean I shouldn't use STL based on your premise?

  166. Samba? by Sits · · Score: 1

    I remember hearing that Samba has some pretty elegant code. Apparently several projects like talloc have also fallen out of it. Later versions also have very extensive test suites...

  167. Cleanest Code Ever by dino213b · · Score: 1
    This is an example of the simplest and clearest code ever. How can you go wrong when your CPU only has 35 instructions, 224 bytes of ram, 128 bytes of eeprom, and 2048 bytes to store code in ? Talk about elegance!

    main: incf ts,f
    movf ts,w
    movwf tmp
    movlw D'59'
    subwf tmp,f
    decfsz tmp
    goto main
    1. Re:Cleanest Code Ever by mrjb · · Score: 1

      Sure, without doubt this is the cleanest code ever.
      But that doesn't automatically make it the most readable.

      For one thing, properly commenting your code will help people understand it; it is one of the best practices that I picked up when coding almost exclusively in assembler for three years. It has lasted across programming languages.

      Due to lack of documentation, the purpose of your snippet of code above is entirely unclear to me (other than it being obvious that the code is forever stuck doing something in an infinite loop) , and I'm not going to spend 10 minutes to try to read it, if 1 minute of your time documenting your code could have explained it perfectly.

      --
      Visit http://ringbreak.dnd.utwente.nl/~mrjb/growingbettersoftware to download your free copy of the book
  168. Speed... by Joce640k · · Score: 1

    "As far as speed goes, the templated version wins..."

    I'll bear that in mind every time I read about C++ compiles which take days/weeks to complete...

    PS: +1 for not incorporating boost into the standard. It's unnecessary and won't make a single person's life any easier (I mean, people are using Boost without it).

    --
    No sig today...
    1. Re:Speed... by JNighthawk · · Score: 1

      I work in games, so I figure that a good balance for me would be an hour of compile time to cut out 100 microseconds a frame. Of course, these compile time optimizations should only be enabled in release builds, but when you only have ~16 milliseconds a frame, a 100 microsecond speed increase is a lot. Template specialization at compile time wouldn't be a terrible speed hit if Visual Studio supported the export keyword, which lets you separate the declaration and definition of templated functions.

      As a side note, with Incredibuild, compile times aren't bad at all.

      --
      Wheel in the sky keeps on turnin'.
  169. Ever take any set theory? by TaleSpinner · · Score: 1


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

    The intersection of those sets is null. There is such a thing as pretty
    code. None of it is written in C++.

  170. quake 3 arena by walshy007 · · Score: 1

    while not in c++, it is a rather complex application, and very elegant imho. understanding it requires 3d background knowledge, but it is still very clean code.

  171. PovRay by ishmalius · · Score: 1

    I have always considered POVRay code to be very clean and elegant. One of the better examples on the Net.

  172. some companies have pretty code by sentientbrendan · · Score: 1

    The company I'm working for right now has a large very high quality code base, and rigorous code review standards internally. The code is almost all c++, but it is all very clean and readable, all unit tested, and what's more extremely well commented.

    This is an area where high standards in what you allow developers to check in is important. Most shops do everything very add hoc and don't give developers any strict guidelines...

    A lot of open source projects have a similar problem. Most of the open source projects I've worked on are totally uncommented and lack any kind of unit test or up to date architectural documentation. The linux kernel is a pretty good example of ugly code, largely because of lack of comments and documentation.

    In open source, or in private companies, someone has to ultimately lay down the law and say what practices, like documentation and unit tests that are required. I think people are a little too worried in open source about scaring off the community with this stuff, but it's much more important to maintain a high quality code base.

    Exceptions:
    Unfortunately, not everyone can use exceptions since integrating with older code that is not exception safe is a problem i.e. if a function throws an exception in exception unsafe code, it will likely leak resources. A lot of older c++ code doesn't use exceptions for whatever reason, and you pretty much can't switch over once you've gone down that path.

    RAII:
    scoped_ptr is most of what you need to know about RAII... everyone should use it where appropriate, and it's part of the standard library in TR1. You can swap out the destructor if you are holding some other resource than memory, and in that way it also helps with exception safety.

  173. Pretty code flows from a simple design... by Anonymous Coward · · Score: 0

    ... its really that simple. Every time I see code that I consider ugly (and I see a lot as a C++ contractor in Londons finance industry), its always because the person who wrote it left out something important in the design phase and it had to be hacked in later. Examples:

    - If you don't know who owns the objects in your program and how long they live, your code will be full of special conditions in odd places.
    - If you didn't realise the implications of having many threads running through your code, the locking will become an inconsistent mess.
    - If you can't reliably know the state of an object without querying some related objects, the failure to encapsulate properly will spread throughout your code.
    - If you don't enforce pre and postconditions at source, then they will be broken and fixes applied in multiple other places to work around this.

    IMHO, sexy code has the following characteristics:

    - Its readable. That is, well formatted (i.e. consistent), commented, uses meaningful abstractions and names.
    - Its reserved. That is, it hides as much as possible about itself and takes care of the management for you.
    - From the above, its replacable. The implementation can be improved without messing up others who use it.

    You get the above for free if you talk through your design with others, especially other developers who will use your code (in ways you may not agree with). Any code that isn't a rats nest of special cases and interdependencies is sexy - because it can be improved easily.

    Jon

  174. Plan 9 by gcapell · · Score: 1

    I was pretty impressed with all the Plan 9 source code I looked at.

  175. Good management is everything by Bubblehead · · Score: 1
    I once worked at a company in the late 90ies that had code of an exceptionally high quality (around 500k LoC in Java). It was pretty clear to me that this was because of good management. The VP of Technology had a very strong opinion about how to develop code:
    • Not a single line of code was written without source control and bug tracking in place
    • The architecture was defined before code was written
    • There were coding guidelines (style, etc.) that were ENFORCED
    • All code was reviewed
    • Incorrect documentation (including comments) were considered bugs of the hightest priority.
    • etc...
    You get the picture. Bottom line: at some point, I had to work on code that was three years old and that I had never worked on or seen before. It was an absolute pleasure to work on the code: Due to the style everything looked familiar, comments described WHAT the methods were doing, the architecture was clean, etc.

    Without good management that understood software development AND that was willing to impose some important rules, this would not have been necessary.

    --
    Under capitalism man exploits man. Under communism it's the other way around.
  176. Random PIDs by gtwilliams · · Score: 2, Informative

    Are there any operating systems out there that use random numbering of PIDs?
    Yes. AIX.
    --
    Garry Williams
  177. I'm pretty by Mike+McTernan · · Score: 1

    I consider most of the code I write to be pretty.

    Here's a link to some source: http://www.mcternan.co.uk/ArmStackUnwinding/wind.t ar.gz

    --
    -- Mike
  178. rewritten application by elmartinos · · Score: 1

    I have rewritten unp, which is a simple extraction utility, just to see how a clean implementation would differ from it. The result is a much shorter, and easy to comprehend application called e.

    The main difference between the two implementations is a clear separation of concerns. While unp looks like one large blob of code with no clear structure, e has all the rules in one place, and application logic in another place. In unp this lack of separation has already led to duplicated code.

  179. Re:BOOST::Python, but you haven't seen the source? by andreas_huber69 · · Score: 1

    Hi

    > This drives me nuts, a simple 200-line *.cpp file using boost::stateschart compiles
    > for about 30 seconds,

    What compiler are you using? I've observed *huge* differences (>300%) in compile time, depending on the make of the compiler and optimization settings. Also, I would be very interested in the 200 lines that cause such a long compile time. Optimizing the TMP part of statechart so that compile time is reduced has been on my TODO list for quite some time now. Reports of unbearable compile times would certainly increase the priority of that work item!

    > and syntax errors result in 400+ character lines with recursive template codes etc

    Have you had a look at http://www.boost.org/libs/statechart/doc/faq.html# CompilerError?

    Thanks & Regards,

    Andreas

  180. Spring by Zizi · · Score: 1

    If you want something from the Java world just look at Spring http://www.springframework.org/. Its design and code are both great.

  181. OpenLB: Open source lattice Boltzmann code by SimHacker · · Score: 1

    OpenLB is a beautiful piece of C+ code. Hard core C++ templates used for and how templates were really designed to be used. After looking at several other LB implementations, this was the nicest designed and by far and easiest to read to figure out what was going on.

    OpenLB: A library for lattice Boltzmann numerics

    Computational framework
    * C++ library for fluid flow simulations
    * Implementation of lattice Boltzmann dynamics
    * Modular, extensible code
    * Platform independent development

    High performance simulations
    * Complex, inhomogeneous dynamics
    * Irregular domain boundaries

    Free source code
    * Gnu General Public License (GPL)
    * Open contributions from CFD community thankfully accepted

    And more
    * Straightforward coupling to external tools for pre- and postprocessing
    * Teaching support (CFD basics and programming)

    The project was created and is supervised by Jonas Latt, former member of the University of Geneva and by Prof. Dr. Vincent Heuveline, Professor at the Supercompuing center of the University of Karlsruhe.

    What is the Lattice Boltzmann Method?

    The lattice Boltzmann method is a powerful technique for the computational modeling of a wide variety of complex fluid flow problems including single and multiphase flow in complex geometries. It is a discrete computational method based upon the Boltzmann equation. It considers a typical volume element of fluid to be composed of a collection of particles that are represented by a particle velocity distribution function for each fluid component at each grid point. The time is counted in discrete time steps and the fluid particles can collide with each other as they move, possibly under applied forces. The rules governing the collisions are designed such that the time-average motion of the particles is consistent with the Navier-Stokes equation.

    Really cool stuff!

    -Don

    --
    Take a look and feel free: http://www.PieMenu.com
  182. Syllable OS by Anonymous Coward · · Score: 0

    http://www.syllable.org/ ... a pleasure to work with.

  183. Re:BOOST::Python, but you haven't seen the source? by zlogic · · Score: 1

    I'm using g++ 4.1.2 (the default g++ in Ubuntu 7.04) with no optimization, as a debug build. I think the relatively small amount of RAM (512Mb) may be responsible since I use Eclipse as my main IDE and it usually takes 150-250 megs. OTOH the other project I mentioned also builds from Eclipse. I can mail you the source that results in insane compile times, my email is [my nickname on slashdot]@gmail.com
    I've looked at http://www.boost.org/libs/statechart/doc/faq.html# CompilerError and it confirms what I said - an error in code using the Boost library results in 6-8 long compiler errors and only one of them actually needs to be fixed.

  184. Can someone point me to an example of a standard? by gr8dude · · Score: 1

    I've been thinking about this problem, as my friends and I are planning to start several programming projects.

    Having only academic experience in programming (i.e. code written by a single person, and maintained by the same person; literally no team-work), we want to try to develop 'good' coding habits - which is why we are looking for a set of conventions that are successfully applied in the real world.

    The ones we've found on various sites are very long and detailed; for example, this one looks good, but I'm not sure it is a good one to start with, as focusing on the rules will probably draw attention away from actually making a program that works.

    Are there any 'light' standards that can be embraced by us at this stage?

  185. None! by forgoil · · Score: 1

    Because a fairly good developer can never really comprehend the idea of good design, and there are far more crappy developers out there than good ones, and great ones, not many at all. It takes discipline and talent to produce good design and without it you will be lost, no chance of recovery, sorry.

    That being said I've heard very good words about llvm (www.llvm.org) so go check that out if you are interested in possibly good code.

    Design is really the key here, changing development methodologies, programming languages, or whatever won't buy you good design. Too bad today's tools for design is HORRIBLE :(

  186. Just another Perl hacker by matt+me · · Score: 1

    Perl has some wonderful examples:
    [Both of these print "Just another Perl hacker" and exit]

    Yes they do actually run without error. Try it.

    Example 1.
    [Edit Slashdot thinks I am using too many junk characters so check the code out here http://en.wikipedia.org/wiki/JAPH
    it consists entirely of punctuation]

    And for those who think perl is cartoon characters swearing:

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

  187. Google Projects by An+Anonymous+Hero · · Score: 1
    Funny you should ask that, I was just reading this (Steve Yegge, 26 Jun 2007):

    I hope you're beginning to see, at least faintly, why I love working at Google. It's because the code base is clean. And anything that takes more than a week of effort requires a design document, with specific sections that have to be filled out, and with feedback from primary and secondary reviewers of your choice. The net result is that for any significant piece of code at Google, you can find almost a whole book about it internally, and a well-written one at that.

    I've never seen anything like it before, to be honest. I don't think you can get that kind of software-engineering discipline without doing it right from the start, and creating a culture that enforces and reinforces that discipline as the organization grows.

    With that in mind I'd take a look at http://code.google.com/projects.html...

  188. Re:BOOST::Python, but you haven't seen the source? by andreas_huber69 · · Score: 1

    > I think the relatively small amount of RAM (512Mb) may be responsible since I use Eclipse as my
    > main IDE and it usually takes 150-250 megs.

    In that case I'm not surprised, TMP code tends to use heaps of RAM for even moderately complicated problems.

    > I can mail you the source that results in insane compile times, my email is
    > [my nickname on slashdot]@gmail.com

    Ok, I'll contact you offline.

    > I've looked at http://www.boost.org/libs/statechart/doc/faq.html# CompilerError and it confirms
    > what I said - an error in code using the Boost library results in 6-8 long compiler errors and
    > only one of them actually needs to be fixed.

    Correct. My point was that it's often very easy to find that single line that needs fixing. Just work yourself up the instantiations until you find a line in your code (as opposed to library code).

  189. Obvious answer by r341i7y · · Score: 1

    Code is pretty or even beautiful when it matches the expectations. In particular, management thinks the code is beautiful if a programmer can spend a deterministic amount of time on a task and be done with it. The same programmer thinks the code is beautiful when he spent less time on it than he expected. A user of the program thinks the code is beautiful if it doesn't crash and doesn't waste the resources on his computer.

    1. Re:Obvious answer by Anonymous Coward · · Score: 0

      You can call a tail a leg, but that's doesn't make it a leg, and cows still have only 4 legs, not 5.

      You sound like an average fuckup manager yourself since you think that words mean whatever you say they mean.

  190. Quantlib by jawahar · · Score: 1

    Check http://quantlib.org/ code. It is pretty good.

  191. CMU CL and OpenBSD by Anonymous Coward · · Score: 0

    CMU CLis a Common Lisp compiler/interpreter (written in cl). Its code is just beautiful - after about 1-2 months since my first contact with lisp I understand nearly everything at first glance. (SBCL also have very nice code). OpenBSD's code (written in C) is also very clear and pretty.

  192. pretty driver code... by martinde · · Score: 3, Informative

    I've always been impressed by the BusLogic SCSI driver code in the Linux kernel. Anyone interested in what a good low-level, bit banging C program should look like should study its code carefully. Here is a randomly chosen snippet: /*
            The Modify I/O Address command does not cause a Command Complete Interrupt.
        */
        if (OperationCode == BusLogic_ModifyIOAddress)
            {
                StatusRegister.All = BusLogic_ReadStatusRegister(HostAdapter);
                if (StatusRegister.Bits.CommandInvalid)
                    {
                        BusLogic_CommandFailureReason = "Modify I/O Address Invalid";
                        Result = -1;
                        goto Done;
                    }
                if (BusLogic_GlobalOptions.TraceConfiguration)
                    BusLogic_Notice("BusLogic_Command(%02X) Status = %02X: "
                                                    "(Modify I/O Address)\n", HostAdapter,
                                                    OperationCode, StatusRegister.All);
                Result = 0;
                goto Done;
            } /*
            Select an appropriate timeout value for awaiting command completion.
        */
        switch (OperationCode)
            {
            case BusLogic_InquireInstalledDevicesID0to7:
            case BusLogic_InquireInstalledDevicesID8to15:
            case BusLogic_InquireTargetDevices: /* Approximately 60 seconds. */
                TimeoutCounter = 60*10000;
                break;
            default: /* Approximately 1 second. */
                TimeoutCounter = 10000;
                break;
            }

    This is some seriously low-level stuff, and it reads like English text. It totally changed my ideas about what this kind of code should look like! It believe it was written by the late Leonard Zubkoff.

    1. Re:pretty driver code... by Anonymous Coward · · Score: 1, Interesting

      Actually that's an example of a bad coding practice: notice the magic number 10000. In the above example it would be much better to use a named constant like BUSLOGIC_TIMEOUT_LOOPS_PER_SECOND, or maybe better yet BusLogic_GlobalOptions.TimeoutLoopsPerSecond. Incidentally, doing so would also remove the stupid "here's what 10000 means" comments.

      And while I'm ranting about comments, I'll point out that they didn't feel the need to explain WHY those particular values are given 60 second timeout while the default is only one second.

  193. ...and Knuth should know by toby · · Score: 3, Insightful

    As the inventor of "literate programming"[1], early practitioner of open source, and author not just of The Art of Computer Programming and its included programs, but some extraordinarily elegant and widely used software systems himself (including TeX and METAFONT). How many people's programs are worth printing as hardcover books?

    [1] mention also to Kernighan & Plauger's Software Tools.

    --
    you had me at #!
  194. The Politics was donated... by Anonymous Coward · · Score: 0

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

    Yes, but reflecting that change, we're getting new "well known" people like NewYorkCountryLawyer. Kind of dresses the place up.

  195. pretty code by Anonymous Coward · · Score: 0

    I don't know about the code, but the most elegant system I have looked at in a long time is forthought, an early version of Forth used in the maing of Starflight on the PC.

    Each forth word is a pointer to the code that executes it.

    http://wiki.starflight3.org/sf1techforthought.ashx

    shows more detail, but the compiled code is as elegant as Kate Winslett in a period drama.

  196. PLXTech driver by Anonymous Coward · · Score: 0

    PLX technology (PLXTech.com) makes a PCI interface chip. When you download the driver for their chip you also get the source code. It is, in my opinion, one of the best written bits of code I've seen in a while. It's clean, well commented, and organized out in such a way that it is obvious where to look for features. As reference code goes it is hard to beat.

  197. Young Programmers... by Organic+Brain+Damage · · Score: 3, Insightful

    ...almost always want to re-write old code from scratch.

    Almost always without taking the time to understand what that old code does. Why? Because writing code is much easier than reading code. Reading code takes perseverance and ability to focus on large numbers of nit-picky details. Something our TV-age brains cannot easily do.

    The result of throwing out the old code without understanding what it is accomplishing is not always positive from a business perspective.

    Sure, sometimes crufty code is crap.

    But sometimes, like on a terminal emulator project I worked on in the mid-90's, the cruft was a bunch of code, accumulated from 1985 to 1995, that actually emulated the bugs in the firmware of 10 different manufacturer's dumb terminals. The programmers who wrote the applications that ran on these dumb terminals relied upon these bugs in the firmware and when the bugs disappeared, the applications broke.

    The company that tried to sell the "correct", "new", "elegant" terminal emulator hit a big solid brick wall called "market acceptance." The company that kept the cruft made roughly $4 million per year in profits and supported 25 employees' and their families for a decade while they developed new products.

    So, before you look at code in a shipping product and say to yourself "this is crufty crap and should be re-written from scratch" ask yourself this question: "Do I really understand what this crufty crap is doing?"

  198. Pretty Code by corporate+zombie · · Score: 1

    Don't just thing pretty code makes a nice system. We recently rewrote a large system. While implementing I noticed that when you wanted to add something to the new system the infrastructure was already there and it was easy to conceptualize how to work the new functionality in. In our old system the code almost pushes you away. Trying to extend functionality almost always means a several day long refactor chain or just adding a new wart. I figure going forward the rewrite would pay for itself over the next two to three large requests for additional functionality so of course it got canceled and we were told to work in the old codebase. :/

    Anyway my point is there is more to pretty than syntax and layout.

        -CZ

  199. eCos by LinuxInDallas · · Score: 1

    I was in an embedded systems seminar hosted by Jack Ganssle (sp?) and he claimed that the eCos (embedded Configurable operating system) source code was some of the best code he had seen, especially given it's complexity.

  200. Brooks Law by Anonymous Coward · · Score: 0
  201. Scorched Earth 3d by Anonymous Coward · · Score: 0

    I'm not so sure of that. I once looked over the Scorched Earth 3d code for a friend that was having trouble setting up a custom weapon file. At first, the code made no damn sense at all, but I could still tell it was very clean code.

    After about half an hour, something suddenly clicked and I realized it wasn't just clean code, but an incredibly clean paradigm as well. I nearly had a code orgasm it was so sweet and perfect a style.

    Just knowing how that code works has improved my programming. Hats off to the original writer.

  202. Dark Energy? by mcrbids · · Score: 1

    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.

    Hmmm... could it be that cruft is really a manifestation of dark energy being stored in another dimension of N-space?

    Wouldn't that mean that cruft just might be a nearly infinite energy source? This could get real interesting!

    --
    I have no problem with your religion until you decide it's reason to deprive others of the truth.
  203. man chroot by tepples · · Score: 1

    Hard coded file and folder names (it must be in exactly one location, too bad if you have a need for two outgoing SMTP servers running on the same box with different configurations) Did you try chroot?

    Memory deallocation done by exiting the program How else should memory allocated statically in BSS be deallocated? By turning off the machine?
  204. Left, center, right? by tepples · · Score: 1

    This place is turning into Hogwarts left, right, and center! Since when do they play LCR at Hogwarts?
  205. SBCL by ghettoimp · · Score: 1

    As a total newbie to SBCL's source code, I was delighted to find it written in Common Lisp instead of bootstrapped through some other language. The code I was interested in patching was about 30 lines total, and comments explained how it worked. Great stuff.

  206. No. by Talgrath · · Score: 1

    There is no such thing as pretty code, just fuckable code; the type of code that you'll never really wanna look at for too long, but it's all right looking.

  207. Buy a book (Norvig, PAIP) by Dunedain · · Score: 2, Interesting

    Peter Norvig, now CTO of Google, agrees with you. Coding, like writing, is best improved by an alternating diet of writing and reading good works. He collected a few of the best he'd found in a book called Paradigms of Artificial Intelligence Programming, available from his web site or from Amazon: http://norvig.com/paip.html

    It talks about AI because it was the 80s (92 by the time it hit shelves) and AI was cool---but the applications involved are now just what we call computing. It's not perfect: fifteen years have passed since it was written. In that time, C++'s STL and Boost have caught up with many features of Common Lisp. Java's come along and done well. Other interactive dynamic languages than Lisp exist: Python, for example. So you'll have to do some translating in your head---but for the same reason that Cicero is read by students of English rhetoric, Norvig should be read by C++ and Java programmers seeking mastery.

    --
    -- Brian T. Sniffen
  208. Spoon Microkernel by nko321 · · Score: 2, Interesting

    http://www.smk.co.za/

    I know practically nothing about OS programming and my C / C++ has been rusting since University, but this guy writes code that even I can follow.

    1. Re:Spoon Microkernel by anubi · · Score: 1
      Nice link!

      I wish I had a mod point for you.

      --
      "Prove all things; hold fast that which is good." [KJV: I Thessalonians 5:21]

  209. Re:BOOST::Python, but you haven't seen the source? by dascandy · · Score: 1

    > 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!!!
    Yeah... That's a butt-ugly hack that's standard from 2009 and on.

    > BOOST looks easy to dumb-ass programmers, but these programmers leave bugs that are difficult for expert programmers to find.
    Learn your language and you'll understand it. Note, that refers to ISO C++, not Microsoft C++.

    > BOOST makes compilers run very very slow, and often breaks the optimizer anyway.
    They make heavy use of the optimizer. If your compiler runs very slow and has an optimizer that makes broken code, I'm not going to blame any code for that except the one IN the compiler. Your compiler should work, if it doesn't, then fix the compiler.

  210. oh my by samantha · · Score: 1

    C++ and modern techniques like exception handling and RAII? Hahahaha. Do not expect any large scale good code in a krap language environment. If you want to see beautiful code then learn Lisp. The largest reason most projects of any size become code crap magnets is because there is far too little incentive and support to improve our tools.

  211. Pretty code by Anonymous Coward · · Score: 0

    10. All code everyone writes is crap and fundementally flawed.

    The real question on prettyness is not how pretty it is but in a relative sense how crappy it is. Never waste your time by being happy with anyones code.

    Authors who write code that blindly submit commands without checking their status just need to be fired outright. Some projects are hard enough without people on your own team working against you.

    The same goes for people who rewrite code simply because it doesn't fit into their self righteous world view.

    The best codes in medium scale applications I've seen all whore meta-data like their going out of style and seek to create frameworks that don't too specifically target the problem space.

    High level design is much much more important than low level implementation. You can ususally salvage low level codes without much trouble. Design mistakes are much more costly.

    I've seen too many problems arise from people with unbalanced views thinking .. design vs snazzy language features. Its sometimes hard to do but one needs to be aware of the global implications of relying on language feature x to keep the system managable when design y would preculde the need for x in the first place. (Ahmm OO whores this means you!)

    At the end of the day the ultimiate success in terms of complete lifecycle of a project trumps anyones personal views of the state of its codebase. If its successfull with low bug rates, maximizes profits and concidered a godsend to the end-user then it was a well written piece of crap. (GOTO 10)

  212. STL by rocketfodder · · Score: 1

    I've always been pretty impressed reading through the code for the Standard Template Libraries. There's some absolutely brilliant, generally simple code there. Just about everybody that writes C++ for a living has used it at some point. It's easy to use, well documented, and general enough to use or modify-and-use in countless projects.

    [no sig here, move along. (fnord)]

  213. Neat kernel code by Anonymous Coward · · Score: 0

    Some recent, low-level, high-quality kernel code I've seen: http://vmhack.acm.jhu.edu/source/xref/vmhack/linux -2.6.20.1/vmhack/resolve_page_fault.c

    This was from a project that someone posted about in #mm, to rewrite the Linux memory manager.

  214. This is a common bug. by Anonymous Coward · · Score: 0

    Every unix will re-use pids in the same second. The assumption that you can't go through 64k pids in a second is a mistake. And good operating systems don't use sequential pids anyways.

  215. The Tandy CoCo by Fantastic+Lad · · Score: 5, Insightful
    Limitation is the Mother of Pretty Software.

    I remember when that cute little home computer came out, and all the programs were just so. . , plinky.

    Memory was a huge barrier, because you only had a small quantity of the stuff, and nobody understood the architecture of the system well enough to produce efficient programs.

    But back then, there were no video card upgrades. No faster processors and mother boards being produces every three months. If you wanted higher speed and cooler graphics, you had to write your code in more ingenious ways.

    And so that's what happened.

    By the twilight years of the Color Computer, the games people were writing on that thing were unreal. I remember looking at a few and thinking to myself, "This is the same computer? Wow! Humans rock!"

    When you reach the raw power limitations of your muscles but you still want to improve yourself in your combat skills, you take up Kung Fu. That's how it was in the old home computer days. Nowadays, though, (dang kids; I hadda walk fifty miles to school!) it seems that the bulk of improvement comes with the purchasing of increasingly large muscles.

    This is not to say that there is no software innovation. Heck, id Software did some pretty amazing things with software ingenuity. But I do remember thinking during the first few years of the big PC revolution, after the 486 was reaching its twilight, "You know, all this hardware innovation is great and all. . , (big muscles are cool), but part of me wishes it would stop cold for six solid years just what would happen when the programmers were really pushed. --You know, to see what one of these machines is actually capable of doing.


    -FL

    1. Re:The Tandy CoCo by The+Raven · · Score: 1

      If you want to see what programmers can do with a computer if it stops changing for a few years, don't look at computers... check out consoles. Some of the games released nowadays for the PS2 are truly beautiful, better looking than some other games released for the PS3/XBOX 360. Early games for the same system look really bad in comparison. That's the difference several years of practice make.

      --
      "I will trust Google to 'do no evil' until the founders no longer run it." Hello Alphabet.
  216. They don't have to be. by Anonymous Coward · · Score: 0

    Good operating systems use random pids. There is nothing that says pids must be sequential, and assuming such is a mistake.

    1. Re:They don't have to be. by Rakishi · · Score: 1

      Good operating systems use random pids. There is nothing that says pids must be sequential, and assuming such is a mistake. Likewise there is nothing that says they must be random and assuming that is even a biggest mistake.
  217. WIN32 and MFC by master_p · · Score: 1

    Just kidding! :)) (as well)

  218. Reminds me of a quote from literature... by CorbaTheGeek · · Score: 1

    "Not that the story need be long, but it will take a long while to make it short." Thoreau. Letter to a Friend. And there are variations of that quote, dating back to days of Cicero.

  219. Are you kidding? by zigamorph · · Score: 1

    If you prefer ALGOL to C, then please code in ALGOL. #defining your own syntax absolutely kills readability and makes small stuff like bad indentation and erroneous comments pale in comparison.

  220. Re: Any Pretty Code Out There? by Xernon · · Score: 2, Insightful

    As you note, the answer is mostly no. In my experience, it is the experienced people who are more likely to complain about code quality, as they can better recognize it and value it more. I just wrote an article about the need to make code more 'pretty': Why You Should Polish Your Code. One code base that has consistently impressed me is the Spring Application Framework, which is open source and written in Java (I'm primarily a Java developer). I've looked at other popular open source Java libraries and generally have not been impressed by their code quality, so I don't think that open source is any guarantee of prettier code.

  221. Ogre3D maybe? by yruf · · Score: 1
    Ogre3D is a 3D-Engine that has nice design as a main goal.

    I didn't have a look at the code myself, but the project matured for a while now and the statements on their website are fairly self-confident:

    [...]OGRE is different. OGRE is design-led rather than feature-led. Every feature that goes into OGRE is considered throughly and slotted into the overall design as elegantly as possible and is always fully documented, meaning that the features which are there always feel part of a cohesive whole. Quality is favoured over quantity, because quantity can come later - quality can never be added in retrospect. OGRE uses sound design principles learned, tried and tested many times in commercial-grade software - the object-orientation mentioned in it's moniker is just one of those approaches - frequent use of design patterns is another[...] ogre3d.org
  222. Garden simulator source code by Paul+Fernhout · · Score: 1

    http://www.gardenwithinsight.com/progman.htm

    Very pretty Delphi code, especially compared to the spaghetti Fortran which was translated to Delphi for some of the underlying models. Notice how, say, all the simulation variables now have units appended to the end of the name, as in "rainfall_mm".

    --
    A 21st century issue: the irony of technologies of abundance in the hands of those still thinking in terms of scarcity.
  223. Re:BOOST::Python, but you haven't seen the source? by r00t · · Score: 1

    I do cross-platform code, and I look at the assembly output.

    By "breaks the optimizer" I wasn't meaning incorrect output. I mean the optimizer gives up on the tangled mess, producing a rather unoptimized result. This affects both gcc 4.1 and Visual Studio 200x. (2005 I think -- the one after 2003)

    Maybe you have some exotic compiler from Intel or Sun that does everything perfectly and has no bugs. The two most popular compilers (gcc and Visual Studio) have big trouble. Heck, neither will even get std::min right; the plain C macro produces better assembly code.

    BTW, you're kidding about "standard from 2009 and on", right? The committee has shown little sense of shame before, but seriously... that'd be way over the top. It's creepy and sad that I should even wonder that you might not be joking.

  224. SevOne Software Satisfaction by scubstev834 · · Score: 1

    I work for a company called SevOne. We write network management software (backend in C and PHP, front-end all web-based and PHP). I think about 70% of the codebase is very well written (though not maintained). Considering the complicated nature of the software we write, I think it's really made a huge impact on hiring new people and having them get right into it. Though that 30% thats left over looks like I tried to open a JPEG file in NotePad++ :-(

  225. I'm not surprised by toby · · Score: 1

    it is not a very large code base with lots of developers

    That may have something to do with it. :)

    But seriously. I saw a Google Talk by lead developer Dr Richard Hipp, who struck me as an organised, methodical clear thinker who takes pride in shipping a product of high quality.

    If I grow up, I want to be a developer like him.

    --
    you had me at #!
  226. Deja Deja Vu Vu by cradle · · Score: 1

    This question gets asked here from time to time. For example,

        Where Can I Find Beautiful Code?

    and when I asked it back in -- my god -- 1998:

        Ask Slashdot:Programming Styles

    1. Re:Deja Deja Vu Vu by Zarf · · Score: 1

      For the sake of the industry, I hope you get different answers every time you ask... at least I hope you get new answers.

      --
      [signature]
  227. Very enterpricy by SLOGEN · · Score: 1

    Nice. Factory, Singleton, A sort of Strategy -- what a good program, that's excellent :)

    Perhaps, with a few refactorings, this could become the HelloWorld of tomorrow. You could declare an interface for MessageBody ;)

    And now, back to the real world.

    --
    SLOGEN [ http://ungdomshus.nu : Sebastian cover music]
  228. Golden Code by SoopahMan · · Score: 2, Informative

    What you're asking for is often called Golden Code or Golden Pages and usually exists within large software engineering companies. The problem with gaining access to such things is that they usually are considered very important to the organization who owns them, so they are not made public - they're more or less considered trade secrets, a guide to that particular company's proprietarily developed best practices.

    The other problem with easy access to Golden Code is that it must be constantly maintained to remain... "golden." So even if someone were to post a great example online, they're probably not getting paid to do so, so it's probably going to lose its luster in a couple years. Companies who maintain Golden Code usually assign a particular product to be coded in a "golden" way and continuously maintained in that perfect state as an example to all. This requires a lot of money.

    So the point is, if you want access to Golden Code, get hired at a big software company. There are a fair number of them out there if you look outside the most obvious markets. Enjoy.

  229. Projects with good code by Anonymous Coward · · Score: 0

    e17 and the efl are some of the best code I've seen in years.

    Other good code I've seen recently include pugs and parrot, but those are a bit more esoteric.

  230. I've found C++ poor, but some C to be excellent by Teunis · · Score: 1

    For C++: no. C++ doesn't really scale very well and doesn't share nicely. So no I can't think of any specific C++ examples. Nice language for relatively quick UI interface dev (but both C# and python are superior for prototyping except where scripts have too much overhead).

    Some other languages (python for instance) tend to be clean code from design.

    Now, C on the other hand...
    - Linux kernel: absolutely beautiful.
    - Gnome - clean, decent, nice. There are sections that still require work but for the most part it's a scalable reliable system.
    - postgres - the underlying model takes getting used to but after that - very nice code.
    - libJPEG - the origins for me of object-oriented C.
    - MacOSX API (okay I really really really like it. It's still evolving but I very much enjoy the directions it's going)

    for worst-ever code I'm nominating MFC++. My past experiences with it resulted in multiplied development time with many "artifacts".

  231. Oh no, I'm not falling for that! by Sits · · Score: 1

    You're probably one of those script-ruby-wiki-vandal-spam-botnet-evangelists aren't you? When I foolishly blurt out this new cool site you quietly infiltrate it accounts from your zombie bot army... Then one day you strike and destroy the inboxes and connectivity of 99% of the most important people in one strike. I wind up being disowned and the remaining 1% are forced to wander from IRC server to ICB server looking for a new home...

    Besides, I'm no luminary so I am on the wrong side of the fence to know where everyone has gone (if they have indeed gone anywhere). Years from now we'll probably find that they're all on Facebook or something...

  232. Dan Bernstein by sqldr · · Score: 1

    If Dan Bernstein worked for the fire service and you phoned to say your house was on fire, he would tell you your sprinkler system was configured wrong and hang up.

    --
    I wrote my first program at the age of six, and I still can't work out how this website works.
  233. Pretty Pretty Good Privacy by Anonymous Coward · · Score: 0

    For readable code, I've always liked the PGP crypto code. The UI stuff is messy, but the underlying encryption code is art. The function names clearly describe what the functions do, the comments explain the algorithms and the logic of the design (not stupid stuff like "exit loop"), and the error handling makes it quite easy to find problems, and since it has been published so it can be machine readable (to deal with export regulations) the formatting is completely consistent, and when something is implemented using a clever algorithm in assembler, the comments almost always have the same algorithm in C (which helps portability) and then the simple algorithm in C as well.

    I'd say that messy code is the result of high changing what you're trying to do. At one level it can be because one programmer loves globals while another one avoids them, but it can also happen at a structural level as a result fixing bugs if the bug forces a redesign of the structure of the program. I think that's part of the reason that UI code tends to be so ugly -- the goals and work flow change frequently.

  234. OpenVPN, glib by cduffy · · Score: 2, Informative

    OpenVPN is very well-written C -- clean and accessible. Likewise for glib (not glibc, glib), presuming one likes the fun it does with macros.

  235. Windows NT by Anonymous Coward · · Score: 0

    Windows NT source code

  236. refactoring must be pointful by Anonymous Coward · · Score: 0

    "I've often heard Java folks talk about re-factoring code and that's fine if no one is using your app, but in the event that folks and money are dependent on it, then re-factoring really just increases risk to all involved. The best possible outcome is that no one will notice the changes. "

    yes : thing is though that refactoring without an aim is tinkering. you refactor the code because you want to change it, and you have to refactor to make "room" for that change. the existing unit tests (you have those, right?) tell you if yr changes have broken anything; and the new one you write fails (you hope/expect) because the feature you want to add doesnt exist yet. i don't see the risk under those circumstances. i _do_ agree that if you don't like the code, you should refactor it, but _only_ because you need to change it. "the best is the enemy of the good" : if it works, it's good. if is doesnt work - then its a whole new ball game, and i'd suggest refactoring to make the bad code easier to change now is both necessary and a boon to the next guy/gal who has to go in there.

    i've a lot of tech lead experience and scars from this sort of thing : there's a happy medium between the pattern junky whose code never gets finished and generally looks a bit arcane, and the "can write it, can't design it" coder with 200 line methods and an approach to object orientation is er, functional decomposition. in my experience, i've spend more time refactoring to prise the latter "code fistula" apart.

  237. Paradox by taradfong · · Score: 1

    The people that write and/or know great code don't have the time to waste posting about it here.

    --
    Does it hurt to hear them lying? Was this the only world you had?
  238. Re:BOOST::Python, but you haven't seen the source? by Anonymous Coward · · Score: 0

    Understanding how to program in C++ effectively is not one of these cases.

  239. RSpec by unDees · · Score: 1

    I'm a little biased, but I think the RSpec test description language (built on Ruby) encourages nice, legible test scripts. You get to use natural-looking language like this example:

    @stack.peek.should == @last_item_added

    ...as a pleasant alternative to a bunch of assert macros. The source code to RSpec itself is pretty decent, too.

    --
    "I call a baby goat a 'goatse.'" -- my non-Internet-savvy 6-year-old stepdaughter
  240. Go to assembler by guruevi · · Score: 1

    Basically, I like assembler because you have to be a good programmer in order to get it right and UNDERSTAND the system. I can't do it myself though:

    mov ax,cs
    mov ds,ax
    mov ah,9
    mov dx, offset Hello
    int 21h
    xor ax,ax
    int 21h

    Hello:
        db "Hello World!",13,10,"$"

    --
    Custom electronics and digital signage for your business: www.evcircuits.com
  241. Nachos.. by inquisitive123 · · Score: 1

    When working on Nachos - A very basic OS designed mainly for academic education purpose - I found it pretty neatly coded.

  242. To Anonymous Coward by pongba · · Score: 1

    To be fair, your arguments are irrelevant: (1) You don't actually need to debug them. I mean, really, how many times do you have to debug a library(like STL)? Even if there's a bug in it, it's not yours to fix. (2) yea, yea, yea. A thousand times yea. Obviously C++ is so complex that it gives compiler writers headaches all the time. But is it C++'s fault really? The real problem is, if compiler can't catch up, then maybe it's the compilers we should blame. Or maybe we can simply wait and not blame anyone. Another cent on C++'s complexity, like Bjarn Stroustrup himself said, we need relatively complex language to deal with really complex problems. English is arguably one of the most complex languages in the world, but it's still popular and well served its purpose. (3) This is a point that has been brought up (and, of course, explained) like a thousand times, too. The problem is real, but the painkiller is coming soon. Concepts system in C++09 will relieve the pain. (4) Bug-fixing is always hard, whether we're dealing with template code or not. And for expert library develops, the major effort is probably not on rassling with templates, and even if it is, like I said previously, we need relatively complex languages to deal with really complex problems. On the other hand, a floating point arithmetic bug may take much more time to fix than a template syntax bug.

  243. Gled by Kvorg · · Score: 2, Interesting

    Take Gled (http://www.gled.org/ - a recent CVS snapshot is preferable), a distributed C++ application builder with OpenGL/OpenAL/FLTK interfaces, object persistence and excellent extensibility.

    It certainly is not pretty the first time you look at it, that is probably true for any unique project, but if you look harder, you will see a strange tangle using ROOT, CINT the C++ interpreter, built-in C++ object dictionaries, elegant and fast network stack for object streaming and synchronization, and strangely effective remote procedure call interface. But my favourite is the auto-building FLTK gui.

    While remotely involved, I do enjoy this code immensely.
    Try building a new library for it and enjoy GUI-enabled objects in minutes... (There is even a scratch for a TA-like game in one of the demos, not yet playable.)

    --
    -Kvorg
  244. Deadbeef Random Number Generator by RAMMS+EIN · · Score: 2, Interesting
    If you still need random numbers in a portable way, you can always use my Deadbeef Random Number Generator. It seems to work faster and generate better numbers than rand() on the *nix systems I've tested with, but take that with a grain of salt, because I don't actually know enough about random numbers to make a good assessment here. Anyway, the advantage of deadbeef_rand is that it's really simple:

    static uint32_t deadbeef_seed;
    static uint32_t deadbeef_beef = 0xdeadbeef;
     
    uint32_t deadbeef_rand() {
            deadbeef_seed = (deadbeef_seed << 7) ^ ((deadbeef_seed >> 25) + deadbeef_beef);
            deadbeef_beef = (deadbeef_beef << 7) ^ ((deadbeef_beef >> 25) + 0xdeadbeef);
            return deadbeef_seed;
    }
    Please see the web page for more information, including test results.
    --
    Please correct me if I got my facts wrong.
  245. Nethack by Anonymous Coward · · Score: 0

    I've was pretty impressed with how clean and straightforward the NetHack code looked.
    That and of course anything that I've written.

  246. Space Shuttle Code is probably kinda pretty by dfenstrate · · Score: 1
    I doubt I'm the only one to post this old fast company article , but I don't see it modded up.

    So there you have it.
    Excerpt:

    What makes it remarkable is how well the software works. This software never crashes. It never needs to be re-booted. This software is bug-free. It is perfect, as perfect as human beings have achieved. Consider these stats : the last three versions of the program -- each 420,000 lines long-had just one error each. The last 11 versions of this software had a total of 17 errors. Commercial programs of equivalent complexity would have 5,000 errors.

    ...
    To be this good, the on-board shuttle group has to be very different -- the antithesis of the up-all-night, pizza-and-roller-hockey software coders who have captured the public imagination. To be this good, the on-board shuttle group has to be very ordinary -- indistinguishable from any focused, disciplined, and methodically managed creative enterprise.

    ...
    At the on-board shuttle group, about one-third of the process of writing software happens before anyone writes a line of code. NASA and the Lockheed Martin group agree in the most minute detail about everything the new code is supposed to do -- and they commit that understanding to paper, with the kind of specificity and precision usually found in blueprints. Nothing in the specs is changed without agreement and understanding from both sides. And no coder changes a single line of code without specs carefully outlining the change. Take the upgrade of the software to permit the shuttle to navigate with Global Positioning Satellites, a change that involves just 1.5% of the program, or 6,366 lines of code. The specs for that one change run 2,500 pages, a volume thicker than a phone book. The specs for the current program fill 30 volumes and run 40,000 pages.

    "Our requirements are almost pseudo-code," says William R. Pruett, who manages the software project for NASA. "They say, you must do exactly this, do it exactly this way, given this condition and this circumstance."



    I imagine that's as good as it gets for proper coding.

    My programming education never made it past the C programming course I needed for my BSME. The fastcompany story looks relevent though.
    --
    Alcohol, Tobacco and Firearms should be the name of a store, not a government agency.
  247. Acme::bleach by Anonymous Coward · · Score: 0

    maybe Acme::bleach should be utilized...for really clean programs!

  248. getpid() in qmail by marcelk · · Score: 1

    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.
    /* myrand - pseudo-random number */

    int myrand(void)
    {
            if (myrand_initdone == 0)
            mysrand(getpid() ^ time((time_t *) 0));
            return (rand());
    }

    Source: postfix 2.4.3

  249. Re:BOOST::Python, but you haven't seen the source? by andreas_huber69 · · Score: 1

    Hello again

    I've finally gotten around to compiling your example with MSVC. A complete compile link cycle takes 10 seconds on my 3.2GHz Pentium 4, with a very small bump (50MB) in the memory graph (my box has 1GB).

    Regarding the large binary sizes you reported by private email:
    With MSVC the executable is 200KB, but I do remember that I sometimes had very large binaries with mingw. I guess this is somehow connected with the compiler/linker taking so long. Might be worth reporting to the gcc developers. Unfortunately, I don't have much time to spend on statechart at the moment as my job is currently very demanding and I'm also in the process of moving to new hardware. So I'm afraid I won't be able to look into this more deeply in the next few weeks.

    Andreas