Naming convention for Scala constants?

grautur picture grautur · Mar 16, 2012 · Viewed 34.4k times · Source

What is the naming convention for Scala constants? A brief search on StackOverflow suggestions uppercase CamelCase (the first line below), but I wanted to double-check.

val ThisIsAConstant = 1.23
val THIS_IS_ANOTHER_CONSTANT = 1.55
val thisIsAThirdConstant = 1.94

Which is recommended Scala style?

Answer

Daniel C. Sobral picture Daniel C. Sobral · Mar 17, 2012

The officially recommended style (and I do mean officially) is the first style, camel case with first letter are upper case. It's laid down clearly by Odersky on Programming in Scala.

The style is also followed by the standard library, and has some support in language semantics: identifiers starting with upper case are treated as constants in pattern matching.

(Section 6.10, p. 107 in the second edition)