Skip to main content

Changing Programs Correctly: Refactoring with Specifications

  • Conference paper

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 4085))

Abstract

Refactorings change the internal structure of code without changing its external behavior. For non-trivial refactorings, the preservation of external behavior depends on semantic properties of the program that are difficult to check automatically before the refactoring is applied. Therefore, existing refactoring tools either do not support non-trivial refactorings at all or force programmers to rely on (typically incomplete) test suites to check their refactorings.

The technique presented in the paper allows one to show the preservation of external behavior even for complex refactorings. For a given refactoring, we prove once and for all that the refactoring is an equivalence transformation, provided that the refactored program satisfies certain semantic correctness conditions. These conditions can be added automatically as assertions to the refactored program and checked at runtime or verified statically. Our technique allows tools to apply even complex refactorings safely, and refactorings automatically improve program documentation by generating assertions.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   84.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   109.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Banerjee, A., Naumann, D.A.: Ownership confinement ensures representation independence for object-oriented programs. J. ACM 52(6), 894–960 (2005)

    Article  MathSciNet  Google Scholar 

  2. Bannwart, F.: Changing software correctly. Technical Report 509, Department of Computer Science, ETH Zürich (2006)

    Google Scholar 

  3. Barnett, M., Leino, K.R.M., Schulte, W.: The Spec# Programming System: An Overview. In: Barthe, G., Burdy, L., Huisman, M., Lanet, J.-L., Muntean, T. (eds.) CASSIS 2004. LNCS, vol. 3362, pp. 49–69. Springer, Heidelberg (2005)

    Chapter  Google Scholar 

  4. Bergstein, P.L.: Object-preserving class transformations. In: OOPSLA, pp. 299–313. ACM Press, New York (1991)

    Google Scholar 

  5. Clarke, D.G., Potter, J.M., Noble, J.: Ownership types for flexible alias protection. In: OOPSLA, pp. 48–64. ACM Press, New York (1998)

    Google Scholar 

  6. Cornélio, M.: Refactorings as Formal Refinements. PhD thesis, Universidade de Pernambuco (2004)

    Google Scholar 

  7. Dietl, W., Müller, P.: Universes: Lightweight ownership for JML. Journal of Object Technology (JOT) 4(8), 5–32 (2005)

    Article  Google Scholar 

  8. Fähndrich, M., DeLine, R.: Adoption and focus: practical linear types for imperative programming. In: PLDI, pp. 13–24. ACM Press, New York (2002)

    Google Scholar 

  9. Fähndrich, M., Leino, K.R.M.: Declaring and checking non-null types in an object-oriented language. In: OOPSLA, pp. 302–312. ACM Press, New York (2003)

    Google Scholar 

  10. Fowler, M.: Refactoring: improving the design of existing code. Addison-Wesley, Reading (1999)

    Google Scholar 

  11. Gheyi, R., Massoni, T., Borba, P.: An abstract equivalence notion for object models. Electr. Notes Theor. Comput. Sci. 130, 3–21 (2005)

    Article  Google Scholar 

  12. Kerievsky, J.: Refactoring to Patterns. Addison-Wesley Professional, Reading (2004)

    Google Scholar 

  13. Kiniry, J.R., Cok, D.R.: ESC/Java2: Uniting ESC/Java and JML. In: Barthe, G., Burdy, L., Huisman, M., Lanet, J.-L., Muntean, T. (eds.) CASSIS 2004. LNCS, vol. 3362, pp. 108–128. Springer, Heidelberg (2005)

    Chapter  Google Scholar 

  14. Lämmel, R.: Towards Generic Refactoring. In: Workshop on Rule-Based Programming (RULE). ACM Press, New York (2002)

    Google Scholar 

  15. Leavens, G.T., Baker, A.L., Ruby, C.: Preliminary design of JML: A behavioral interface specification language for Java. Technical Report 98-06-rev28, Iowa State University (2005)

    Google Scholar 

  16. Leino, K.R.M., Müller, P.: Object invariants in dynamic contexts. In: Odersky, M. (ed.) ECOOP 2004. LNCS, vol. 3086, pp. 491–515. Springer, Heidelberg (2004)

    Chapter  Google Scholar 

  17. Lieberherr, K.J., Hürsch, W.L., Xiao, C.: Object-extending class transformations. Formal Aspects of Computing (6), 391–416 (1994)

    Article  MATH  Google Scholar 

  18. Logozzo, F., Cortesi, A.: Semantic hierarchy refactoring by abstract interpretation. In: Emerson, E.A., Namjoshi, K.S. (eds.) VMCAI 2006. LNCS, vol. 3855, pp. 313–331. Springer, Heidelberg (2005)

    Chapter  Google Scholar 

  19. Morgan, C.: Programming from specifications. Prentice-Hall, Englewood Cliffs (1990)

    MATH  Google Scholar 

  20. Opdyke, W.F.: Refactoring object-oriented frameworks. PhD thesis, University of Illinois at Urbana-Champaign (1992)

    Google Scholar 

  21. Roberts, D.B.: Practical analysis for refactoring. PhD thesis, University of Illinois at Urbana-Champaign (1999)

    Google Scholar 

  22. Streckenbach, M., Snelting, G.: Refactoring class hierarchies with KABA. In: OOPSLA, pp. 315–330. ACM Press, New York (2004)

    Google Scholar 

  23. Tokuda, L., Batory, D.: Evolving object-oriented designs with refactorings. In: Automated Software Engineering, pp. 174–182. IEEE Computer Society, Los Alamitos (1999)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2006 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Bannwart, F., Müller, P. (2006). Changing Programs Correctly: Refactoring with Specifications. In: Misra, J., Nipkow, T., Sekerinski, E. (eds) FM 2006: Formal Methods. FM 2006. Lecture Notes in Computer Science, vol 4085. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11813040_33

Download citation

  • DOI: https://doi.org/10.1007/11813040_33

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-37215-8

  • Online ISBN: 978-3-540-37216-5

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics