The Artima Developer Community
Sponsored Link

Weblogs Forum
What is good code?

35 replies on 3 pages. Most recent reply: Mar 30, 2005 11:09 PM by Scott Bockelman

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 35 replies on 3 pages [ « | 1 2 3 | » ]
Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Re: What is good code? Posted: Feb 28, 2005 6:43 PM
Reply to this message Reply
Advertisement
Good code is code that's tuned to today and poised to strike at tomorrow.

Kirk Knoernschild

Posts: 46
Nickname: kirkk
Registered: Feb, 2004

Re: What is good code? Posted: Feb 28, 2005 10:22 PM
Reply to this message Reply
>>Now, the end-user quality is supreme. The developer/tester
>>quality is relevant only if it adds to the end-user quality
>>or to other values relevant to end-users

I agree with most of what you say. End user perception is always what's most important. If I deliver poorly structured code, but it meets their needs, the user is happy...temporarily. If I deliver beautifully designed code that performs poorly and doesn't meet their needs, the user is unhappy. However, there is certainly a direct relationship between well-written code and a product that meets a user's need.

Early in my career, I always felt that I had to hit the date, at all costs. This typically meant sacrificing quality of the code. I wasn't often late, and always managed to get it working. Oddly enough, after maintaining the crap that I delivered, I quickly found that I wasn't writing code that could adapt. It was too rigid. As time passed, changes became more difficult. The software was rotting. Eventually, the maintenance teams would grow in size to equal the original development team. Then, it was time to rewrite the software. This was a wonderful, though expensive, learning experience.

Everyone should have the opportunity to live with the code they write until the application dies.

>>I propose a different view of the list that you are
>>suggesting (which is too flat in my opinion).

I'd certainly be interested in your list if you wanted to share it.

Kirk Knoernschild

Posts: 46
Nickname: kirkk
Registered: Feb, 2004

Re: What is good code? Posted: Feb 28, 2005 10:29 PM
Reply to this message Reply
>>Good code should address the following issues with roughly
>>the following priority:
>>1. It should be very high in business value.
>>2. Test coverage should be near 100%
>>3. It should be simple.
>>4. It should have as little duplication as possible.
>>5. It should be expressive.

This is pretty close to the original list. And I suspect if we analyzed it for a while, we'd likely arrive at a common conclusion. The basic premise upon which I derived my original list is this:
I have to give my customer what s/he wants today. Then, I must be able to keep giving my customer s/he asks for tomorrow.

Dan Perl

Posts: 28
Nickname: nanov
Registered: Sep, 2004

Re: What is good code? Posted: Feb 28, 2005 11:39 PM
Reply to this message Reply
> >>I propose a different view of the list that you are
> >>suggesting (which is too flat in my opinion).
>
> I'd certainly be interested in your list if you wanted to
> share it.

My point was with the way you were presenting your list as a flat list where all the items are at the same level. Items in your own list are qualities required by the end user and other items are qualities for developers and testers. I think these constitute two different levels.

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: What is good code? Posted: Mar 1, 2005 5:35 AM
Reply to this message Reply
> 1. It should be very high in business value.
> 2. Test coverage should be near 100%
> 3. It should be simple.
> 4. It should have as little duplication as possible.
> 5. It should be expressive.

Thant is a good set of general principles.

Vince.

Nicolas Nombela

Posts: 17
Nickname: nnombela
Registered: Feb, 2005

Re: What is good code? Posted: Mar 1, 2005 7:15 AM
Reply to this message Reply
> > I almost agree, but I would say:
> >
> > primary goals:
> >
> > * Easy to read, understand and use
> > * Easy to change/modify
> > * Simple as posible
>
> A small but significant oversight is: "does what it
> should" or something comparable. Consider the program:
>
>
> int main() {
>   return 0;
> }
> 

>
> This clearly satisfies your primary goals for every single
> possible set of software requirements. ;-)


I deliberately push "does what it should" as a secondary goal, why? I prefer code that does not do what it should but it is easy to understand and change, than code that not fully does what it should, but you can not find out what it does, and It is a hell to change (and pardon my bad english)

