News for hackers. Stuff that matters.
Re:Using ‘switch’ to match arbitrary logic instead of string... by metalgearsolid on Monday August 19, 2019 @06:34AM (#20736563)
Swift's nil-coalescing operator is a great solution for this.

  return config.github ?? config.twitter ?? default
Re:Using ‘switch’ to match arbitrary logic instead of string... by lsaferite on Monday August 19, 2019 @08:32AM (#20737130)
And you just introduced a bug.

You refactored the code and changed the logic without noticing.

Re:Using ‘switch’ to match arbitrary logic instead of string... by degif on Monday August 19, 2019 @06:45AM (#20736635)
The same is in JavaScript:

  return (twitterUrl && config.twitter) || (githubUrl && config.github) || default
Re:Using ‘switch’ to match arbitrary logic instead of string... by masklinn on Monday August 19, 2019 @07:01AM (#20736714)
Seems like an unnecessary mess when you could just use ternary expressions:

    return twitterUrl ? config.twitter
         : githubUrl ? config.github
         : default
Re:Using ‘switch’ to match arbitrary logic instead of string... by Y-bar on Monday August 19, 2019 @07:48AM (#20736914)
I envy you, I’d love to grok ternary expressions better but every time I just end up having to spend a long time unrolling the logic.