Skip to content

Dart 2.0 lib changes / constants lower case #31245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MikeMitterer opened this issue Oct 28, 2017 · 7 comments
Closed

Dart 2.0 lib changes / constants lower case #31245

MikeMitterer opened this issue Oct 28, 2017 · 7 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.

Comments

@MikeMitterer
Copy link

Why????
The whole world uses UPPERCASE for constants why do you plan to break this convention?

@zoechi
Copy link
Contributor

zoechi commented 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
Copy link
Member

lrhn commented 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
Copy link
Author

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 floitschG added the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Oct 30, 2017
@floitschG
Copy link
Contributor

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
Copy link
Contributor

zoechi commented Oct 30, 2017

@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.

We could introduce MiXeDcAsE for final fields ;p

@MikeMitterer
Copy link
Author

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
Copy link

Related: #58508

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
Projects
None yet
Development

No branches or pull requests

5 participants