Is Your Code Acceptable?

Posted by Jeremy Voorhis Tue, 02 May 2006 22:10:00 GMT

In his book, Aspects of the Theory of Syntax, Noam Chomsky insists that we make a distinction between language competence and performance. Competence refers to one’s knowledge of a language, while performance refers to one’s ability to practice that language. When discussing language performance, Chomsky introduces the term acceptability. In Chomsky’s words, utterances are acceptable when they are “perfectly natural and immediately comprehensible without paper-and-pencil analysis, and in no way bizarre or outlandish.” Chomsky goes on to describe some structural heuristics for acceptability of the written word. Some things that contribute to the decay of acceptability are repeated nesting of an element, self-embedding of an element and nesting of a long and complex element.

He goes on to suggest that these patterns limit acceptability because they work against the finiteness and decay of human memory. He may not have had programming languages in mind while he wrote this passage, but the same limitations when communicating in English stand when communicating in Ruby or some other programming language.

Simply put, if you are writing software for a human first and a computer second, keep your statements concise and refrain from gratuitous nesting and run-on statements when possible. The interpreter may find your code very acceptable, but you also have a human audience which includes yourself. Look back on some code you have written two weeks ago and ask yourself – is it acceptable?

Comments

  1. Justin Watt said 7 days later:

    Having had an undergraduate background in linguistics, I often muse on this question when working on Perl code versus PHP .

    In Perl it seems to me, all the power is in the syntactic structures, which, though very concise and mentally satisfying to construct, can be challenging to read and really understand.

    Contrast that with PHP which has like several thousand functions in the global namespace (a point which hackles Perl hackers) but which makes the code that much more readable (aka, acceptable, imho).

    Of course then the burden shifts to holding all those function names (and their frustrating inconsistencies) in one’s head, but a few weeks later, a handful of functions are going to be a lot easier to read than <code>$</code>s, <code>@</code>s, <code>#</code>s, etc.

    Ruby, it seems, is taking this to a whole nother level.

  2. Justin Watt said 7 days later:

    Yeah, ignore those <code>s.

  3. random8r said 7 days later:

    You oughta try ruby then ;-)

(leave url/email »)