dart-lang / dart-lang/language
Language suggestion: make IF and TRY/CATCH expressions (like Kotlin)
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
I am not sure this is possible, but it will be great.
In Kotlin you can do:
```
var x = if (condition) {
value1
} else {
value2
}
```
And yes in Dart we can use `x = aaa ? bbb : ccc;` but we can't put any complex logic here (as well as use few branches)
Live example form code which I am writing right now
```
var entrantsValueText = '';
if (f.stakeFrom > 0 && f.stakeTo > 0) {
entrantsValueText = '$curSymbol ${f.stakeFrom}-${f.stakeTo}';
} else if (f.stakeFrom > 0) {
entrantsValueText = '>$curSymbol${f.stakeFrom}';
} else {
entrantsValueText = '<$curSymbol${f.stakeTo}';
}
```
will be MUCH more shorter
```
var entrantsValueText = if (f.stakeFrom > 0 && f.stakeTo > 0) {
'$curSymbol ${f.stakeFrom}-${f.stakeTo}';
} else if (f.stakeFrom > 0) {
'>$curSymbol${f.stakeFrom}';
} else {
'<$curSymbol${f.stakeTo}';
}
```
I would like to see in Dart all nice features from Kotlin like `when`, `let`, `with` and many more. Should I create an issue for each of them? Or this is totally impossibly due the language architecture?
I know Kotlin transforms all that code inside and generates needed properties, fields and functions, but Dart don't behave like this.
Maybe this is possible to create some lib / plugin for that? If somebody will teach me how to do it and will pay for it I would love to spend 1 month for that, for example =)
Contributor guide
Assessment
This issue has not been assessed yet.