Why can't const be inferred, if we get warnings from Lint to use it? Why, if possible, all classes constructors aren't by default const? This would let our code much more clean.
Asked
Active
Viewed 241 times
0
-
Related: [Dart: Is there a disadvantage to using const constructor?](https://stackoverflow.com/q/57607745/) – jamesdlin Jun 09 '22 at 23:43
1 Answers
0
The main point of using const is not to assist the compiler in optimizations but to protect yourself from mistakes which means it prevents you from inadvertently modifying something you didn't expect to be modified.
Generally it makes it easier to program a when there is too many variables you dont. No need to memorize which one should be modified and which one shouldn't.

Kaleb
- 541
- 2
- 7
-
The Flutter Team has made a great job from turning keyword 'new' optional. This clean our code. But having to use 'const' made the code dirty again. @Kaleb, you said the point is to prevent me from inadvertently changing something. But if it automatically makes 'const', the compiler won't let me modify it. Without me having written 'const' in my code. It infers, by default. That is... By default, everything that CAN be 'const' is 'const'. Why this cannot be done? – sérgio brito Jun 16 '22 at 13:11
-
We dont have to forget that there are variables which updates after initialization. If every thing is const then you cant be able to update any variables and besides computer cant identify which variable is constant for your needs unless you write it – Kaleb Jun 19 '22 at 03:44