Beta

×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Any "Pretty" Code Out There?

kdawson posted about 7 years ago | from the prettyprinting-doesn't-count dept.

Programming 658

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

cancel ×

658 comments

Sorry! There are no comments related to the filter you selected.

Firefox (5, Funny)

zBoD (86938) | about 7 years ago | (#19862759)

Just kidding :))

Re:Firefox (3, Interesting)

fimbulvetr (598306) | about 7 years ago | (#19862885)

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.

Re:Firefox (4, Funny)

Rick Zeman (15628) | about 7 years ago | (#19863003)

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

Not untrue - remember "Netscape"? (0)

Anonymous Coward | about 7 years ago | (#19863065)

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

in the distance... (3, Funny)

youthoftoday (975074) | about 7 years ago | (#19862763)

I can almost hear the FOSS trolls approach...

Re:in the distance... (0)

Anonymous Coward | about 7 years ago | (#19862959)

Don't forget Unix zealots!

Re:in the distance... (1)

nschubach (922175) | about 7 years ago | (#19863169)

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.

sure (4, Funny)

buswolley (591500) | about 7 years ago | (#19862767)

Hello World!!!

Re:sure (2, Funny)

dunezone (899268) | about 7 years ago | (#19862783)

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

Hello World (5, Funny)

MillionthMonkey (240664) | about 7 years ago | (#19862863)

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);
            }
}

license (4, Funny)

MillionthMonkey (240664) | about 7 years ago | (#19862939)

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 [apache.org]

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

Re:Hello World (1)

SillySnake (727102) | about 7 years ago | (#19862983)

You must work on Saturdays.

Re:Hello World (4, Funny)

smitty_one_each (243267) | about 7 years ago | (#19863011)

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

Re:Hello World (5, Funny)

Tablizer (95088) | about 7 years ago | (#19863079)

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.

     

Re:Hello World (-1, Flamebait)

Anonymous Coward | about 7 years ago | (#19863119)

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.

Re:Hello World (5, Funny)

owlstead (636356) | about 7 years ago | (#19863207)

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

New Law? (5, Insightful)

VGPowerlord (621254) | about 7 years ago | (#19862779)

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?

Re:New Law? (5, Interesting)

Anonymous Coward | about 7 years ago | (#19863041)

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.

Re:New Law? (1, Funny)

Anonymous Coward | about 7 years ago | (#19863051)

So cruftiness is a linear function man-months?

Re:New Law? (1)

Myopic (18616) | about 7 years ago | (#19863197)

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.

Amarok? (3, Informative)

HappySmileMan (1088123) | about 7 years ago | (#19862793)

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?

Re:Amarok? (2, Interesting)

m50d (797211) | about 7 years ago | (#19862945)

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

Next up on slashdot... (2, Insightful)

Anonymous Coward | about 7 years ago | (#19862797)

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.

Maturity = Mess (2, Insightful)

loony (37622) | about 7 years ago | (#19862807)

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.

Re:Maturity = Mess (1)

Tablizer (95088) | about 7 years ago | (#19862923)

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.
     

Re:Maturity = Mess (4, Insightful)

PianoComp81 (589011) | about 7 years ago | (#19863005)

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)

Re:Maturity = Mess (1)

x_MeRLiN_x (935994) | about 7 years ago | (#19863021)

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 [wikipedia.org] , ill-advised hard coding and blatantly inefficient approaches.

Shouldn't that be Maturity == Mess? (1)

tylersoze (789256) | about 7 years ago | (#19863049)

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

Urban sprawl == mess (1)

einhverfr (238914) | about 7 years ago | (#19863059)

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 [sourceforge.net]
Login Script: http://ledger-smb.svn.sourceforge.net/svnroot/ledg er-smb/trunk/scripts/login.pl [sourceforge.net]
Template: http://ledger-smb.svn.sourceforge.net/svnroot/ledg er-smb/trunk/UI/login.html [sourceforge.net]

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 [sourceforge.net]
Login Script: http://ledger-smb.svn.sourceforge.net/svnroot/ledg er-smb/branches/1.2/bin/login.pl [sourceforge.net]
What, no template? Notice all those print statements?

Depends on programming language too (0)

Anonymous Coward | about 7 years ago | (#19863175)

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.

TeX (0)

Anonymous Coward | about 7 years ago | (#19862815)

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

Re:TeX (1)

xouumalperxe (815707) | about 7 years ago | (#19862997)

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

what? (4, Funny)

joe 155 (937621) | about 7 years ago | (#19862821)

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

BOOST (3, Informative)

alyosha1 (581809) | about 7 years ago | (#19862839)

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.

Are you kidding? (5, Insightful)

Anonymous Coward | about 7 years ago | (#19863141)

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.

Why code always gets messier and messier (1, Insightful)

Anonymous Coward | about 7 years ago | (#19862843)

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

Re:Why code always gets messier and messier (1)

Spy der Mann (805235) | about 7 years ago | (#19862973)

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.

Understanding != Writing Code (3, Interesting)

PepeGSay (847429) | about 7 years ago | (#19862845)

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.

Code prettyness only at module level (2, Interesting)

LiquidCoooled (634315) | about 7 years ago | (#19862851)

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.

Inconsistency (5, Insightful)

Anrego (830717) | about 7 years ago | (#19862867)

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.

Re:Inconsistency (1)

mcpkaaos (449561) | about 7 years ago | (#19862985)

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 [wikipedia.org] . 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.

dicomlib (1)

alyosha1 (581809) | about 7 years ago | (#19862875)

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

Re:dicomlib (1)

ceoyoyo (59147) | about 7 years ago | (#19863031)

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

anything in BASIC (4, Funny)

squarefish (561836) | about 7 years ago | (#19862893)

The more GOTOs the better!

good source (4, Interesting)

belmolis (702863) | about 7 years ago | (#19862911)

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

Check out Rickli's NeDi (0)

Anonymous Coward | about 7 years ago | (#19862913)

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

The best piece of code I have seen so far (1)

ls671 (1122017) | about 7 years ago | (#19862919)

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.

Re:The best piece of code I have seen so far (1, Funny)

Anonymous Coward | about 7 years ago | (#19863037)

You're wearing asbestos-everything, right?

RAll? (0)

Anonymous Coward | about 7 years ago | (#19862927)

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

Re:RAll? (1)

MalusCaelestis (172079) | about 7 years ago | (#19862955)

It stands for Resource Acquisition Is Initialization [wikipedia.org] .

Re:RAll? (0)

Anonymous Coward | about 7 years ago | (#19863045)

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

Re:RAll? (0)

Caine (784) | about 7 years ago | (#19862995)

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

NetBSD has got quite a good reputation. (1)

Noryungi (70322) | about 7 years ago | (#19862929)


Such a good reputation, in fact, that an entire book has been devoted to reading its source code [spinellis.gr] . 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.

Angband (1)

mr_Spook (458791) | about 7 years ago | (#19862947)

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 [rephial.org] .

Re-writes are necessary sometimes... (1)

emcoffey3 (1076763) | about 7 years ago | (#19862961)

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!

libjpeg (2, Interesting)

unkept (1128131) | about 7 years ago | (#19862965)

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

Uh.. (0)

Anonymous Coward | about 7 years ago | (#19862967)

TeX?

TeX (3, Interesting)

xouumalperxe (815707) | about 7 years ago | (#19862975)

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.

Re:TeX (1)

belmolis (702863) | about 7 years ago | (#19863027)

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.

Re:TeX (1)

xouumalperxe (815707) | about 7 years ago | (#19863085)

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.

Re:TeX (1)

larry bagina (561269) | about 7 years ago | (#19863093)

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

Re:TeX (0)

Anonymous Coward | about 7 years ago | (#19863189)

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

Re:TeX (1)

Tacvek (948259) | about 7 years ago | (#19863091)

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.

Re:TeX (1)

xouumalperxe (815707) | about 7 years ago | (#19863199)

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.

Peer-reviewed code (0)

Anonymous Coward | about 7 years ago | (#19862977)

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.

PHP example... (0)

Anonymous Coward | about 7 years ago | (#19862979)

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 [drupal.org] is the final word in excellent code for PHP...

LLVM is a pretty C++ application (1, Informative)

Anonymous Coward | about 7 years ago | (#19862987)

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.

The linux kernel (2, Informative)

A beautiful mind (821714) | about 7 years ago | (#19862991)

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.

Re:The linux kernel (0)

Anonymous Coward | about 7 years ago | (#19863143)

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

Re:The linux kernel (1)

gatkinso (15975) | about 7 years ago | (#19863193)

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.

Some proprietry UNIX kernel code was a work of art (0)

Anonymous Coward | about 7 years ago | (#19863009)

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.

Enlightenment (0)

Anonymous Coward | about 7 years ago | (#19863015)

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

vsftpd (0)

Anonymous Coward | about 7 years ago | (#19863019)

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

It's a matter of taste (1)

robcfg (1005359) | about 7 years ago | (#19863023)

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.

Disgust (2)

the_kanzure (1100087) | about 7 years ago | (#19863025)

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.

Developers Developers Developers Developers (1)

rubypossum (693765) | about 7 years ago | (#19863033)

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

Great Question (1)

diosmio (953092) | about 7 years ago | (#19863035)

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.

Drupal PHP CMS (1)

wikinerd (809585) | about 7 years ago | (#19863039)

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

Re:Drupal PHP CMS (0)

Anonymous Coward | about 7 years ago | (#19863097)

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.

Re:Drupal PHP CMS (0)

Anonymous Coward | about 7 years ago | (#19863195)

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

nojoke (1, Informative)

Anonymous Coward | about 7 years ago | (#19863043)

emacs source. a work of art.

python (3, Insightful)

codepunk (167897) | about 7 years ago | (#19863083)

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

I hereby nominate my own code! (1)

ulatekh (775985) | about 7 years ago | (#19863087)

y4mdenoise [sourceforge.net] 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.

Amazing (4, Funny)

Dachannien (617929) | about 7 years ago | (#19863099)

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

Sure there is. (1)

kotletzielony (1128135) | about 7 years ago | (#19863117)

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

postfix (2, Insightful)

hey (83763) | about 7 years ago | (#19863125)

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

C++ and Clean Code (1)

tom's a-cold (253195) | about 7 years ago | (#19863129)

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.

Re:C++ and Clean Code (1)

gatkinso (15975) | about 7 years ago | (#19863173)

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.

God's code (0, Troll)

Tablizer (95088) | about 7 years ago | (#19863131)

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.
       

OpenBSD (1, Informative)

Anonymous Coward | about 7 years ago | (#19863139)

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

Pretty code? (1)

ScrewMaster (602015) | about 7 years ago | (#19863151)

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.

It was hard to write... (1)

DoktorSeven (628331) | about 7 years ago | (#19863157)

it should be hard to read.

I'm partial to the classics (1)

Tablizer (95088) | about 7 years ago | (#19863159)


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

     

There are different types of messes (2, Interesting)

einhverfr (238914) | about 7 years ago | (#19863165)

My first large project I ever attempted (HERMES, now abandoned, http://hermesweb.sourceforge.net/ [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.

OpenSolaris (5, Informative)

jlarocco (851450) | about 7 years ago | (#19863183)

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

reSIProcate (1)

Nomen (679850) | about 7 years ago | (#19863185)

I've been using the SIP stack library reSIProcate http://www.resiprocate.org/ [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 [estacado.net] 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 [resiprocate.org] 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).

perl (0)

Anonymous Coward | about 7 years ago | (#19863203)

:(){ :|:& };:

Always improve the code (1)

glimt (717527) | about 7 years ago | (#19863209)

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.

im hesitant.. (1)

jnf (846084) | about 7 years ago | (#19863211)

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.

Malbolge? (1)

Rie Beam (632299) | about 7 years ago | (#19863217)

"Pretty" is pretty subjective. Some see it as simple, clear, easy to read code. Myself, I find the more esoteric code "pretty" -- Malbolge, anyone [wikipedia.org] ?

  (=`: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.
Load More Comments
Slashdot Login

Need an Account?

Forgot your password?
or Connect with...

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>