Skip to main content

Refactoring MATLAB

  • Conference paper

Part of the Lecture Notes in Computer Science book series (LNTCS,volume 7791)


Matlab is a very popular dynamic “scripting” language for numerical computations used by scientists, engineers and students world-wide. Matlab programs are often developed incrementally using a mixture of Matlab scripts and functions, and frequently build upon existing code which may use outdated features. This results in programs that could benefit from refactoring, especially if the code will be reused and/or distributed. Despite the need for refactoring, there appear to be no Matlab refactoring tools available. Furthermore, correct refactoring of Matlab is quite challenging because of its non-standard rules for binding identifiers. Even simple refactorings are non-trivial.

This paper presents the important challenges of refactoring Matlab along with automated techniques to handle a collection of refactorings for Matlab functions and scripts including: converting scripts to functions, extracting functions, and converting dynamic function calls to static ones. The refactorings have been implemented using the McLab compiler framework, and an evaluation is given on a large set of Matlab benchmarks which demonstrates the effectiveness of our approach.


  • Behavior Preservation
  • Clone Detection
  • Output Argument
  • Input Argument
  • Call Site

These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. Opdyke, W.F.: Refactoring Object-Oriented Frameworks. Ph.D. thesis, University of Illinois at Urbana-Champaign (1992)

    Google Scholar 

  2. Griswold, W.G.: Program Restructuring as an Aid to Software Maintenance. Ph.D. thesis, University of Washington (1991)

    Google Scholar 

  3. Fowler, M.: Refactoring: Improving the Design of Existing Code. Addison-Wesley (1999)

    Google Scholar 

  4. Doherty, J., Hendren, L., Radpour, S.: Kind analysis for MATLAB. In: Proceedings of OOPSLA 2011 (2011)

    Google Scholar 

  5. McLab,

  6. Lameed, N., Hendren, L.: Staged Static Techniques to Efficiently Implement Array Copy Semantics in a MATLAB JIT Compiler. In: Knoop, J. (ed.) CC 2011. LNCS, vol. 6601, pp. 22–41. Springer, Heidelberg (2011)

    CrossRef  Google Scholar 

  7. English, M., McCreanor, P.: Exploring the Differing Usages of Programming Language Features in Systems Developed in C++ and Java. In: PPIG (2009)

    Google Scholar 

  8. Radpour, S.: Understanding and Refactoring the Matlab Language. M.Sc. thesis, McGill University (2012)

    Google Scholar 

  9. Soares, G., Gheyi, R., Serey, D., Massoni, T.: Making Program Refactoring Safer. IEEE Software 27(4), 52–57 (2010)

    CrossRef  Google Scholar 

  10. Schäfer, M., de Moor, O.: Specifying and Implementing Refactorings. In: OOPSLA (2010)

    Google Scholar 

  11. Tip, F., Fuhrer, R.M., Kieżun, A., Ernst, M.D., Balaban, I., Sutter, B.D.: Refactoring Using Type Constraints. TOPLAS 33, 9:1–9:47 (2011)

    Google Scholar 

  12. Schäfer, M., Thies, A., Steimann, F., Tip, F.: A Comprehensive Approach to Naming and Accessibility in Refactoring Java Programs. TSE (2012) (to appear)

    Google Scholar 

  13. Roberts, D., Brant, J., Johnson, R.E.: A Refactoring Tool for Smalltalk. TAPOS 3(4), 253–263 (1997)

    Google Scholar 

  14. Feldthaus, A., Millstein, T., Møller, A., Schäfer, M., Tip, F.: Tool-supported Refactoring for JavaScript. In: OOPSLA (2011)

    Google Scholar 

  15. Li, H., Thompson, S.J., Orösz, G., Tóth, M.: Refactoring with Wrangler, updated: Data and process refactorings, and integration with Eclipse. In: Erlang Workshop, pp. 61–72 (2008)

    Google Scholar 

  16. Li, H., Thompson, S.J.: Clone Detection and Removal for Erlang/OTP within a Refactoring Environment. In: PEPM, pp. 169–178 (2009)

    Google Scholar 

  17. Li, H., Thompson, S.J.: Refactoring Support for Modularity Maintenance in Erlang. In: SCAM, pp. 157–166 (2010)

    Google Scholar 

  18. Li, H., Thompson, S.: A Domain-Specific Language for Scripting Refactorings in Erlang. In: de Lara, J., Zisman, A. (eds.) Fundamental Approaches to Software Engineering. LNCS, vol. 7212, pp. 501–515. Springer, Heidelberg (2012)

    CrossRef  Google Scholar 

  19. Sagonas, K., Avgerinos, T.: Automatic Refactoring of Erlang Programs. In: PPDP, pp. 13–24 (2009)

    Google Scholar 

  20. Overbey, J.L., Negara, S., Johnson, R.E.: Refactoring and the Evolution of Fortran. In: SECSE, pp. 28–34 (2009)

    Google Scholar 

  21. Overbey, J.L., Johnson, R.E.: Regrowing a Language: Refactoring Tools Allow Programming Languages to Evolve. In: OOPSLA (2009)

    Google Scholar 

  22. Overbey, J., Xanthos, S., Johnson, R., Foote, B.: Refactorings for Fortran and High-performance Computing. In: SE-HPCS, pp. 37–39 (2005)

    Google Scholar 

  23. Boniati, B.B., Charão, A.S., Stein, B.D.O., Rissetti, G., Piveta, E.K.: Automated Refactorings for High Performance Fortran Programmes. IJHPSA 3(2/3), 98–109 (2011)

    CrossRef  Google Scholar 

  24. Menon, V., Pingali, K.: A Case for Source-level Transformations in MATLAB. In: DSL, pp. 53–65 (1999)

    Google Scholar 

Download references

Author information

Authors and Affiliations


Editor information

Editors and Affiliations

Rights and permissions

Reprints and Permissions

Copyright information

© 2013 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Radpour, S., Hendren, L., Schäfer, M. (2013). Refactoring MATLAB. In: Jhala, R., De Bosschere, K. (eds) Compiler Construction. CC 2013. Lecture Notes in Computer Science, vol 7791. Springer, Berlin, Heidelberg.

Download citation

  • DOI:

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-37050-2

  • Online ISBN: 978-3-642-37051-9

  • eBook Packages: Computer ScienceComputer Science (R0)