IssueRaiser

The `final` keyword is too long

It's inconvenient that declaring final variables require more typing than non-final variables. This discourages the use of final variables. Even with inferred types, it's shorter, and if you want to specify the type, it gets even longer: ```dart var foo = ...; String foo = ...; final foo = ...; final String foo = ...; ``` While final variables are not strictly necessary (if you don't assign to a variable, it doesn't matter semantically whether it's declared final or not), some people prefer a style where you make variables final unless they need to be mutable, and Dart does not support that writing style very well. See #135 for one suggestion which improves the experience for inferred variables by replacing `final` with `val`. It doesn't improve the typed case. It requires adding a new built-in identifier (but likely not a reserved word). Another option could be using `:=` for final initialization (since final local variables need to be initialized): ```dart: foo := ...; String foo := ...; ``` This doesn't work for instance variables since they may be intialized by a constructor, or parameters, and to keep requiring the `final` word for instance variables and parameters, and using `:=` everywhere else, is inconsistent.

Posted by lrhn on Dec 17, 2018, 9:28 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

support (Other)

The `final` keyword is too long

lrhnDec 17, 2018, 9:28 AM

It's inconvenient that declaring final variables require more typing than non-final variables. This discourages the use of final variables. Even with inferred types, it's shorter, and if you want to specify the type, it gets even longer: ```dart var foo = ...; String foo = ...; final foo = ...; final String foo = ...; ``` While final variables are not strictly necessary (if you don't assign to a variable, it doesn't matter semantically whether it's declared final or not), some people prefer a style where you make variables final unless they need to be mutable, and Dart does not support that writing style very well. See #135 for one suggestion which improves the experience for inferred variables by replacing `final` with `val`. It doesn't improve the typed case. It requires adding a new built-in identifier (but likely not a reserved word). Another option could be using `:=` for final initialization (since final local variables need to be initialized): ```dart: foo := ...; String foo := ...; ``` This doesn't work for instance variables since they may be intialized by a constructor, or parameters, and to keep requiring the `final` word for instance variables and parameters, and using `:=` everywhere else, is inconsistent.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue