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 drittich on Saturday January 14, 2023 @07:02PM
(#34385376)
What interests me here is that both your version and the else if version perpetuate the error in the original code which is the case where a is greater than b, which is handled once by a greater than comparison, and then again by a greater than or equal to comparison, which is clearly redundant. Neither CoPilot, nor you, nor the article author I presume caught this error in the flow control. Catching errors like these adds more value then making it more readable, although making it more readable certainly did expose the error more clearly to me.
Re:GitHub Copilot’s Code Brushes
by garaboncias2 on Sunday January 15, 2023 @05:20PM
(#34394227)
Actually it is not redundant as >= do numerical comparsion (so convert a and b to number) while == do not do that. So it has different result on objects.
Re:GitHub Copilot’s Code Brushes
by satvikpendem on Saturday January 14, 2023 @03:47PM
(#34384029)
I've used a few of these but to be honest they're worse than ChatGPT, and they're almost nigh useless. I'm not sure what model Microsoft is using because they own half of OpenAI now, they should integrate the ChatGPT model instead of the older Codex one, it seems.
Re:GitHub Copilot’s Code Brushes
by jerkstate on Saturday January 14, 2023 @05:11PM
(#34384636)
I've been experimenting with this kind of thing lately, but what I've found more useful is the "edit" mode in the openapi playground. You paste your existing code in there, give some instruction, then submit, and it seems to do pretty well. I'm hoping that the next generation of Copilot will be able to make use of this, as sort of "dynamic brushes"
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)
That said, I do wish more languages had copied Haskell's guard syntax for this kind of chain... For reference, that looks like: