When to stop drying code?

So, apparently, should the code be good? In one of the projects I was working on, there was a situation where there were certain models / entities that were more or less the same, except for the context in which they were used. That is, each such object has a title, descriptions, tags, user_id, etc. And some other attributes. Consequently, their CRUD actions in their respective controller looked pretty similar.

My manager claimed that his code repetition and the need for DRYed. Consequently, he came up with the ruby ​​CRUD module, which, when included took care of the CRUD actions for the controllers of all these objects. But in the end, Simplicity was compromised. The code has lost readability because each “thing” has been called an “object”. Debugging became difficult, and the whole point of DRY code was lost.

This was just one case. There are several of them where DRYing up leads to complex, hard-to-debug code. So the question is when will we stop DRYing code? Because not every time you understand that the code has lost simplicity (and often the author of the code never realizes that the simplicity of the code is lost). In addition, if we need to choose between simplicity and DRYed code, what to choose, if at all there is a situation where you can get only one of them.

+3
source share
8 answers

, , DRYing- , - . , , . / , . , . DRYing , , , DRY- , , . DRYing , .

+4

REST, , . , .

, . , Jose Valim inherited_resources , Rails 3.

+2

- . , . , .

. , , , .

0

"", , " ", . , ( , , ). + "realtype [id]", .

DRY.

DRY :

. IS-A. , , . .

, . , , ( ) . , (DRY), (imho).

2 cts.

0

- - - DRY, , , , , , -sake--.

, () (). , , . ( PHP, , ):

$checked = ($somevariable) ? "checked=\"checked\"" :"";
echo "<input type="radio" $disabled_checked />";
$checked = ($someothervariable) ? "checked=\"checked\"" :"";
echo "<input type="radio" $checked />";

, . , , , . , , "" , , - , . , : ", , , . ".

, , , , , , ( " , , ).

, , , , - , , , Ruby Python , Jquery.

, , 70 things 2? , . ( ), . , , , .

0

DRY - "" .

, . . , - , .

, , , codegolfing, DRY, .

, .

0

DRY , , , , .

:

DT, :

DRY , , .

, "", " " , .

DRY - , : , , .

(, , , , " ", "" : , , ).

0

- , :

  • ( ).
  • (push- ).
  • ( ).
  • - ( ).
  • ( ).

, , . .

, , , . , . , . , :

  • (, , ).
  • - ( ).
  • Your software is necessarily complex (make changes and live with it).

Consider a sample submit code, as well as questions like this, if possible. They provide something specific to the job. And remember that many things are very subjective.

0
source

Source: https://habr.com/ru/post/1719486/


All Articles