Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention for Scala constants?

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?

like image 570
grautur Avatar asked Mar 16 '12 22:03

grautur


People also ask

What is the naming conventions for variables and constants?

The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.)

What is the convention for writing constants?

Constant names are to be written in uppercase with an underscore separating the words. However, they will still compile as long as keywords and spaces are not used even if not written in uppercase with underscore.

What are the naming conventions for variables?

A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign " $ ", or the underscore character " _ ". The convention, however, is to always begin your variable names with a letter, not " $ " or " _ ".


1 Answers

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)

like image 124
Daniel C. Sobral Avatar answered Sep 18 '22 18:09

Daniel C. Sobral