site-www
site-www copied to clipboard
Improve Lang-tour const constructors explanation
There was a doubt in this repo's Gitter about const constructors. @zoechi answered very well here:
a const constructor has constraints, like it can't have a body. A class can have const constructors and non-const constructors. Only const constructors can be used to create constant values. You still can have runtime-created instances of the same class, for example if parameter values can't be provided as constants.
It would be nice to have that answer included in https://www.dartlang.org/guides/language/language-tour#using-constructors
It could make sense to point out how const can be used and what the benefits are.
In that discussion we figured out, that you can use const at constructors, but maybe there are more ways to use const differently in dart, which is worth to take a deep look, or better explanation.
See also
- https://stackoverflow.com/questions/21744677/how-does-the-const-constructor-actually-work
- https://stackoverflow.com/questions/12418819/why-does-dart-have-compile-time-constants
cc @kwalrath
I'm going to close this in favor of https://github.com/dart-lang/site-www/issues/4350 to consolidate issues related to const
in the language tour. Thanks!