By the way, for some very bad code that I had to work with. the code that you mention: int main() { return 0; }

was the best start I could think of :-)

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: What is good code? Posted: Mar 1, 2005 8:19 AM
Reply to this message Reply
> Good code is code that's tuned to today and poised to
> strike at tomorrow.

Does that mean that as well as being designed for today it is also designed for the future? If the code really is tuned for today, stop.

Dan Perl

Posts: 28
Nickname: nanov
Registered: Sep, 2004

Re: What is good code? Posted: Mar 1, 2005 8:25 AM
Reply to this message Reply
> I deliberately push "does what it should" as a secondary
> goal, why? I prefer code that does not do what it should
> but it is easy to understand and change, than code that
> not fully does what it should, but you can not find out
> what it does, and It is a hell to change (and pardon my
> bad english)

We all like better writing code that is elegant and crafty (one way of defining good code). That is the real motivation for many (if not most) of us. That is my motivation. And that is what makes the open-source community so strong. People who develop software for a business (satisfying the needs of the business) go home and develop software for their own satisfaction.

However, even if our true motivation is elegant, "quality" code, the quality of the code that we develop for a business should be driven mainly by value for the customer. Let's say a customer asks for some piece of software to be delivered in one day and it takes you three days to deliver "quality" code. You may explain to your customer that code delivered in one day is going to be more expensive in the long term, but if the customer still insists one the one day delivery then that's what you do and only then, at the end of the day, did you do your job. That is your professional responsibility. You may go home and write software for an open source project or you may start looking for another job that will be more satisfying to you, but that is what you have to do for the job you have today. And, after all, you may even get some satisfaction from satisfying a customer.

Yes, we are surounded by crappy software. But let's not forget that it has been our choice as customers too, because we always want it cheap and today. We all like gourmet food too, but it's McDonald's that is the big business.

Bill Venners

Posts: 2244
Nickname: bv
Registered: Jan, 2002

Re: What is good code? Posted: Mar 1, 2005 1:32 PM
Reply to this message Reply
Thanks for all the thoughtful comments. I just had one thing to add. I think maybe we've been talking past each other a bit when talking about quality, because we have different ideas of what quality means, so it is good to ask the question what does it mean.

I think there's an aspect of code/design quality that is universal, that cuts across all the projects you work on. Minimizing coupling, maximizing cohesion would fall in that universal category. I have a seminar I teach, most often with Bruce Eckel, in which I try and draw a picture of that universal quality. All of my examples are Java, and it is in many ways specific to Java. So maybe I should say it is universal Java quality. The handouts are here, and they would be my long answer to your question of what quality code looks like:

http://www.artima.com/javaseminars/JavaDesWkshp/index.html

The material is broken up into guidelines, like the organization of Effective C++ or Effective Java. The way I do this seminar is I present a guideline, support it a bit with examples, then open up the floor for discussion. I try to get people talking to each other, because I think that's where the best education comes from. I am trying to do the same thing here in these forums, and I usually learn something myself by following the discussion here.

My first guideline, Guideline Zero, says:

"Every guideline presented in this seminar should be ignored some of the time, including this one."

The reason that's true is because, as Ken Arnold put it, "All designs take place in context." The non-universal aspect of good design is that which depends on the context, the particular thing you're trying to solve. The best I can come up with here is that what seems to help most in both knowing what to design, and recognizing good design, is experience in that domain. As others have put it, if it solves today's problems and faciliates you in solving tomorrow's problem, it is a good design. The trouble with that definition is that although it may help me recognize good design, it doesn't really help me figure out how to create a good design. So although it isn't that satisfying, it is the best way I know how to describe quality at this point. And the best way I know how to get there is having domain experience.

Ken Arnold discussed this topic here:

http://www.artima.com/intv/perfect.html

Robert C. Martin

Posts: 111
Nickname: unclebob
Registered: Apr, 2003

