News for hackers. Stuff that matters.
Re:GitHub Copilot’s Code Brushes by mpeg on Saturday January 14, 2023 @06:48PM (#34385290)
That’s not readable at all. Chaining ternary operators like that is much worse than the code the article shows.

Maybe it’s a stylistic choice, but there’s nothing wrong with a sequence of “else ifs” as long as you don’t go deeper (like in the example)

Re:GitHub Copilot’s Code Brushes by Nullabillity on Saturday January 14, 2023 @08:27PM (#34385852)
Chained ifs add a whole lot of visual noise, aren't guaranteed to be total, and introduce the temptation to add more logic into the cases.

That said, I do wish more languages had copied Haskell's guard syntax for this kind of chain... For reference, that looks like:

    cmp x y | (x == Nothing || y == Nothing) = NaN -- (assuming x and y are Maybe, but this would typically be non-idiomatic)
            | x < y = -1
            | x > y = 1
            | x >= y = 0 -- inert bug copied from original, "should" be == instead
            | otherwise = NaN
Re:GitHub Copilot’s Code Brushes by mpeg on Tuesday January 17, 2023 @09:44AM (#34412919)
I too always find myself wanting features from functional languages, I haven't done much Haskell but love the syntax for pattern matching in Elixir with guards, plus the pipe operator.
Re:GitHub Copilot’s Code Brushes by 9dev on Sunday January 15, 2023 @03:12AM (#34387708)
This would be a perfect case for a match expression, which, surprisingly, PHP now supports:

  return match(true) {
    $a == null && $b == null => null,
    $a < $b => -1,
    $a > $b => 1,
    $a == $b => 0,
    default => null;
  }
I’m surprised this feature isn’t prevalent in modern languages. It makes the code so concise and easy to understand, it’s marvellous.