vendredi 29 mai 2015

Single large function vs multiple smaller funcions?

I am well aware of fact that single task per function is better than single function doing multiple tasks. Moreover, my question is bit trickier than this.

I am writing a parser which requires many parameters (8 to 10) on various condition to parse a input buffer. I have following two choices.

  1. Keep all functions small enough including main parser function. Pass the required parameters as pointer to structure from the main parser function to helper functions. Individual Function will access parameter from structure and write the result to the structure.

  2. One large main parser function (~250 lines) and other smaller functions. All required parameters will be local to main parser function. Main function pass the parameters to helper functions by arguments. function arguments are limited to 4 only.

Which is the better approach?

Aucun commentaire:

Enregistrer un commentaire