Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why val declaration doesn't follow scala constants naming convention?

In Scala val is used for creating constants and the naming convention for Scala Constants is to use UpperCamelCase convention. (https://docs.scala-lang.org/style/naming-conventions.html#constants-values-variable-and-methods)

A generalization for this rule should be all vals should be in UpperCamelCase.

i.e. if a variable is declared using val keyword its name should be in UpperCamelCase. However I see examples on Scala's website exploiting this rule.

What am I missing here?

like image 570
Rajat Sharma Avatar asked Dec 23 '25 00:12

Rajat Sharma


1 Answers

Put simply:

A constant only has one value while the program is running. It is either fixed at compile time, e.g. Pi, HoursInDay, or is an immutable value inside a top-level object.

A val is an immutable variable. It cannot be changed once it is set, but it may be set to different values each time the containing code is called.

like image 165
Tim Avatar answered Dec 24 '25 14:12

Tim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!