本日は
Nim の変数名スタイルのお話です.Nim IN ACTION 本を買ってみました.
Nimのスタイルは
から引用すると
Type identifiers should be in PascalCase. All other identifiers should be in camelCase with the exception of constants which may use PascalCase but are not required to.
となっています.つまり下のコードの通りです.
# Constants can start with either a lower case or upper case letter.
const aConstant = 42
const FooBar = 4.2
var aVariable = "Meep" # Variables must start with a lowercase letter.
# Types must start with an uppercase letter.
type
FooBar = object
Identifiers in Nim are style insensitive
そして Nim IN ACTION に記述されていたことなのですが,
camelCaseとsnake_caseの書き方,例えば,
aVariable
と a_variable
が同一視されるようです.
when isMainmodule:
var myString : string = "Hello"
echo my_string
my_string
が定義されていないとコンパイラから怒られそうですが,実は通ります.
echo my_string==myString
の実行結果は true
になります.
でも基本的には camelCase スタイルが勧められています.ナンジャラホイ.将来的にスタイルが変わるかもしれないことを見越しての設計なのかもしれないですね・
そして
when isMainmodule:
var 変数 : string="文字"
echo 変数
と日本語を変数名としても使えるようです.確かPython3もできましたね.