Skip to content

Dart 2.0 lib changes / constants lower case #31245

Closed
@MikeMitterer

Description

@MikeMitterer

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

Activity

zoechi

zoechi commented on Oct 29, 2017

@zoechi
Contributor

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

lrhn commented on Oct 30, 2017

@lrhn
Member

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

MikeMitterer commented on Oct 30, 2017

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

added
area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
on Oct 30, 2017
floitschG

floitschG commented on Oct 30, 2017

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

zoechi commented on Oct 30, 2017

@zoechi
Contributor

@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

MikeMitterer commented on Nov 2, 2017

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

mleonhard commented on Oct 28, 2021

@mleonhard

Related: #58508

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @MikeMitterer@zoechi@mleonhard@lrhn@floitschG

        Issue actions

          Dart 2.0 lib changes / constants lower case · Issue #31245 · dart-lang/sdk