go version)?$ go version go version go1.12.7 darwin/amd64
Yes
Try to find better to way to check if the string is empty.
Expecting verbose way to check if the string is empty rather than using,
Len(s) == 0
or
s == ""
The choices seem to be:
`
len(s) == 0
s == ""
strings.IsEmpty(s)
I don't see the advantage of adding another approach that is longer to write and no easier to read.
@ianlancetaylor
isn't this more obvious, cleaner and readable way.
it removes magic numbers/string constants from code which makes cleaner.
Constants like "" and 0 are not magic. They are ordinary language values that every Go programmer understands.
What approach would you take to check if an integer is zero? Surely you would just write
i == 0
and not expect a function IsZero? Well, strings are values, just like integers, and the way to check if they have a particular value is to compare them against that value:
s == ""
Strings also have the added, more "magic" as you put it, mechanism of checking their length. Surely a third way is not required.
most of the people more inclined towards an existing way, I am closing this issue.
Thank you for inputs here.
Most helpful comment
Constants like
""and0are not magic. They are ordinary language values that every Go programmer understands.