The Artima Developer Community
Sponsored Link

Weblogs Forum
Beautiful Code in the Real World - Part I

13 replies on 1 page. Most recent reply: Aug 13, 2007 5:08 PM by Kay Schluehr

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 13 replies on 1 page
Alberto Savoia

Posts: 95
Nickname: agitator
Registered: Aug, 2004

Beautiful Code in the Real World - Part I (View in Weblogs)
Posted: Aug 8, 2007 1:34 PM
Reply to this message Reply
Summary
In Part I we ask the question: "Is there a place and opportunity for truly beautiful code and programming pearls in real world of legacy applications and enterprise software?".
Advertisement

You are a bright-eyed and bushy-tailed developer. You have just finished reading the book Beautiful Code and you are ready to create some binary beauty of your own. You can’t wait to put what you’ve learned into action. You fire up your IDE and, as the blob of code that you’ve inherited and have to work with slowly loads, the brightness in your eyes is replaced by a glazed look. A minute later your bushy tail hangs limply in defeat. Reality sets in. Beautiful Code goes back on the shelf, next to Programming Pearls and Six-Pac Abs in Seven Days. You drink a sip of tepid coffee, sigh, and start hacking at the blob of code with the same level of energy and enthusiasm commonly displayed by those people in orange vests who pick up litter on the side of the highway.

The two most common comments I’ve heard on the topic of beautiful code, following the release of the book, go something like this:

Comment 1:

“I have read a few chapters of Beautiful Code. It’s a great book, but in my job I have to maintain a steaming pile of legacy code. I don’t have many opportunities to think about beauty because I barely have time to keep the existing code functional. The best I can do it to keep crappy code from getting worse.”

Comment 2:

“Very interesting book. I wish I had an opportunity to think about cool algorithms for tough problems, but I am working on a boring enterprise application. I read stuff from a database, do something trivial to it and then I generate some reports. There aren’t that many opportunity for clever algorithms and beautiful solutions in business logic.”

It’s easy to sympathize with, and understand, both comments. The odds of finding truly beautiful code in most production systems seem to be on par with the odds of finding a well-read copy of IEEE Transactions on Software Engineering in Paris Hilton’s apartment. Furthermore, enterprise software, which represents the bulk of code in existence, deals mostly with forms, reports, etc., which – one might argue – seldom require much thinking or cleverness.

Let’s face it, the majority of code that has to be written does not offer chances for the kind of beauty and cleverness that would earn it an entry in Beautiful Code – Part II. For every opportunity to implement something cool and clever, like MapReduce (see Chapter 23), there are hundreds of blue-collar pieces of code that have to be written or maintained.

Does that mean that you should stop thinking about beautiful code in your day-to-day programming? Should you save those lofty ambitions for your after-hour pet projects – or abandon them altogether? Of course not!

The opportunities for creating a true masterpiece of coding worthy of sharing and bragging about may be rare, but you have dozens of chances everyday to make the code base you work with more beautiful – even if you are stuck working on a mortifying morass of legacy code. That’s what my series of blogs Beautiful Code in the Real-World will be all about.

In the next few days and weeks, I will use these blogs to share with you thoughts, strategies, and ideas for creating beauty in everyday production code – even if that code looks as if it fell off the ugly tree and hit every branch on the way down.

Make sure you come back for Part II – Scorn globally, act locally.


Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: Beautiful Code in the Real World - Part I Posted: Aug 9, 2007 3:04 PM
Reply to this message Reply
Writing beautiful code is easy. Maintaining code so as that it remains beautiful is hard.

Chris Chedgey

Posts: 14
Nickname: chgrs
Registered: Apr, 2006

Re: Beautiful Code in the Real World - Part I Posted: Aug 10, 2007 7:20 AM
Reply to this message Reply
The Real World has some monster code-bases - I'd like to suggest you address how "beauty" can be applied in the large, not just to snippets, algorithms or class-level patterns.

