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

Improved syntax for defining new variables #2672

Closed
DartBot opened this issue Apr 21, 2012 · 8 comments
Closed

Improved syntax for defining new variables #2672

DartBot opened this issue Apr 21, 2012 · 8 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Apr 21, 2012

This issue was originally filed by girishrv...@gmail.com


Code like

  Map<int, View> views = new Map<int, View>();

is redundant and require a lot of typing especially when the class names are long. Since people hands are very soft it would be great if this could be shortened as

  views := new Map<int, View>();

Yes. this is just for convenience. But convenience has been a great force in history.

The proposal is only for assignments whose right hand side is a new keyword.

@DartBot
Copy link
Author

DartBot commented Apr 21, 2012

This comment was originally written by is...@google.com


I would look for the type information on the left side of a variable, and this construct is definitely against the conventions of Java / C world...

Btw. you can use the following compact code instead:
 
  Map<int, View> views= {};

@DartBot
Copy link
Author

DartBot commented Apr 22, 2012

This comment was originally written by @seaneagan


Map<int, View> views= {};

I think that should yield a type warning, since it's taken to be the same as:

Map<int, View> views= <String, Dynamic>{};

However, type inference allows you to do:

var views = new Map<int, View>();

@DartBot
Copy link
Author

DartBot commented Apr 22, 2012

This comment was originally written by giri...@gmail.com


@#­1
For maps may be that is a short code. But that doesnt work for an arbitrary object. For eg:

  view := new View();

@#­2
Sorry. I didnt understand your comment. Are you saying that Dart has type inferencing?

But your suggestion seems to solve the problem. Except that after i type

  var views = new Map<int, View>();

i should get code completion after views. in the dart editor. I guess this is not difficult to implement.

@DartBot
Copy link
Author

DartBot commented Apr 22, 2012

This comment was originally written by @seaneagan


Yes, Dart supports type inference by making types optional, and leaving it up to the tools to implement. I believe they have implemented local variable type inference in the analysis engine used by dart editor, but if not, then certainly at some point they will.

@madsager
Copy link
Contributor

Added Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Apr 29, 2012

There is often a degree of redundancy between type annotations on variables and the expressions being assigned to them. To a degree, this is deliberate - that redundancy indicates programmer intent and provides the typechecker with more information so it can detect inconsistencies.

That said, there is always the desire to reduce/eliminate redundancy. One mechanism for this is type inference. Our view is that inference is best supported via tooling rather in the language. This is especially critical in an optionally typed language. For example:

var m = new Map<int, String>();

Has a meaning that is significantly different from

Map<int, String> m = new Map<int, String>;

So we cannot have the language do inference here. Instead, a tool can put in the declaration for you.
Other ways to reduce the inconvenience might be typedefs that make the annotations shorter. More radical ideas are possible as well. We might say introduce typed variables via a different keyword

def m = new Map<int, String>();

and say that in this case, the type of the expression is the type of the variable. But this comes with costs as well - new keywords, two ways of doing things etc. So I don't really like it. I think tooling is the way to go.


Removed Type-Defect label.
Added Type-Enhancement, Accepted labels.

@gbracha
Copy link
Contributor

gbracha commented Apr 29, 2012

Set owner to @gbracha.

@gbracha
Copy link
Contributor

gbracha commented May 24, 2012

Tooling should support this, not the language.


Added WontFix label.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels May 24, 2012
@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed resolution-wont_fix labels Mar 1, 2016
dart-bot pushed a commit that referenced this issue Oct 14, 2020
git log --oneline cf9795f3bb209504c349e20501f0b4b8ae31530c..f0c7771b38155d3829a60d60b5dba2784b100811
f0c7771b Set first version with null safety to 2.12 (#2684)
df1140af Warn from get, when mixed mode (#2590)
765778c0 Simplify test detection (#2682)
afd66ea2 Inline the single test asset. (#2681)
059e4796 Simplify the logic for unicode and colors in output (#2679)
35ddaec2 Dartify test tool (#2680)
62f26401 Example for User-Agent (#2678)
e8b4b114 fixes: #2670 pub global activate commands always exit cmd on windows. (#2671)
93e703b1 Improve stack traces in many tests (#2673)
5b540a39 Fix experiments tests for Dart 2.11 (#2672)
b0ac77d8 Bump dependency on pkg:analyzer (#2662)
73f0906e Removed @alwaysThrows (#2642)
88e0a83c Fixed bug in adding dependency to empty dependencies key (#2640)
135d9fa0 Pub add/remove now remove dependencies key if it makes them empty (#2639)
f4cc9673 Fix "pubpsec" typo (#2641)
4686d74d Adding an existing package is now a dataError (#2638)
1e93f47c Checks pubspec keys for potential typos (#2616)
fa5f51ef Vendor yaml_edit (#2633)
ac6d307f Adding a `pub remove` command (#2620)
9d236e00 Adding the `pub add` command (#2618)
04e237f7 Drop upper bound instead of using "any" while resolving in "pub outdated" (#2623)
93954f33 Use InternetAddress.tryParse over try/catch (#2626)
638c81c9 Refine publishing message (#2624)


Allow github


Embed pub as a library into dartdev

Change-Id: Iadc6acb5c3425dfb8848db89820e6c9c8caf16ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167574
Reviewed-by: Jonas Jensen <jonasfj@google.com>
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants