Both versions below achieve the same thing but version 1 is idiomatic in Go for the following reasons:
- It expresses intent, not mechanics — it’s easy to understand that you’re checking for empty value
- It is aligned wiht Go’s zero-value philosophy
- You know you’re dealing with string by looking at its comparison
// version 1
if str == "" {
//...
}
// version 2
if len(str) == 0 {
// ...
}