What makes good code?

Since I'm in the process of shipping out to an uncaring world my new javascript library, one of the nagging questions I have is "is it good"? In the spirit of second-guessing my own choices I did a quick Google survey of opinion on the subject. I've reduced the stuff I found to bullet points, and highlighted things I think are significant to Bindinator.

Bold red items are where I think Bindinator can be significantly improved.

What makes good code good? A digital social research view

Correct

Also demonstrable and testable.

Well-Designed

Note: I have plans for implementing a simple type system (I don't want to add external dependencies) that serves the dual roles of validating method parameters and interactions with services.

As an aside, one of the problems I perceive with JSON is that it's too tied to Javascript and we should actually further restrict it to not allowing arrays of scalars (i.e. arrays can only be of objects, object properties can be scalars, objects, or arrays), not having both undefined and null, and so on. A few of these restrictions would make dealing with JSON in languages that aren't Javascript less ugly.

Anyway, this restricted subset of JSON would be the basis for my type system, and it would also leverage modern Javascript's syntax sugar for object properties, so a lot of methods could be called like this: foo({bar, baz}) and type-checking in methods would look something like:

Types.verify(arguments, {a: Types.string, b: Types.number, c: Types.number.required, d: Types.number(Math.PI), e: Types.object(…)});

Readable

Notes:

I have plans on implementing a lot of literate programming ideas, but they're mainly ideas for the moment.

Bindinator's naming is decent, but it's a bit inconsistent in use of underscore_word_separation vs camelCase. I like the way Facebook's coding standards insist on underscore separation for internal symbols and camelCase for exported symbols, so I may move further that way.

Appropriate

Robust

Note: I'd like to put more, better runtime checks (at least in debug mode). Right now the philosophy is fail quickly and obviously (i.e. in front of the developer, rather than the end-user), which is a variation of "fail gracefully".

Available

Usable

Copyrighted and Licensed

Under Revision Control

A good coder is like a good pool player

a good coder writes code that looks like it was easy and straightforward to do. Many of the examples by Brian Kernighan in his books follow this pattern. Part of the "trick" is coming up with a proper conceptualization of the problem and its solution. When we don't understand a problem well enough, we're more likely to over-complicate our solutions, and we will fail to see unifying ideas.

How do you know if you're writing good code?

The biggest clue for me is: When you have to go back and add/modify a feature, is it difficult? Do you constantly break existing functionality when making changes?
This seems totally on the money to me, but the problem is, how do you define difficult? I get pretty annoyed if a fairly major feature takes me an evening to implement. Does that mean my code sucks or that I have high standards?

Quality is line one -- 8 Characteristics of Good Software Code

  1. It works
  2. It's easy to read
  3. It's testable
  4. It's easy to maintain
  5. It's pleasant to look at
  6. It's easy to change
  7. It's simple
  8. It's efficient
Note: bindinator's code is testable, but it needs a lot more actual tests.

How to you define good code?

From Code Complete: From Paul DiLascia MSDN:

What does a good programmer's code look like?

Notes: I'm constantly striving to write straightforward (and not clever) code, but this is always a danger.

I think some of bindinator's source files are uncomfortably large, and one refactoring I've done requires methods to be assigned to b8r, which — among other things — confuses minifiers, which is almost certainly a bad sign.

What makes code great?

The title reminds me of a pithy quotation whose source and exact wording I forget: "The reason that there are no good American writers is that American writers all want to be great." Anyhow…

Second response to me is the pithiest:

  1. It works. (functionality)
  2. It runs fast. (performance)
  3. It can be maintained by others. (maintainability)
  4. It was written quickly. (cost)
Note: whether this code can be maintained by others remains to be seen.

The writer also points out that it's almost impossible to achieve all this, so the next step is rewriting.

The third response opens thus:

Maintainability is the goal. Great code can easily be maintained by other developers, including the future you.
The top response to me is interesting mostly because I find it bizarre:

— Tonio Loewald,