What does "canonical" mean?

Sometimes I read a sentence containing the word canonical, but I cannot find appropriate meaning of the word.

For example, in this link:

Returns a canonical representation for the string object.

It's hard for me to find an appropriate definition from Google:

ca·non·i·cal Adjective /kəˈnänikəl/

  1. According to or ordered by canon law
    • the canonical rites of the Roman Church
  2. Included in the list of sacred books officially accepted as genuine
    • the canonical Gospels of the New Testament
  3. Accepted as being accurate and authoritative
    • the canonical method of comparative linguistics
  4. (of an artist or work) Belonging to the literary or artistic canon
    • canonical writers like Jane Austen
  5. According to recognized rules or scientific laws
    • canonical nucleotide sequences
  6. Of or relating to a general rule or standard formula
  7. Of or relating to a cathedral chapter or a member of it

When this word is used by programmers, it is a synonym for "authoritative," "standard," or "official." That's meaning number 3 in the definition you quote.

It implies that there is one best, most official, most standard way to represent the string object and this is it.

For example sometimes things can be represented using a relative link or an absolute link. Relative might be something like ../foo.txt meaning "The file foo.txt in the folder above this one" while absolute is something like \\www.example.com\fileserver\share\foo.txt which can only refer to one file on the Internet. One might say that the latter name is canonical.


In computing, the "canonical" form of something usually means something like "a standardised base form, to which any given variant resolves when you apply any relevant conversions". For example, you could have various paths "$NEILSDIR$\Directory", "$USERPATH$\Neil\Directory", but the canonical form of these might be "C:\Users\Neil\Directory".

Another type of conversion that the word commonly applies to is character encoding.

Unfortunately, I don't think the general dictionary entry you quote gives you so much of a clue in this case as to the technical use.


Of the dictionary meanings given, three of them are very similar:

3. Accepted as being accurate and authoritative
5. According to recognized rules or scientific laws
6. Of or relating to a general rule or standard formula

The first two of these imply reference to an authority or recognized rule, which is usually not the case for a programming usage like canonical representation. The last (definition 6) is the most appropriate: according to a general rule.

For example, strings might be considered equivalent whether in upper case or lower case. For a particular program, the designer might have a rule that all strings are to be stored in upper case. That means that upper case is the canonical representation.