You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the convention since at least 3 years and used consequently since then as far as I know.
The mentioned changes are only for older code that doesn't yet follow the convention.
What's the value of having a different style for constants? Uppercase is cumbersome to write and to read.
In this case clearly all the others are wrong ;-)
This is indeed done entirely to follow the Dart style guide. All future Dart code will use lowerCamelCase for constants, so we take this one opportunity to get the platform libraries into line. It is a breaking change, so we need to do it as soon as possible.
What is first code or style guide? pi in lowercase - what a ... A style guide should define best practice and not it's own universe!!!!
@zoechi Sure it's true that uppercase is a bit harder to write but code should be documentation. Uppercase tells everyone that this is not a var but a const value. Without this convention we loose part of our documentation.
BTW Google is not always right with their styleguides - C++ for example is very Google centric and in many cases outdated.
The style guide states that constants have to be lowerCase.
This choice is definitely not uncontroversial, but the choice of how constants should be written was done a long time ago, and is unlikely to change now.
The Dart libraries are simply following the guide now, which makes code look more consistent.
@MikeMitterer the difference between final and const is quite weak in Dart.
If you want to create an immutable field that would be const in other languages, you can't do that in Dart if the class doesn't provide a const constructor.
Therefore such a strong differentiation with UPPERCASE doesn't carry its weight in Dart.
If we would do that, we probably should also introduce a new style for finals.
Constant names use UPPER_SNAKE_CASE: all uppercase letters, with words separated by underscores. But what is a constant, exactly?
Constants are val properties with no custom get function, whose contents are deeply immutable, and whose functions have no detectable side-effects. This includes immutable types and immutable collections of immutable types as well as scalars and string if marked as const.
@zoechi First of all - is it really "We"? Second it's not necessary to tell me how to write var/const/final names!
Activity
zoechi commentedon Oct 29, 2017
This is the convention since at least 3 years and used consequently since then as far as I know.
The mentioned changes are only for older code that doesn't yet follow the convention.
What's the value of having a different style for constants? Uppercase is cumbersome to write and to read.
In this case clearly all the others are wrong ;-)
lrhn commentedon Oct 30, 2017
This is indeed done entirely to follow the Dart style guide. All future Dart code will use lowerCamelCase for constants, so we take this one opportunity to get the platform libraries into line. It is a breaking change, so we need to do it as soon as possible.
MikeMitterer commentedon Oct 30, 2017
What is first code or style guide? pi in lowercase - what a ... A style guide should define best practice and not it's own universe!!!!
@zoechi Sure it's true that uppercase is a bit harder to write but code should be documentation. Uppercase tells everyone that this is not a var but a const value. Without this convention we loose part of our documentation.
BTW Google is not always right with their styleguides - C++ for example is very Google centric and in many cases outdated.
floitschG commentedon Oct 30, 2017
The style guide states that constants have to be lowerCase.
This choice is definitely not uncontroversial, but the choice of how constants should be written was done a long time ago, and is unlikely to change now.
The Dart libraries are simply following the guide now, which makes code look more consistent.
zoechi commentedon Oct 30, 2017
@MikeMitterer the difference between
final
andconst
is quite weak in Dart.If you want to create an immutable field that would be const in other languages, you can't do that in Dart if the class doesn't provide a const constructor.
Therefore such a strong differentiation with UPPERCASE doesn't carry its weight in Dart.
If we would do that, we probably should also introduce a new style for finals.
We could introduce MiXeDcAsE for final fields ;p
MikeMitterer commentedon Nov 2, 2017
Just found this in Kotlin style guide for Android:
https://android.github.io/kotlin-guides/style.html
Constant names
Constant names use UPPER_SNAKE_CASE: all uppercase letters, with words separated by underscores. But what is a constant, exactly?
Constants are val properties with no custom get function, whose contents are deeply immutable, and whose functions have no detectable side-effects. This includes immutable types and immutable collections of immutable types as well as scalars and string if marked as const.
@zoechi First of all - is it really "We"? Second it's not necessary to tell me how to write var/const/final names!
mleonhard commentedon Oct 28, 2021
Related: #58508