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

Add swap macro #1724

Open
gnudles opened this issue Jul 3, 2021 · 4 comments
Open

Add swap macro #1724

gnudles opened this issue Jul 3, 2021 · 4 comments
Labels
request Requests to resolve a particular developer problem

Comments

@gnudles
Copy link

gnudles commented Jul 3, 2021

swapping two integer variables cannot be made in function, because it alters only the local value.
fact: variable swap takes 3 lines of code.
please add swap macro that do swap instead of doing it in every place we need.

@gnudles gnudles added the request Requests to resolve a particular developer problem label Jul 3, 2021
@gnudles gnudles changed the title swapping two integer variables cannot be made in function Add swap macro Jul 3, 2021
@Semvrij
Copy link

Semvrij commented Jul 3, 2021

Swapping variables will become much easier when a way to destructure (#207) is added.

Current method:

int a = 1;
int b = 2;

int temp = a;
a = b;
b = temp;

With destructuring:

int a = 1;
int b = 2;

[a, b] = [b, a];

@gnudles
Copy link
Author

gnudles commented Jul 13, 2021

Destructure does not seem like it coming soon, or ever.
I think a macro or a special syntax should be in the meantime

@ChristianKleineidam
Copy link

It's a huge part of darts language philosophy to be a concise language to learn. If special syntax would created to solve a bunch of cases like this (that aren't even important enough for the author to argue why they need it in real world programs) the special syntax would make dart more complex and harder to learn.

Core language features aren't supposed to be added to solve issues "in the mean time".

@gnudles
Copy link
Author

gnudles commented Jul 31, 2021

You've got a point. It is just annoying to write 3 lines of code each time you need a tiny swap. That's all.

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