News for hackers. Stuff that matters.
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 Nullabillity on Saturday January 14, 2023 @08:17PM (#34385796)
I did notice it but wanted to keep the AST identical. But yes, it would have been worth pointing out, heh.
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 drittich on Monday January 16, 2023 @08:15AM (#34400267)
You learn something new every day! I have written JavaScript off and on for years and did not encounter that.