User:Colby Russell/Static initializers: Difference between revisions

m
rm barbs
(module state)
m (rm barbs)
Line 40:
A use case: in the new lexer, I want to be able to assert that the constants selected for <code>Scanner</code> "enums" don't collide with the constants selected for <code>Token</code>. Even with the convention that <code>Token</code>'s constants are no less than, say, <code>101</code>, it sure would be nice to both communicate the relationship between carefully selected constants to other programmers and getting machine verification at the same time.
 
NB: There are also ordering concerns, similar to those we ran into for <code>extends</code>, based on TC39's (IMO extremely silly and unnecessary) decision to make class hoisting differ from the way function hoisting works. This means we have some difficult choices:
 
# forbid cross-module references for top-level scope (no <code>Scanner.WHITESPACE = Token.WHITESPACE</code>, for example; we could make an exception for where we're already handling ordering issues, such as if <code>A</code> extends <code>B</code>, then <code>A.FOO = B.BAR</code> is permitted, but that seems sketchy)