vendredi 18 septembre 2015

Shall I refactor code if it hides the flow of the program?

I have built restful web services. The services endpoints have a similar logic:

If the input validation succeeds, do a database operation and return the result.

If the db operation fails, return the db error.

If the validation fail, return a response with information on the failed validation

My code was explicit in the sense you can read the code and understand the flow of the program.

A coworker refactored it so that this basic flow is refactored in a utile class which main function takes the request body, the db operation and the handlers.

Now the code doesn't express the flow but the basic logic is refactored.

What is the best practice? Would u sacrifice readability for refactoring?

Yes unit test will be reduced a bit too.

Thanks.

Aucun commentaire:

Enregistrer un commentaire