Go

Go

Made by DeepSource

Unnecessary call to strings.Compare GO-C4012

Anti-pattern
Minor

As per Go's official doc, it is recommended not to use strings.Compare. Here's the reason why it is not recommended:

Compare is included only for symmetry with package bytes. It is usually clearer and always faster to use the built-in string comparison operators ==, <, >, and so on.

Examples

Bad practice

if strings.Compare(x, y) == 0 {

}

if strings.Compare(x, y) < 0 {

}

Recommended

if x == y {

}

if x < y {

}