Skip to content
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

Annoying to have to write double literals for integer values. #3

Closed
lrhn opened this issue Jul 2, 2018 · 2 comments
Closed

Annoying to have to write double literals for integer values. #3

lrhn opened this issue Jul 2, 2018 · 2 comments
Labels
request Requests to resolve a particular developer problem

Comments

@lrhn
Copy link
Member

lrhn commented Jul 2, 2018

In Dart, unlike many other languages, integers and doubles are objects, not "primitive values". There are no special rules converting between the types on assignment (assignment generally preserves the identity of objects).

This can be annoying when you want to write something simple, like:

double x = 10;
foo(double x) => ...;
foo(42);

Here the integer number isn't allowed where a double is expected, so the program fails to compile. You have to write it as 10.0 and 42.0 to get the program compiling. This is annoying, and it feels like needless overhead when the meaning is clear.

I would be nice if you didn't have to write the extra .0, the compiler should be able to figure that out.

Proposed solutions: #4

@lrhn lrhn added the request Requests to resolve a particular developer problem label Jul 2, 2018
@zoechi
Copy link

zoechi commented Jul 2, 2018

That's all over the place in Flutter.

Not sure why they didn't use num instead of double everywhere, but I guess it would cause inefficiencies in sensible places.

@mit-mit
Copy link
Member

mit-mit commented Oct 17, 2018

Closing, this is tracked in implementation issue #20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Requests to resolve a particular developer problem
Projects
None yet
Development

No branches or pull requests

3 participants