Search code examples
scalanaming-conventionsidentifier

Why are List and String identifiers named "xs" (in Scala and other languages)?


A lot of sample Scala code contains Strings and Collections named "xs". Why xs?

Examples:

var xs = List(1,2,3)
val xs = "abc"

Solution

  • Basically it's a naming convention that originated in LISP. The rationale behind it is that:

    1. X is a common placeholder name.
    2. XS is pronounced X'es, i.e "many X".