Skip to main content
1 of 9
CPlus
  • 4.5k
  • 1
  • 27
  • 50

Should there be a language-agnostic canonical for if (x == a || b || c)

I have seen: Canonical, language-agnostic question for if(var != "x" || var != "y" ...)

That question solicits a canonical for a similar but slightly different problem, but mentions the same problem in the question. An answer reads:

I'm planning to write one as soon as I find time though, so that we could close them all.

But the answer was written a decade ago and mentioned only JS. A good language-agnostic canonical exists for the similar if (x != a || x != b ...) problem in the linked question: Why does non-equality check of one variable against many values always return true?

Several canonical questions exist for the if (x == a || b || c ...) problem but only for specific languages:

I am considering creating a single cross-language canonical for this common beginner error to serve as a dupe target for miscellaneous questions to which no language-specific canonical exists. A good if (x != a || x != b ...) canonical was created a decade ago as a response to the old question. I am wondering if creating a language-agnostic canonical to the similar but different if (x == a || b || c ...) problem would bring still benefit to the community now in 2024. I have seen this and this but one says 'Go for it' and other says 'Don't even bother.'

CPlus
  • 4.5k
  • 1
  • 27
  • 50