Here's my humble contribution on the matter http://chris.headwaysoftware.com/2007/08/beautiful-archi.html

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Beautiful Code in the Real World - Part I Posted: Aug 10, 2007 9:07 AM
Reply to this message Reply
Can COBOL be made to be beautiful? My feeling is that it should be stuffed in a sack, beaten, weighed-down and tossed in the ocean.

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: Beautiful Code in the Real World - Part I Posted: Aug 10, 2007 9:53 AM
Reply to this message Reply
> Can COBOL be made to be beautiful? My feeling is that it
> should be stuffed in a sack, beaten, weighed-down and
> tossed in the ocean.

You just need to drink more beer before looking at the COBOL code :-)

Bill Pyne

Posts: 165
Nickname: billpyne
Registered: Jan, 2007

Re: Beautiful Code in the Real World - Part I Posted: Aug 10, 2007 9:57 AM
Reply to this message Reply
> Can COBOL be made to be beautiful? My feeling is that it
> should be stuffed in a sack, beaten, weighed-down and
> tossed in the ocean.

James, please don't be so sublime. What's your real opinion of COBOL? ;-)

Okay, onto an actual point and not directed at you James. Do experienced COBOL coders - and I'm not - find each others' code more and less beautiful? I find more and less beautiful C coding. I'm looking over Scala examples now and I find some that are elegant; consequently, the elegant ones are influencing how I'm going to approach use of the language. There's certainly more and less elegant SQL. When I was a DBA I had to review a lot of SQL; there are few developers who really use it well. My point is that there's certainly a subjective element influenced by what you're used to.

This is certainly a topic that waxes philosophical and draws us into discussions on Relativism.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Beautiful Code in the Real World - Part I Posted: Aug 10, 2007 10:38 AM
Reply to this message Reply
> Do experienced COBOL coders - and I'm not - find each
> others' code more and less beautiful?

There's definitely a 'right' way to do COBOL and a 'wrong' way to do it. Probably the worst thing about COBOL is that it allows for really bad approaches. But even the good COBOL looks like crap to me. You can either repeat yourself a billion times or make things opaque. Sometimes you have to compile it to clearly see what it does.

Bill Pyne

Posts: 165
Nickname: billpyne
Registered: Jan, 2007

Re: Beautiful Code in the Real World - Part I Posted: Aug 10, 2007 10:56 AM
Reply to this message Reply
> There's definitely a 'right' way to do COBOL and a 'wrong'
> way to do it. Probably the worst thing about COBOL is
> that it allows for really bad approaches. But even the
> good COBOL looks like crap to me. You can either repeat
> yourself a billion times or make things opaque. Sometimes
> you have to compile it to clearly see what it does.

I haven't had to support COBOL for 15 years and, even then, I only had to look over code to pull out SQL statements. It's a tool I've intentionally stayed away from.

So, it seems like within a language there is elegance/non-elegance but viewed in a wider scope, there's a progression in languages towards greater possibility for "beauty". Perhaps the ephemeral trait is greater abstraction giving a possibility for greater conciseness of expression with less verbosity?

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: Beautiful Code in the Real World - Part I Posted: Aug 10, 2007 11:17 AM
Reply to this message Reply
> So, it seems like within a language there is
> elegance/non-elegance but viewed in a wider scope, there's
> a progression in languages towards greater possibility for
> "beauty". Perhaps the ephemeral trait is greater
> abstraction giving a possibility for greater conciseness
> of expression with less verbosity?

Paul Graham has some things to say about this:

http://www.paulgraham.com/icad.html

http://www.paulgraham.com/hundred.html

http://www.paulgraham.com/langdes.html

Some people seem to have some rather strong opinions about Paul's writing, but I think when it comes to language design and usage, he is spot on.

Bill Pyne

Posts: 165
Nickname: billpyne
Registered: Jan, 2007

Re: Beautiful Code in the Real World - Part I Posted: Aug 10, 2007 12:49 PM
Reply to this message Reply
> Paul Graham has some things to say about this:
>
> http://www.paulgraham.com/icad.html
>
> http://www.paulgraham.com/hundred.html
>
> http://www.paulgraham.com/langdes.html
>
> Some people seem to have some rather strong opinions about
> Paul's writing, but I think when it comes to language
> design and usage, he is spot on.

