How can I verify that refactoring maintains a stream of code, not just behavior?

Sometimes I see if-statements that can be written better. Usually these are cases where we have several levels of nested if statements, and I have defined an easier way to rewrite the if-statement block. Of course, the biggest problem is that in some cases the resulting code will have a different code stream.

How can I compare two code blocks and determine if the code stream is the same or different? Is there a way to support this analysis with static analysis tools? Are there any other methods that might help?

+4
source share
1 answer

Find a way to implement all the possible paths through the code you want to reorganize. You could

  • write block tests manually
  • use Daikon http://plse.cs.washington.edu/daikon/ , which automatically and systematically enters code to output invariants (I did not use it myself, but I tried a commercial Java-oriented descendant)

In any case, use the code coverage tool to make sure you have a complete application and coverage solution. Use a coverage tool that reports the number of times each statement is executed during a coverage run. You might even be able to get trucov , which actually creates code path diagrams to work.

Do refactoring.

. - , . , , , , . , trucov, ; .

+2

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


All Articles