Hacker News new | comments | show | ask | jobs | submit login
Ask HN: Looking for examples of "really great code"?
14 points by andrewstuart 1994 days ago | hide | past | web | favorite | 21 comments
Is there any code that is "widely accepted" as being "really great code"?

I would like to use this in a research exercise.

The context is that many companies wish to "examine your code" as part of their recruitment process.

I believe that "examining code" is an extremely poor way of evaluating someone, and that the results of such assessments are extremely subjective and ultimately meaningless.

One of the most effective ways to prove this is to take some code that is widely regarded as being "really great code" and ask various people how they would rate the programmer based on that code. My prediction is that many people will assess this code to be of poor quality.

In an ideal world I'd like to find "generally accepted" "really great code" in a variety of languages, but even one example would be a starting point.

Specifically it would be good to find some of Bill Joy's original TCP/IP implementation code. This unfortunately will only be of limited value however as it's not going to be object oriented, and OO is something that all employers look for these days.

EDIT CLARIFICATION: I'm looking for code that can be specifcally attributed to one individual programmer.

For example it would be good to identify code that is written purely by John Resig, or code that is written purely by James Gosling. I need to be able to attribute all of that code purely to one individual programmer.

http://doom.wikia.com/wiki/Doom_source_code (john carmack et al - you may be able to find which parts carmack wrote from articles or code comments; apparently there's a commit log too)

I believe the point of examining code is usually to eliminate "really crappy code", it's not to determine "really great code". The code sample is usually a qualifying factor, not a determining one.

People may disagree on what constitutes great code, but most people reasonably skilled in the art can agree on when code is crappy.

I don't agree. My assertion is that person X might think a code sample is crappy, but person Y will not think it is crappy code.

I am expecting this is especially the case where the person assessing the code does not understand what the code does (i.e. a "lesser" programmer assessing the work of a "greater" programmer)

Your original assertion was that person X might think a code sample is good, but person Y will not think it is good. Those are two different assertions - you need to test them independently if you want to draw conclusions.

I wouldn't be terribly surprised if "lesser" programmers cannot recognize good code - that's just Dunning-Kruger. That was why I suggested looking for crappy code instead - more people can recognize crappy code, because more people are beyond that skill level. If you ask for samples of good code and your replies all differ in their assessments, you don't know whether that's because "good" code is intrinsically hard to recognize, or because all your respondents were crappy programmers.

'Good code' is more of common sense than personal preference. Maybe you should have a look at one of the cited examples ;)

Interesting thought. This is the heart of my argument. "Good code is common sense" makes me wonder where is the science in deciding if code is good or not.

When deciding if code is good or not, surely there should be quantified criteria for assessment. Code cannot be judged to be "good" or "not good" without specific pre defined measures of assessment. I would suggest that close to 0% of employers that want to "see your code" are assessing against pre defined assessment criteria.

Well, scientific metrics of code quality may be more related to software design than the code craftsmanship itself.

A good experience would be get 4 experienced developers to read and evaluate a piece of code; that'd raise some interesting practical aspects of their evaluation of its goodness.

All great examples but I'm trying to find code that can be definitively attributed to one single person.

The source code for the Tarsnap client (https://www.tarsnap.com/download.html) is some of the best-written C I have ever seen. As far as I can tell it was 100% authored by cperciva.

What makes you think it is good code? Specifically.

I was curious so I took a quick look. Good indicators are:

1. Most of the code is error checking/handling. This isn't necessarily a good indicator in general, but for C code it is.

2. Consistent style.

3. Functions are static unless otherwise needed.

2 and 3 seem minor, but in my experience, 2 is indicative of someone who pays attention to details and 3 suggests that the person is an experienced C coder.

Mongrel[1] has mostly code written by Zed Shaw, I like his style! Very consistent.

    [1]: https://github.com/mongrel/mongrel

I'm certainly no expert, and it's not OO but I've always enjoyed reading the code of some of the coreutils.

Qt source code

Have you checked Linux kernel by Linus Torvalds ?

I'm looking for code that can be definitely attributed entirely to a single developer. I'm pretty sure Linus is not the only developer of that code. Also it's C, whereas most companies these days are looking for OO coding so C is somewhat less relevant for my specific purpose in this exercise.

"I'm pretty sure Linus is not the only developer of that code."

At 14,998,651 lines of code as of 3.2[1], I'd sure as hell hope not!

[1] http://www.h-online.com/open/features/What-s-new-in-Linux-3-...

Why not just go to github and explore the most popular projects? As an experienced programmer you can tell if it's good code or bad code. In JavaScript is even more clear, since there are lots of DONT'S, you know, `eval`, `==`, `with`, etc...

I'm trying to find code that is widely accepted as being great code. The popularity of a project is not as effective ass attribution to a specific well known developer.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact