-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
The unnecessary_final
lint contains a controversial explanation of its rationale.
Specifically:
var is shorter, and final does not change the meaning of the code.
The historical context is here: dart-archive/linter#1827
While there are clearly divergent preferences around the use of final
, it does change the meaning of the code (as the prefer_final_locals
lint explains). And while var
is shorter by two characters, that seems like a poor rationale for a lint. Readability is preferred over terseness, anyway.
Lastly, Effective Dart has settled case law on the subject:
State that is not mutable—that does not change over time—is easier for programmers to reason about. Classes and libraries that minimize the amount of mutable state they work with tend to be easier to maintain. Of course, it is often useful to have mutable data. But, if you don’t need it, your default should be to make fields and top-level variables final when you can.
While we don't need to remove the rule, we should have explanatory text that is more accurate. For example, "some people prefer the simplicity of using var
for all variables."