Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does DRY combine with "Separation of concern" and "One function, one task"?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/611304/how-many-lines-of-code-should-a-function-procedure-method-have">How many lines of code should a function/procedure/method have?</a> </p> </blockquote> <p>Out team has a project of not well structured ansi-c code. I would like to use some CC techniques to tidy up the code base.</p> <p>As for C code, we have a lot of pointers and a lot of NULL-pointer pitfalls to catch. Therefore there are lot of fragments which look alike. It's like</p> <pre><code>if (pointer == NULL) { function1(); function2(); } </code></pre> <p>all over the place. Then there are an awful lot of functions that will be called after each other in the same fashion only with a few variations, like</p> <pre><code>function1(); function2a(); function3(); </code></pre> <p>and </p> <pre><code>function1(); function2b(); function3(); </code></pre> <p>all over the place.</p> <p>I would like to extract those blocks as a single function to reduce LOC and copy-pasting. But that will create not only a (somewhat) orthogonal layer but also a handfull of function doing more or less the same, except for some details. And even worse, it will create functions that do a lot of things at once.</p> <p>So, what's a good strategy? What's more important, lean code on high level, lean functions on low level or lean architecture? Which principle trumps the other? Seperation of concern or DRY?</p> <p>I would like to refactor that beast but don't know where to start.</p> <p>To exploid the example below and put same names in. Lets assume we have</p> <pre><code>morningBath(); drinkCoffee(); if (checkMail()) { answerMail(); } </code></pre> <p>and put that into morningRoutine(). Now we have</p> <pre><code>drinkTea(); morningBath(); if (checkMail()) { answerMail(); } </code></pre> <p>and call it sundayMorningRoutine(). But then there is duplicated code. Or expand morningRoutine(day) as</p> <pre><code>if (day == sunday){ drinkTea(); morningBath(); } else { morningBath(); drinkCoffee(); } if (checkMail()) { answerMail(); } </code></pre> <p>or maybe</p> <pre><code>if (day == sunday){ drink(Tea); morningBath(); } else { morningBath(); drink(Coffee); } if (checkMail()) { answerMail(); } </code></pre> <p>I wonder if that is good style.. maybe.. Thanks for that hint!</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