Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to improve maintainability of functions
    primarykey
    data
    text
    <p>I will expand here on a comment I made to <a href="https://stackoverflow.com/questions/2244860/when-a-method-has-too-many-parameters">When a method has too many parameters?</a> where the OP was having minor problems with someone else's function which had 97 parameters.</p> <p>I am a great believer in writing maintainable code (and it is often easier to write than to read, hence Steve McConnell(praise be upon his name)'s phrase "write only code").</p> <p>Since statistics how that most car accidents happen at junctions and my experience (ymmv) shows that most "anomalies" occur at interfaces, I will list some things that I do to attempt to avoid misunderstandings at interfaces and invite your comments if I am going badly wrong.</p> <p>But, more importantly, I invite your suggestions for making things even more prophylactic (see, there is a question after all - how to improve things?).</p> <ul> <li>Adequate documentation, in the form of (up to date) DoxyGen format comments describing the nature and porpoise of each parameter.</li> <li>absolutely <strong>NO</strong> back-door shenanigans with global variables as hidden parameters.</li> <li>try to limit parameters to six or eight. If more, pass related parameters as a structure; if they are not related then seriously reconsider the function. If it needs so much information, is it too complex to maintain? Can it be broken down into several smaller functions?</li> <li>use the CONST as often as possible and meaningful.</li> <li>a coding standard that says that input parameters come first, then output only, and finally input/output, which are modified by the function.</li> <li><p>I also #define some empty macros to make declarations even easier to read:</p> <p><code>#</code>define INPUT<br> <code>#</code>define OUTPUT<br> <code>#</code>define MODIFY<br> bool DoSomething(INPUT int howOften, MODIFY Wdiget *myWidget, OUTPUT WidgetPtr * const nextWidget)</p></li> </ul> <p>Just a few ideas. How can I improve on these? Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload