Go

Go

Made by DeepSource

Potentially unwanted dependency on evaluation order GO-W4006

Bug risk
Major

Depending on the evaluation order is not idiomatic and may lead to bugs during future refactorings.

Bad practice

package main

func mutate(x *int) int {
    *x += 10
    return *x
}

func identity(x int) int {
    return x
}

func foo() (int, int, int) {
    x := 5
    return identity(x), mutate(&x), x // 5, 15, 15
}

Recommended

package main

func mutate(x *int) int {
    *x += 10
    return *x
}

func identity(x int) int {
    return x
}

func foo() (int, int, int) {
    x := 5
    result := mutate(&x)
    return identity(x), result, x // 15, 15, 15
}