From the course: Refactoring with GitHub Copilot

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Code smells

Code smells

You are familiar with code smells, even if you don't know that phrase by name. Code smells are not bugs, but they are things that just don't seem right. This first function, process order, is 40 lines long. Long functions can be a code smell. It might be okay, but it's worth looking at. I'm going to walk through this function. The comments indicate that it has four responsibilities: validate order, calculate total price, apply shipping, and send notification. If I was going to refactor this function, I'd use those each as jumping-off points. This isn't, of course, about testing, but imagine having to write unit tests for this function, a nightmare. The next function, createUser, is an example of too many arguments. Just look at the signature, it has 11 or 12 parameters. I'm not sure I'd even remember if email or phone number comes first. And do I have to pass an empty string for args I don't intend to use? Imagine a use case where a business logic requires adding a title to the user…

Contents