2011-03-23

The Four Duties of Coding



"Concision," a noun form of the adjective "concise" makes for a handy one-word summary of what we are seeking in the artifacts we produce from our work as software developers. Lets look at a definition of concise:

giving a lot of information clearly and in a few words; brief but comprehensive.
(from Mac OS X Leopard Dictionary.app)

That sounds great, but what does it really mean, in real-world application to our work?

The "four C's" of coding are all aimed at making your code concise. They are, in priority order:


  1. Correct
  2. Complete
  3. Clear
  4. Compact


The gold standard for code is to meet all four of these simultaneously, but we would not be doing engineering if there were not trade-offs, at least at intermediate points along the way in development if not in the final product.

The First Duty is to write code that is Correct. That can mean meeting a specification for semantics or for performance or for robustness in the face of bad inputs. Of course, the way to achieve Correct code could include a mix of refining the specification where it is ambiguous, negotiating requirements to make them more amenable to implementation, and of course the particulars of the approach and implementation. These same four C's could equally be applied to the specification as to the code that is produced in response to it.

The Second Duty is to write code that is Complete. In a way, this is an extension of the dictum to write Correct code, since if the code is incomplete, it cannot be correct, but the distinction is we should strive to write smaller bits of correct code with higher priority, and fill in and integrate it into a larger whole to achieve completeness as a secondary objective. Well-constructed code should be composable into a larger whole to achieve a well-constructed whole.

The Third Duty is to write code that is Clear. Code is written by one human to tell other humans across space and time what it is intended that a computer should do. Code should be written in a way that respects its nature as a write-once, read-many (and possibly modify-many) artifact. As long as Correctness and Completeness have been achieved, one should strive for code that is as clear as possible within those constraints.

The Fourth Duty is to write code that is Compact. If there are multiple representations that satisfy the first three Duties with equal or nearly equal success, then selecting for the representation that is more Compact will help keep incidental complexity as low as possible. Just as Complete can be thought of as subsumed within Correct, Compact can be thought of as subsumed within Clear, but is called out separately precisely to assert that its priority is strictly lower than overall Clearness. Do not optimize for compactness at the expense of clarity.


2009-09-07

mordant

According to Merriam-Webster's Online Dictionary: “biting and caustic in thought, manner, or style : incisive <a mordant wit>”

2009-08-31

milksop

According to Dictionary.com: “a weak or ineffectual person.” According to The Oxford Dictionary of English Etymology: “milksop orig. SOP dipped in milk, (hence) one who is fed on such food, young infant, (transf.) effeminate fellow” Also: milquetoast

2009-08-24

horology

(No, I'm not going to give a hint for this one!) The science of measuring time.

2009-08-17

hondo

According to Wikipedia, “The lariat has a small reinforced loop at one end, called a honda or hondo, through which the rope passes to form a loop.”

2009-08-10

encomium

According to Merriam-Webster's Online Dictionary: “glowing and warmly enthusiastic praise ; also : an expression of this.” Definitely not to be confused with meconium!