Go

Go

Made by DeepSource

Swapping can be done using parallel assignment CRT-A0009

Anti-pattern
Major
Autofix

It is legal and idiomatic to swap values of two variables using "tuple assignment" instead of swapping them in multiple statements.

For Python, "tuple assignment" is a feature that allows a tuple of variables on the left of an assignment to be assigned values from a tuple on the right of the assignment. A similar assignment approach works for Go as well.

Bad practice

tmp := *x
*x = *y
*y = tmp

Recommended

*x, *y = *y, *x