about icon indicating copy to clipboard operation
about copied to clipboard

Remove/replace misleading example about EqualFold in blog post

Open varungandhi-src opened this issue 3 years ago • 3 comments

In Code search turned code checker, we showcase the example of Go staticcheck's SA6005 where strings.ToLower(a) == strings.ToLower(b) is changed to strings.EqualFold(a, b). We also link the DigitalOcean blog, which frames this as an "optimization", and we repeat that:

And as a codebase grows, small inefficiencies like this one, and inconsistencies opportunities compound. Code patterns creep in that affect readability and performance—and it matters.

However, the DigitalOcean blog post is incorrect; in general, this is not a semantics-preserving transformation. (see https://github.com/golang/go/issues/52204, https://github.com/dominikh/go-tools/issues/1246)

I think we should remove this example, and optionally replace it with a different one which doesn't have any such subtleties.

varungandhi-src avatar Apr 07 '22 17:04 varungandhi-src

cc @rvantonder

varungandhi-src avatar Apr 07 '22 17:04 varungandhi-src

It seems like we may also want to corresponding checks from https://github.com/comby-tools/go-patterns/blob/main/go-staticcheck.toml

varungandhi-src avatar Apr 07 '22 17:04 varungandhi-src

@varungandhi-src nice catch, count me surprised! You posted this when I was OOO but I have a different example I can replace it with, will address ~soonish.

rvantonder avatar May 22 '22 03:05 rvantonder