From the course: Accelerating Laravel API Development with AI: From Specification to Testing

Unlock this course with a free trial

Join today to access over 25,100 courses taught by industry experts.

Debugging AI-generated code

Debugging AI-generated code

- [Instructor] AI code almost always looks reasonable, but there can be hidden logic issues. To uncover these, you need to think like a tester: Test with different values to confirm expectations. This function calculates the discount percentage for certain user types. It was, of course, AI generated. Can you spot the bug? If a student is greater than or equal to 65, they receive the student discount, which is a smaller discount than they would receive in the upper age bracket. So I'll just tell Copilot, "There is a logic bug in the function. A user is a student and over 65 should get 30%, not 15%." And so unsurprisingly, Copilot's suggestion is to change the order of comparison. And that's fine, I want to go further. What if there is future business logic for students over 60? I want to show you something that AI is bad at. It has a bias to word agreement. I'll ask, "Does this function have too much responsibility?" It's of course not going to say, "nope," but the code change output…

Contents