词汇文件名顺序是什么意思?
What does lexical file name order mean?
在Go规范的package initialization部分,"lexical file name order"是什么意思?
To ensure reproducible initialization behavior, build systems are
encouraged to present multiple files belonging to the same package in
lexical file name order to a compiler.
来自Wikipedia:
Lexical order is a generalization of the way the alphabetical order of words is based on the alphabetical order of their component letters.
实际上这意味着将文件名作为字符串进行比较,使用字符代码来决定顺序。英文字母的字符代码顺序遵循字母的自然顺序,但如果非字母也是文件名的一部分(例如数字和其他字符,如 '-'
),字符代码顺序很重要。
如果包包含多个源文件,这只是定义源文件(任意)顺序的约定,如果重新编译包(当然文件不会重命名),该顺序将保持不变。
目的是让源文件始终以相同的顺序处理,因此包 init()
函数也将以相同的顺序执行,您将观察到相同的行为。包 init()
函数的顺序通常无关紧要,但也有可能是这样的情况。通过遵循此词法文件名顺序约定,您可以依赖 init()
函数的(固定)执行顺序。
在Go规范的package initialization部分,"lexical file name order"是什么意思?
To ensure reproducible initialization behavior, build systems are encouraged to present multiple files belonging to the same package in lexical file name order to a compiler.
来自Wikipedia:
Lexical order is a generalization of the way the alphabetical order of words is based on the alphabetical order of their component letters.
实际上这意味着将文件名作为字符串进行比较,使用字符代码来决定顺序。英文字母的字符代码顺序遵循字母的自然顺序,但如果非字母也是文件名的一部分(例如数字和其他字符,如 '-'
),字符代码顺序很重要。
如果包包含多个源文件,这只是定义源文件(任意)顺序的约定,如果重新编译包(当然文件不会重命名),该顺序将保持不变。
目的是让源文件始终以相同的顺序处理,因此包 init()
函数也将以相同的顺序执行,您将观察到相同的行为。包 init()
函数的顺序通常无关紧要,但也有可能是这样的情况。通过遵循此词法文件名顺序约定,您可以依赖 init()
函数的(固定)执行顺序。