

Ask YC:  What is "quality" code? - iamelgringo

I've read tons online about an amorphous and elusive goal: quality code.  <p>What is it?  Links code that you consider to be great would be appreciated.  <p>
======
marcus
Just like great art or hot women.

You'll know it when you see it.

~~~
DanielBMarkham
I'll know it when I maintain it.

~~~
neilk
Just like certain hot women.

------
abomb
Quality code is any code written by me. Poor code is any code not written by
me.

me = any developer

:o)

~~~
akkartik
:) There's something to this. When you have to read your own code a lot of it
lingers still, so it's often easier to hold in your head. Importing other
people's code into your head is usually more effort, proportional at least to
project size regardless of how well-written it is.

------
greendestiny
Great code is simple. Simplicity is the cornerstone of all the other
attributes of beautiful code - ease of extension, ease of understanding, often
even efficiency or at least amenability to optimization.

~~~
mojuba
That's possibly the best definition of good code. Simplicity and succinctness
is not only power, it is also beauty.

Besides, good code is inseparable from good architecture, for which
beauty=simplicity applies as well.

------
icky
Quality code is the kind that someone else maintaining it doesn't feel the
urge to rewrite...

~~~
pg
...except because of the language it's written in.

~~~
icky
:)

------
anupamkapoor
couple of salient features: \- easy to maintain \- easy to extend \- obviously
correct \- <this space is for rent>

------
neilk
I think I can boil it down to one sentence:

In quality code, the cost of changing the code grows more slowly than the
benefits.

Everything else flows from this: functionality, readability, clean design,
appropriate technology to problem, appropriate effort spent on problem,
availability of programmers who can work on such a system, management of
legacy features, and foresight of problems and opportunities in the future.
Lame 10-line bash scripts that even repeat a few lines can be quality code.
And so can entire application frameworks coded in C++.

The Agile people might say that the cost should instead be proportional. They
would argue that if extension of the system is too easy, you probably
overspent on the initial quality. But I feel in my bones that this is wrong.
We should really be aiming for a polynomial or exponential ratio of benefits
to cost.

------
iamelgringo
Most of the comments here are in regards to maintainability and conciseness.
There are comments like: quality code is elegant. But saying that code is
"elegant" is the same as "quality".

Can the person who writes the code be the authority on whether it is quality
code? If one of the most important aspects of quality code is how easy it is
to maintain or extend. Shouldn't it follow that code shouldn't be considered
good until it's maintained or extended.

------
hello_moto
Java is not the most loved language around here but check out the Java API.

Some of the books you might want to read:

1) Code Complete (MS Press)

2) Effective Java/C++ (Joshua Bloch/Scott Meyers)

3) Design Patterns

4) Refactoring

I don't know other books/library that can answer this question from other
language (such as LISP, Python and Ruby)

~~~
nostrademons
The Java API's are wildly inconsistent. Some are pretty good, but some
(Calendar, Date, IO) are massive trainwrecks that even some of Java's
architects don't like. Joshua Bloch gave a presentation somewhere on effective
API design where he ragged on Calendar.

And the Design Patterns and Refactoring should be considered starting points,
not the be-all-and-end-all of programming. Every programmer should be familiar
with them just for the vocabulary. But there are better examples of
programming in SICP, _On Lisp_ , _Programming Pearls_ , and _TeX: The
Program_.

~~~
hello_moto
My examples and suggestions are limited for Java/C#. The reason why I pointed
out Java API is such that people can see which part has a good clean code and
which part has inconsistent design.

I'm not currently programming in functional language so I can't really say how
much SICP and On Lisp help people to write better software. To my
understanding, despite the praise of LISP for clean code, the statement mostly
come from experience developers with years of flight-time. I began to question
whether LISP actually helped them much given their extensive experience.

Paul Graham (or insert any bloggers that praised LISP) said LISP helped him
code in a better way (and etc etc etc) but Paul Graham never program in Java
so how do we know if his LISP experience actually help the way he programs in
OOP?

Other experience developers said Scheme helped them to have clean code but
then again, they threw that statement after x-number of projects in which I'm
sure they've learned a lot anyway.

------
boucher
According to my room mate, some of the greatest code ever written:

[http://www.amazon.com/Standard-Template-Library-P-J-
Plauger/...](http://www.amazon.com/Standard-Template-Library-P-J-
Plauger/dp/0134376331/ref=pd_bbs_sr_2?ie=UTF8&s=books&qid=1195793398&sr=8-2)

------
jhrobert
Quality code is code that is worth reading, not just running.

Which leads us to code litterature.

And poetry.

And haiku.

$de&&bug( "Carpe diem")

<http://virteal.com/DebugDarling>

~~~
tel
Aie! Attack of the floaty yinyang troupe!

------
DanielBMarkham
If you're talking nuts and bolts coding, and if you read one book about what
makes quality imperative code, read Code Complete. In my experience, when
people read it, they change the way they program in profound (and good) ways.

<http://www.cc2e.com/>

[http://www.amazon.com/Complete-Microsoft-Programming-
Steve-M...](http://www.amazon.com/Complete-Microsoft-Programming-Steve-
McConnell/dp/1556154844)

------
carpal
Quality code is elegant and concise.

------
amichail
Consider buying these books:

[http://www.amazon.com/Refactoring-Improving-Design-
Existing-...](http://www.amazon.com/Refactoring-Improving-Design-Existing-
Code/dp/0201485672)

[http://www.amazon.com/Design-Patterns-Object-Oriented-
Addiso...](http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-
Wesley-Professional/dp/0201633612)