Re: What is good code? Posted: Mar 1, 2005 3:17 PM
Reply to this message Reply
> Comedy? A mediocre programmer trying their best
> produces code that is as good as it can be.

No, tautology. (Or oxymoron, depending on which view you take)

My definition of a mediocre programmer is one who does not try his/her best.

Robert C. Martin

Posts: 111
Nickname: unclebob
Registered: Apr, 2003

Re: What is good code? Posted: Mar 1, 2005 3:26 PM
Reply to this message Reply
> However, I think that is the
> truth and I think statements saying that there should be
> absolutely no compromise in quality are just as
> dangerous. Everything in life is made of compromises and
> trade-offs. And finding the right balance, the right
> compromises and the right trade-offs are a very important
> part of our profession.

In other words: There should be absolutely no compromise in finding the right balance and tradeoffs.

(Sorry, couldn't resist. ;-)

I understand your intent; but I disagree with your statement. When I was young I believed in absolutes. Shades of grey were dishonorable in my world-view. As I grew older I realized that compromise was everywhere and necessary. As I grew even older I realized that there were some things that must not be compromised. Honor and professionalism in the practice of software craftsmanship is one of them.

This does not mean that we don't adapt to business and schedule needs. Of course we do. However, we do not adapt our professional values at the same time. Those values remain constant despite business and schedule pressure.

Those values ensure that I produce the best product I can, in the shortest time possible. Any deviation of those values can only serve to slow me down and degrade my output.

Kent Schnaith

Posts: 3
Nickname: windchill
Registered: Mar, 2004

Re: What is good code? Posted: Mar 1, 2005 3:35 PM
Reply to this message Reply
Do the right things all of the time.

Coach Lombardi used to yell at players if he caught them slacking off in practice, or when the outcome of the game was already determined.

"Winning is not a sometime thing: it's an all the time thing. You don't win once in a while; you don't do the right thing once in a while; you do them right all the time. Winning is a habit. Unfortunately, so is losing." - Coach Vince Lombardi

Isaac Gouy

Posts: 527
Nickname: igouy
Registered: Jul, 2003

Re: What is good code? Posted: Mar 1, 2005 5:18 PM
Reply to this message Reply
> > Comedy? A mediocre programmer trying their best
> > produces code that is as good as it can be.
>
> No, tautology. (Or oxymoron, depending on which view you
> take)

Or simple contradiction, depending how we re-define the words - which is what makes it seem like comedy :-)


> My definition of a mediocre programmer is one who does not
> try his/her best.

Would you consider someone to be a mediocre programmer, when they never tried their best and yet others agreed that the code produced was of the highest quality?

Would you consider someone to be a mediocre programmer, when they always tried their best and yet never managed to produce code that would compile?

Kirk Knoernschild

Posts: 46
Nickname: kirkk
Registered: Feb, 2004

Re: What is good code? Posted: Mar 1, 2005 8:56 PM
Reply to this message Reply
>>Would you consider someone to be a mediocre programmer, when
>>they never tried their best and yet others agreed that the
>>code produced was of the highest quality?

>>Would you consider someone to be a mediocre programmer, when
>>they always tried their best and yet never managed to
>>produce code that would compile?

I know which one I'd rather work with. Eventually, the guy trying harder will surpass the one who isn't putting forth the effort.

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: What is good code? Posted: Mar 2, 2005 5:32 AM
Reply to this message Reply
> Eventually, the guy
> trying harder will surpass the one who isn't putting forth
> the effort.

Maybe, maybe not. And it could take years and still not happen. What do you do in the meantime?. Maybe the other guy just needs encouragement, or recognition, or thanks? Maybe they'd rather be writing Python but the current project is Java? Who knows?

In short, if you have people who aren't pulling to their full ability then you (or whoever's managing them) should be finding out why, rather than writing them off. But that's a whole new thread.

V.

Flat View: This topic has 35 replies on 3 pages [ « | 1  2  3 | » ]
Topic: The Vanishing Middle Previous Topic   Next Topic Topic: Hygenic versus Unhygenic macros in Heron


Sponsored Links



Google
  Web Artima.com   

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