Meaningful colour

2023-02-19

I have never heard anyone say, “My favorite color is brown”. But neutral colors like brown are clearly important. Much of the world is muted in color with only punctuations of intensity. Ashley Hurst

A lot has been written on semantic colouring, and how to convey meaning into colours. Hurst's observation reminds us that nature is already pretty readable colour-wise, with most things bearing a "don't mind me" signal. Or, to put it another way, our brains are already pre-processing the colour's added information, and human constructions use it for a long time. It seems probable that red tiles are so common because they warn people about the danger of a steep, fragile zone to step on.

Colour names in languages

In the 1969 book Basic Color Terms, Brent Berlin and Paul Kay Someone observe that languages acquire colour terms in a common pattern :

  1. initially all languages contain terms for black (cool colours) and white (bright colours).
  2. if a language contains three terms, then it contains a term for red.
  3. if a language contains four terms, then it contains a term for either green or yellow (but not both).
  4. if a language contains five terms, then it contains terms for both green and yellow.
  5. if a language contains six terms, then it contains a term for blue.
  6. if a language contains seven terms, then it contains a term for brown.
  7. if a language contains eight or more terms, then it contains terms for purple, pink, orange or gray.

These observations lead universalists to claim that we all perceive a similar signal that conveys color, so that the concept behind "red" is available in all languages. Muyueh Lee authored a beautiful presentation on colour names' frequency across languages, that illustrates some of these analogies.


John A. Lucy notably objected that Berlin & Kay silently assume that "speech is about labelling accuracy", a cultural bias he attributes to the way English speakers think about their language.

Also, like many others, Berlin & Kay suppose that languages acquire more and more colours over time. If I'm correct, Lucy says it's because they assumed the existence of an absolute progress.

I actually found most of these informations on a Stack Overflow answer about ANSI colours. There was so much progress in colour implementations since 1970 that we are left with several overlapping console colouring systems. Which brings us to our main subject :

Code highlighting

Code published on the web is mostly colour-highlighted nowadays, so much that plain code feels harder to read. Even so, some like Linus Åkesson blame syntactic highlighting (the underlying process) for keeping readers away from the semantic level - the code's more elaborate meaning, as opposed to syntax.

Some others defend the idea of semantic colouring : each variable should have its colour, with different grouping tactics. Evan Brooks gave semantic highlighting examples in 2014. Those didn't convince me though ; I still find them hard to read.

A proposition

This site proposes code highlightings that push coders' variables up, and the language's keywords down. It also insists on comments, as proposed by Jim Fisher. See the following example, extracted from the Rosetta code project : variables are in white, keywords are greyed out, docs are cyan and constants are green. The only fancy colour is magenta for the modifiers (not illustrated here).

import urllib.request

from collections import defaultdict

words = urllib.request.urlopen(
    'http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'
).read().split()

# Map sorted chars to anagrams :
anagram = defaultdict(list)
for word in words:
    anagram[tuple(sorted(word))].append( word )

count = max(len(ana) for ana in anagram.values())
for ana in anagram.values():
    if len(ana) >= count:
        print ([x.decode() for x in ana])

Compare that to Github's default :

Github highlighting on some python code
I made a Vim highlighting theme that shows out in a same manner. It's now my daily theme and I fell that code doesn't yell grammar at me anymore. Get it !