dart-lang / dart-lang/language

Proposal: argument passed by reference

Open
#426 5 comments 2 reactions 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

There is a workaround for local variables (wrap in class) but it's not clear how to handle class fields. Amount of code to do routine stuff like copy values and check for changes is overwhelming comparing to languages like C++, C#, Delphi, Swift. It's just annoying to write and maintain.

```
// model

class DateRange {
DateTime start, end;
...
}

// utility

/// returns false if not changed
bool editDate(ref DateTime date) {
...
}

// view

DateRange range;
...
btn1.onPressed = () {
if(editDate(range.start))
save();
};
btn2.onPressed = () {
if(editDate(range.end))
save();
};
```

Compare to
```
btn1.onPressed = () {
final out = editDate(range.start);
if(out != null && out != range.start) {
range.start = out;
save();
}
};
```
This is two lines vs. five. And in our business logic it's a very common thing.

Contributor guide

Open the contributing guide

Research direction

No files, tests, or entry points are named. Start by reviewing the proposal and its Dart examples, then determine the intended semantics and language-design constraints for reference arguments, including class fields. Done would require an accepted, specified design rather than a localized code change.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.