Changing software correctly
Year: 2006
Type: report
Abstract: Modifications of code that do not alter the functioning of object-oriented software are called refactorings.Refactoring tools, not programmers, should guarantee correctness to be most useful.When do refactorings retain equivalence?To tackle this question, I conceive a semantic model of refactorings.It aims at making it simple to prove refactorings correct, i.e., to prove that equivalence is retained.It is parameterized over an operational semantics.The crucial point is that the correspondence between original and refactored program need not be defined for all states and all program points.The formalism is crafted so as to offer a solution to a second problem: How can refactorings be applied in practice without giving up equivalence guarantees?The idea is this: The proof procedure for refactorings yields minimal obligations that must be satisfied by the transformed program.These conditions can be formulated as pre-and postconditions of statements in the code -they are local.Every program you want to apply the refactoring to needs to satisfy those conditions.It is not practical to check them by hand.I suggest that a refactoring tool does it for you: It will check simple conditions before applying the refactoring as "preconditions" and it will add specification and instrumentation to the transformed program for all those properties that cannot be readily checked or sensibly approximated -these are called "postconditions".It will also add all conditions as specifications that encode architectural constrains.With every refactoring, the programmer thus codifies part of the tacit knowledge that is needed to know that the respective refactoring is applicable for the program.The idea to extract specifications from interactions between program and programmer can be applied to any change with defined semantics.A refactoring catalogue that is included does not mainly serve as an illustration of theoretical concepts.It shows that most refactorings can be reduced to individual code changes that are easy to verify using the theoretical framework and then be composed to the conventional refactorings as we know them.I.e., refactorings in this text hardly ever affect an unbounded number of code locations.The exception are data-refactorings.They are covered separately.• If every access path is retained, it is impossible that the refactoring is changing an unbounded number of program parts -if the refactoring is atomic.This is Global data invariance ⇒ local modifications so because data invariant changes are in fact independent of each other and the refactoring could be split into multiple simpler refactorings.• If the control flow is not retained, modification should be local.If control flow changes, modifications to the local state σ are made.This cannot be due to access Control flow changes ⇒ local modifications path changes because they should be isolated by data translation.Changes in control flow must therefore be due to other local changes.Local changes can be made in isolation however and if they are not, the refactoring is not atomic.Likewise, control flow changes should not involve access path modifications because Control flow changes ⇒ no global state changes 24 It can still be argued about correctnenss, but not in a mathematically rigorous way.
Author: Bannwart, Fabian Yves
Language: English
Subfield: Software
Field: Computer Science
Domain: Physical Sciences
Open Access status: green
OpenAlex ID: W1473903605
