go - What does lexical file name order mean? -
in package initialization part of go specification, "lexical file name order" mean?
to ensure reproducible initialization behavior, build systems encouraged present multiple files belonging same package in lexical file name order compiler.
from wikipedia:
lexical order generalization of way alphabetical order of words based on alphabetical order of component letters.
in practice means files names compared strings, using character codes decide order. order of character codes of english alphabet follow natural order of letters, character code order important if non-letters part of file name (e.g. digits , other characters '-'
).
this convention define (arbitrary) order of source files if package contains multiple source files, order remains same if package recompiled (and of course files not renamed).
the purpose source files processed in same order, , therefore package init()
functions executed in same order, , observe same behavior. order of package init()
functions not matter, there may cases when does. following lexical file name order convention, can rely on (fixed) execution order of init()
functions.
Comments
Post a Comment