Cambridge Comma
Home Up MPLAB GIT Rebase Cambridge Comma GIT and CPS

 

The Cambridge Comma

A Web search for "cambridge comma" currently returns references to an April fool's day joke, however in computing the term should refer to an additional redundant comma after the last item in a list!

Comma delimited lists cause an irritating problem in revision control because they tend to make the last entry in the list special

Consider the following sample:

{
  Item 1,
  Item 2,
  Item 3,
  Item 4
}	

See how Item 4 is not interchangeable with the others. Now lets say I extend the list to:

{
  Item 1,
  Item 2,
  Item 3,
  Item 4,
  Item 5
}	

In order to add a line I have had to alter the previous line.

This is a problem in revision control as it means the change takes place over more than the minimum number of lines.

If an additional trailing comma is added the problem goes away

{
  Item 1,
  Item 2,
  Item 3,
  Item 4,
  Item 5,
}	

We can now add, delete and re-arrange the lines without regard to their position in the list.

While this may seem like a trivial matter when editing manually this can be an enormous help when using revision control, especially when combined with machine-generated file formats where the user does not control the order the list elements appear in. JSON is an egregious offender.

Where a trailing "Cambridge" comma is expressly disallowed a dummy end record may be added to the same effect.

 

Home Up MPLAB GIT Rebase Cambridge Comma GIT and CPS