I read "Hackers and Painters" not long ago and enjoyed it. I found myself agreeing with him quite a bit.

As far as language development goes, it's not only having the right ideas but having them at the right time. (Kind of a generalizable principle.) IMO, expression of ideas has become better. However, it's all still dependent on the developer. Unskilled developers are still going to write ugly code no matter the language. (An unskilled bike rider is still going to look clumsy even with training wheels and crash equipment.) Part of becoming skilled is a desire to do so and part is having skilled people to learn from.

nes

Posts: 137
Nickname: nn
Registered: Jul, 2004

Re: Beautiful Code in the Real World - Part I Posted: Aug 10, 2007 4:14 PM
Reply to this message Reply
50% of enterprise software is crud (Create, read, update and delete; pun intended). The book beautiful code has none of that.

I will be impressed the day somebody finds a beautiful way to create an interactive GUI front-end to correctly (keeping the business rules) manipulate views (consistent with the POV of different users) of a database. Bonus points if the solution scales properly.

The other 50% of enterprise software transforms data from one obtuse format into another to avoid having to manually type information taken from one proprietary application into another. Big companies unable to write all software themselves have hundred of those.

That is also a reason why most software written in house is not very reusable. Specific utility UI screens developed against “Acme loan processing database” and a data transformation program that allows to import client data from “Bambi client manager” into “Maxbeta billing system” is not very useful unless you just happen to own that software.

Vijay Kandy

Posts: 37
Nickname: vijaykandy
Registered: Jan, 2007

Re: Beautiful Code in the Real World - Part I Posted: Aug 10, 2007 5:24 PM
Reply to this message Reply
Creating and keeping anything beautiful comes with a price. I think source code is no different. Most of the time people settle for better than average. A Lamborghini looks beautiful but I can't afford it (yet :). I settled for a nice looking Grand AM. They are plenty of shops that offer maintenance service for it at a price I can afford. I see the source code the same way. My 2 cents.

robert young

Posts: 361
Nickname: funbunny
Registered: Sep, 2003

Re: Beautiful Code in the Real World - Part I Posted: Aug 12, 2007 10:02 PM
Reply to this message Reply
> I will be impressed the day somebody finds a beautiful way
> to create an interactive GUI front-end to correctly
> (keeping the business rules) manipulate views (consistent
> with the POV of different users) of a database. Bonus
> points if the solution scales properly.

There are a number, which do it correctly; beauty is another issue. I prefer Andromeda.

MDA/XBML/foobar are all built on the notion of "abstracting" away from source syntax to something higher/else. The FOM is XML; using the system catalog is not really different. The difference is in the expression. If one believes that xNF is the true model (and I do), then it's same/same. OTOH some, as the RoR folks, assert that if you have to resort to source code generation, then your language is semantically wrong.

Kay Schluehr

Posts: 302
Nickname: schluehk
Registered: Jan, 2005

Re: Beautiful Code in the Real World - Part I Posted: Aug 13, 2007 5:08 PM
Reply to this message Reply
I read stuff from a database, do something trivial to it and then I generate some reports.

Sentences like this indicate that the programmer still has a positive identification potential with the program he writes. Otherwise he would say:

The program reads stuff from a database, does something trivial to it and then it generates some reports.

Note the change in perspective which is usually just applied when the evil program goes wrong and the I + program unity dissociates.

But keep it positive and assume that once the program does all the stuff and the meta-program contains the configuration / adaption instructions the man in the orange vest can garden the flowers on the wayside most of his time. That's why Paul Graham is right. A "great hacker" is by definition a person that rather prefers doing a different job than working with tools that won't bring him to his limits. And he will do different things along his daily work anyway - not necessarily gardening but maybe researching?

Flat View: This topic has 13 replies on 1 page
Topic: Beautiful Code in the Real World - Part I Previous Topic   Next Topic Topic: I Need Smart RSS


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us