4 ms·
Ask YC: What is "quality" code?
I've read tons online about an amorphous and elusive goal: quality code.
What is it? Links code that you consider to be great would be appreciated.
- icky 19y agoQuality code is the kind that someone else maintaining it doesn't feel the urge to rewrite...
- pg 19y ago...except because of the language it's written in.
- icky 19y ago:)
- axod 19y agoIt is a matter of taste and opinion though. We had a programmer at our office who used to use strings for everything. Any datatype, he'd use a string anyway. He thought it made things uniform and easy. So he'd probably feel the urge to rewrite everything. That doesn't mean it's bad code, it just means he has issues :)
- akkartik 19y agoTry rewriting more often :) Rewriting is a form of active reading, and I find active reading helps in comprehending code just like any writing. A lot of the benefits of the whole XP/refactoring movement may come from just this phenomenon, that writing code helps swap a program into one's head more effectively than just reading code.
- amichail 19y agoConsider buying these books: http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672 http://www.amazon.com/Refactoring-Improving-Design-Existing-... http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612 http://www.amazon.com/Design-Patterns-Object-Oriented-Addiso...
- DanielBMarkham 19y agoIf 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.cc2e.com/ http://www.amazon.com/Complete-Microsoft-Programming-Steve-McConnell/dp/1556154844 http://www.amazon.com/Complete-Microsoft-Programming-Steve-M...
- boucher 19y agoAccording to my room mate, some of the greatest code ever written: 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 http://www.amazon.com/Standard-Template-Library-P-J-Plauger/...
- anupamkapoor 19y agocouple of salient features: - easy to maintain - easy to extend - obviously correct - <this space is for rent>
- marcus 19y agoJust like great art or hot women. You'll know it when you see it.
- DanielBMarkham 19y agoI'll know it when I maintain it.
- neilk 19y agoJust like certain hot women.
- samson 19y agoFollowing marcus's lead on this one, I don't presume to know what elegant code is. For me its like watching your favourite athlete in action and striving emulate that in your self. So I find rather then reading books on how to write great code, reading the code of people who have made great programs (when you have the opportunity) is an invaluable way to learn. And alot of fun too!
- greendestiny 19y agoGreat 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 19y agoThat'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.
- jhrobert 19y agoQuality 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 http://virteal.com/DebugDarling
- tel 19y agoAie! Attack of the floaty yinyang troupe!
- carpal 19y agoQuality code is elegant and concise.
- abomb 19y agoQuality code is any code written by me. Poor code is any code not written by me. me = any developer :o)
- akkartik 19y ago:) 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.
- iamelgringo 19y agoMost 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 19y agoJava 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)
- ntoshev 19y agoJava APIs err on the side of overengineering - and it's not the language, it's the culture around it. I do recommend Effective Java and Effective C++ (and its sequels). They show the limitations of the respective languages and how to overcome them.
- nostrademons 19y agoThe 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 19y agoMy 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.
- neilk 19y agoI 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.