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

Some improvements picked up from Kotlin language #1408

Open
mregnauld opened this issue Jan 17, 2021 · 4 comments
Open

Some improvements picked up from Kotlin language #1408

mregnauld opened this issue Jan 17, 2021 · 4 comments
Labels
feature Proposed language feature that solves one or more problems

Comments

@mregnauld
Copy link

mregnauld commented Jan 17, 2021

I'm currently migrating a music app from native Android (using Kotlin) to Flutter, and here are a few improvements that could be done:

  • using the switch command without break, as it is done in Kotlin with the when command. The reason why it's very useful is that the break could lead to bugs that are very hard to find if you forget it (happened to me a few times and I struggled a lot):
switch(myVariable)
    1 -> doOneLineCommand()
    2 -> {
        doMultipleLineCommand()
        doSomethingElseAndSoOn()
    }
    3, 4, 5 -> doSomethingForThoseMultipleCases()
    default -> defaultCommand()
  • using the for command as it is done in Kotlin. Again, repeating the variable name in the for command can lead to bugs if you copy/paste some code and you forget to rename the variable everywhere for example (happened again once):
for (a in 1..10) {...}
for (a in 1..10 step 2) {...}
for (a in start until end step 3) {...}
for (a in start downTo end step 4) {...}
// and so on...
  • also, just like Kotlin, can we get rid once for all of the ; in the end of each line? That would be great!

Thanks.

@mregnauld mregnauld added the feature Proposed language feature that solves one or more problems label Jan 17, 2021
@vxern
Copy link

vxern commented Jan 17, 2021

The switch statement is very similar to rust's syntax, and I really like it.

Also, having a for loop that takes a range such as 1..10 is much cleaner than for (var i = 0; i < 10; i++) {}.

As to the semicolons at the end of lines, nah. It is good as it is right now. I'm not sure if the entire SDK wouldn't have to be ploughed through in order to bring that change in

@mregnauld
Copy link
Author

mregnauld commented Jan 17, 2021

As to the semicolons at the end of lines, nah. It is good as it is right now. I'm not sure if the entire SDK wouldn't have to be ploughed through in order to bring that change in

I was skeptical about the semicolons too when I first tried Kotlin, but then I realized how nice it was to not deal with semicolons anymore and how they are actually useless.

And the feature I'm asking for is not to get rid of semicolons, but at least to make them not mandatory anymore (just like Kotlin, in fact, you can use semicolons if you want, even though it's useless).

@karthickr95
Copy link

karthickr95 commented Apr 27, 2021

Duplicate #1509

@karthickr95
Copy link

Duplicate #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

3 participants