Skip to main content Accessibility help
×
Home

Refactoring tools for functional languages

  • SIMON THOMPSON (a1) and HUIQING LI (a1)

Abstract

Refactoring is the process of changing the design of a program without changing what it does. Typical refactorings, such as function extraction and generalisation, are intended to make a program more amenable to extension, more comprehensible and so on. Refactorings differ from other sorts of program transformation in being applied to source code, rather than to a ‘core’ language within a compiler, and also in having an effect across a code base, rather than to a single function definition, say. Because of this, there is a need to give automated support to the process. This paper reflects on our experience of building tools to refactor functional programs written in Haskell (HaRe) and Erlang (Wrangler). We begin by discussing what refactoring means for functional programming languages, first in theory, and then in the context of a larger example. Next, we address system design and details of system implementation as well as contrasting the style of refactoring and tooling for Haskell and Erlang. Building both tools led to reflections about what particular refactorings mean, as well as requiring analyses of various kinds, and we discuss both of these. We also discuss various extensions to the core tools, including integrating the tools with test frameworks; facilities for detecting and eliminating code clones; and facilities to make the systems extensible by users. We then reflect on our work by drawing some general conclusions, some of which apply particularly to functional languages, while many others are of general value.

Copyright

References

Hide All
Alglave, J., Donaldson, A. F., Kroening, D. & Tautschnig, M. (2011) Making software verification tools really work. In Proceedings of the 9th International Conference on Automated Technology for Verification and Analysis (ATVA'11). Berlin, Germany: Springer-Verlag.
Armstrong, J. (2007) Programming Erlang: Software for a Concurrent World. The Pragmatic Bookshelf.
Baker, B. S. (1992) A program for identifying duplicated code. Comput. Sci. Stat. 24, 4957.
Baker, B. S. (1995) On finding duplication and near-duplication in large software systems. In Second Working Conference on Reverse Engineering, Wills, L., Newcomb, P. & Chikofsky, E. (eds), Washington, DC, USA: IEEE Computer Society Press, pp. 8695.
Bravenboer, M., Kalleberg, K. T., Vermaas, R. & Visser, E. (2008) Stratego/XT 0.17. A language and toolset for program transformation. Sci. Comput. Program. 72, 5270.
Brown, C. (2008) Tool Support for Refactoring Haskell Programs. PhD thesis, School of Computing, University of Kent, Kent, UK.
Brown, C., Loidl, H.-Wo. & Hammond, K. (2011) Refactoring parallel Haskell programs. Symposium on Trends in Functional Programming (TFP'11), Madrid, Spain, May 2011, LNCS 7193.
Brown, C. & Thompson, S. (2010) Clone detection and elimination for Haskell. In Partial Evaluation and Program Manipulation (PEPM'10), Gallagher, J. & Voigtlander, J. (eds), New York, NY: ACM Press, pp. 111120.
Bulychev, P. & Minea, M. (2008) Duplicate code detection using anti-unification. In Spring Young Researchers Colloquium on Software Engineering (SYRCoSE), Saint-Petersburg, Russia, May 29–30, pp. 5154.
Burstall, R. & Darlington, J. (1975) Some transformations for developing recursive programs. In Proceedings of the International Conference on Reliable Software. New York, NY: ACM, pp. 465472.
Carlsson, R. & Rémond, M. (2006) EUnit: A lightweight unit testing framework for Erlang. In Proceedings of the 2006 ACM SIGPLAN Workshop on Erlang (ERLANG '06), Portland, Oregon, USA.
CarvalhoJúnior, A. Júnior, A., Silva, L. & Cornélio, M. (2007) Using CafeOBJ to mechanise refactoring proofs and application. Electron. Notes Theor. Comput. Sci. 184 (July), 3961.
Chassell, R. J. (2004) An Introduction to Programming in Emacs Lisp. Boston, MA: Free Software Foundation.
Claessen, K. & Hughes, J. (2000) QuickCheck: A lightweight tool for random testing of Haskell programs. In Proceedings of the Fifth ACM SIGPLAN International Conference on Functional Programming (ICFP '00), Montréal, Canada. New York, NY: ACM, pp. 268279.
Daniel, B., Dig, D., Garcia, K. & Marinov, D. (2007) Automated testing of refactoring engines. In Proceedings of the the 6th Joint Meeting of the European Software Engineering Conference and the ACM SIGSOFT Symposium on The Foundations of Software Engineering (ESEC-FSE '07), Dubrovnik, Croatia. New York, NY: ACM, pp. 185194.
Darlington, J. (1982) Program transformation. In Functional Programming and Its Applications, Darlington, J., Henderson, P. & Turner, D. A. (eds), Cambridge, UK: Cambridge University Press.
Drienyovszky, D., Horpacsi, D. & Thompson, S. (2010) QuickChecking refactoring tools. In Proceedings of the 2010 ACM SIGPLAN Erlang Workshop (Erlang'10), Baltimore, Maryland, USA. Fritchie, S. L. & Sagonas, K. (eds). New York, NY: ACM SIGPLAN, pp. 7580.
Erlang E-learning. (2011) Online e-Learning System. Available at: https://elearning.erlang-solutions.com. Accessed 6 September 2013.
ErlIDE. (n.d.) The Erlang IDE. Available at: http://erlide.sourceforge.net/. Accessed 6 September 2013.
Evans, W., Fraser, C. & Ma, F. (2008) Clone detection via structural abstraction. In The 14th Working Conference on Reverse Engineering, IEEE Computer Society Press, Washington, DC, USA. Vancouver, BC, Canada, pp. 150159.
Fowler, M. (1999) Refactoring: Improving the Design of Existing Code. Object Technology Series. Boston, MA: Addison-Wesley.
Gallardo, D. (n.d.) Refactoring for Everyone: How and Why to use Eclipse's Automated Refactoring Features. Available at: http://www.ibm.com/developerworks/library/os-ecref/. Accessed 6 September 2013.
Garrido, A. & Meseguer, J. (2006) Formal specification and verification of Java refactorings. In Proceedings of the Sixth IEEE International Workshop on Source Code Analysis and Manipulation (SCAM '06), Philadelphia, PA, USA. Washington, DC: IEEE Computer Society.
Ge, X., DuBose, Q. L. & Murphy-Hill, E. (2012) Reconciling manual and automatic refactoring. In Proceedings of the 2012 International Conference on Software Engineering (ICSE 2012), Zurich, Switzerland. New York, NY: IEEE Press, pp. 211221.
GHC API. (n.d.) GHC Commentary. Available at: http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/API. Accessed 6 September 2013.
Göde, N. & Koschke, R. (2009) Incremental clone detection. In Proceedings of the 2009 European Conference on Software Maintenance and Reengineering (CSMR'09), Kaiserslautern, Germany.
Griswold, W. G. (1991) Program Restructuring as an Aid to Software Maintenance. PhD thesis, Department of Computer Science and Engineering, University of Washington, Seattle, WA.
Griswold, W. G. & Notkin, D. (1993) Automated assistance for program restructuring. ACM Trans. Softw. Eng. Methodol. 2, 228269.
Hackage. (2010) HackageDB. Available at: http://hackage.haskell.org/. Accessed 6 September 2013.
Hallgren, T. (2003) Haskell tools from the programatica project (Demo Abstract). In ACM Sigplan Haskell Workshop, Uppsala, Sweden. New York, NY: ACM Press.
HaRe. (n.d.) The HaRe system. Available at: http://www.cs.kent.ac.uk/projects/refactor-fp/hare.html. Accessed 6 September 2013.
Haskell Platform. (2010) The Haskell Platform. Available at: http://hackage.haskell.org/platform/. Accessed 6 September 2013.
Hills, M., Klint, P. & Vinju, J. J. (2012) Scripting a refactoring with Rascal and Eclipse. In Proceedings of the Fifth Workshop on Refactoring Tools (WRT '12), Rapperswil, Switzerland. New York, NY: ACM, pp. 4049.
Horváth, Z., Lövei, L., Kozsik, T., Kitlei, R., Víg, A. N., Nagy, T., Tóth, M. & Király, R. (2008) Building a refactoring tool for Erlang. In Workshop on Advanced Software Development Tools and Techniques (WASDETT 2008), Paphos, Cyprus.
Hughes, J. & PeytonJones, S. Jones, S. (eds). (1999) Report on the Programming Language Haskell 98. Available at: http://www.haskell.org/onlinereport/. Accessed 6 September 2013.
Jiang, L., Misherghi, G., Su, Z. & Glondu, S. (2007) DECKARD: Scalable and accurate tree-based detection of code clones. In Proceedings of the 29th International Conference on Software Engineering (ICSE '07), Minneapolis, MN. Washington, DC: IEEE Computer Society, pp. 96105.
Katić, M. & Fertalj, K. (2009) Towards an appropriate software refactoring tool support. In Proceedings of the 9th WSEAS International Conference on Applied Computer Science (ACS'09), Genova, Italy. Stevens Print, WI: World Scientific and Engineering Academy and Society (WSEAS), pp. 140145.
Kitlei, R., Bozó, I., Kozsik, T., Tejfel, M. & Tóth, M. (2010) Analysis of Preprocessor Constructs in Erlang. In Proceedings of the 9th ACM SIGPLAN Erlang Workshop, Baltimore, Maryland, USA, pp. 4555.
Kitlei, R., Lövei, L., Tóth, M., Horváth, Z., Kozsik, T., Király, R., Bozó, I., Hoch, C. & Horpácsi, D. (2008 November) Automated syntax manipulation in RefactorErl. In 14th International Erlang/OTP User Conference, Stockholm, Sweden.
Komondoor, R. & Horwitz, S. (2001) Tool Demonstration: Finding Duplicated Code Using Program Dependences, Lecture Notes in Computer Science, 2028. New York, NY: LNCS.
Lahoda, J., Bečička, J. & Ruijs, R. B. (2012) Custom declarative refactoring in NetBeans: Tool demonstration. In Proceedings of the Fifth Workshop on Refactoring Tools (WRT '12), Rapperswil, Switzerland. New York, NY: ACM, pp. 6364.
Lämmel, R. (2000) Reuse by program transformation. In Selected Papers from the 1st Scottish Functional Programming Workshop, Functional Programming Trends series, vol. 1, Michaelson, G. & Trinder, P. (eds). Bristol, UK: Intellect, pp. 143152.
Lämmel, R. & Visser, J. (2003) A Strafunski Application Letter, In Proceedings of the 5th International Symposium on Practical Aspects of Declarative Languages. PADL'03, Springer Verlag, Berlin and New York.
Leitão, A. P. T. de M. C. (2002) A formal pattern language for refactoring of Lisp programs. In Proceedings of the Sixth European Conference on Software Maintenance and Reengineering (CSMR '02), Budapest, Hungary. Washington, DC: IEEE Computer Society.
Li, H. (2006) Refactoring Haskell programs. PhD thesis, School of Computing, University of Kent, Canterbury, Kent, UK.
Li, H., Lindberg, A., Schumacher, A. & Thompson, S. (2009) Improving Your Test Code with Wrangler. Tech. Rept. 4-09, School of Computing, University of Kent, Canterbury, Kent, UK.
Li, Z., Lu, S. & Myagmar, S. (2006) CP-miner: Finding copy-paste and related bugs in large-scale software code. IEEE Trans. Softw. Eng. 32 (3), 176192.
Li, H. & Thompson, S. (2005) Formalisation of Haskell refactorings. In Trends in Functional Programming, van Eekelen, M. & Hammond, K. (eds). Tallinn, Estonia. Bristol, UK: Intellect, pp. 95110.
Li, H. & Thompson, S. (2006) A comparative study of refactoring Haskell and Erlang programs. In Sixth IEEE International Workshop on Source Code Analysis and Manipulation (SCAM'06), September 27–29, Sheraton Society Hill, Philadelphia, PA, Di Penta, M. & Moonen, L. (eds). New York, NY: IEEE, pp. 197206.
Li, H. & Thompson, S. (2007) Testing Erlang refactorings with quickcheck. In 19th International Symposium on Implementation and Application of Functional Languages (IFL 2007), Freiburg, Germany. New York, NY: LNCS.
Li, H. & Thompson, S. (2009a). Clone detection and removal for Erlang/OTP within a refactoring environment. In ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM'09), Savannah, GA, USA.
Li, H. & Thompson, S. (2009b) Testing-framework-aware refactoring. In 3rd ACM Workshop on Refactoring Tools, Orlando, FLA, USA, pp. 14.
Li, H. & Thompson, S. (2010a) Refactoring support for modularity maintenance in Erlang. In 10th IEEE International Working Conference on Source Code Analysis and Manipulation, Vunju, J. & Marinescu, C. (eds), Timisoara, Romania. New York, NY: IEEE Computer Society, pp. 157166.
Li, H. & Thompson, S. (2010b). Similar code detection and elimination for Erlang programs. In Twelfth International Symposium on Practical Aspects of Declarative Languages (PADL10), Madrid, Spain.
Li, H. & Thompson, S. (2011a). A User-Extensible Refactoring Tool for Erlang Programs. Tech. Rept. 2011-04, School of Computing, University of Kent, Canterbury, Kent, UK.
Li, H. & Thompson, S. (2011b). Incremental code clone detection and elimination for Erlang programs. In Proceedings of the Conference on Fundamental Approaches to Software Engineering (FASE'11), Giannakopoulou, D. & Orejas, F. (eds), Saarbrücken, Germany. New York, NY: Springer.
Li, H. & Thompson, S. (2012a). A domain-specific language for scripting refactoring in Erlang. In Fundamental Approaches to Software Engineering (FASE 2012), deLara, J. Lara, J. & Zisman, A. (eds). Lecture Notes in Computer Science, Tallinn, Estonia. New York, NY: Springer, vol. 7212, pp. 294297.
Li, H. & Thompson, S. (2012b). Automated API migration in a user-extensible refactoring tool for Erlang programs. In Automated Software Engineering (ASE'12), Menzies, T. & Saeki, M. (eds), Essen, Germany. New York, NY: IEEE Computer Society.
Li, H. & Thompson, S. (2012c). Let's make refactoring tools user-extensible! In Proceedings of the Fifth Workshop on Refactoring Tools (WRT '12), Rapperswil, Switzerland. New York, NY: ACM, pp. 3239.
Li, H., Thompson, S. & Arts, T. (2011) Extracting properties from test cases by refactoring. In Refactoring and Testing Workshop (RefTest 2011), Counsell, S. (ed). New York, NY: IEEE Digital Library.
Li, H., Thompson, S., Orosz, G. & Töth, M. (2008) Refactoring with wrangler, updated. In ACM SIGPLAN Erlang Workshop 2008, Victoria, British Columbia, Canada.
Lövei, L. (2009) Automated module interface upgrade. In Proceedings of the 2009 ACM SIGPLAN Erlang Workshop, Edinburgh, Scotland. New York, NY: ACM, pp. 1121.
Lövei, L., Hoch, C., Köllő, H., Nagy, T., Nagyné-Víg, A., Horpácsi, D., Kitlei, R. & Király, R. (2008) Refactoring module structure. In Proceedings of the 7th ACM SIGPLAN Erlang Workshop, Victoria, British Columbia, Canada. New York, NY: ACM, pp. 8389.
Marlow, S. (ed). (2010) Haskell 2010 language report. Available at: http://www.haskell.org/onlinereport/haskell2010/. Accessed 6 September 2013.
Mens, T. & Tourwé, T. (2004) A survey of software refactoring. IEEE Trans. Softw. Eng. 30, 126139.
Meszaros, G. (2007) xUnit Test Patterns: Refactoring Test Code. Boston, MA: Addison-Wesley.
Mitchell, N. (2011) HLint Manual. Available at: http://community.haskell.org/~ndm/hlint/. Accessed 6 September 2013.
Murphy-Hill, E., Parnin, C. & Black, A. P. (2009) How we refactor, and how we know it. In Proceedings of the 31st International Conference on Software Engineering (ICSE '09), Vancouver, British Columbia, Canada. Washington, DC: IEEE Computer Society, pp. 287297.
NetBeans. (n.d.) Wiki entry on refactoring. Available at: http://wiki.netbeans.org/Refactoring. Accessed 6 September 2013.
Nguyen, T. T., Nguyen, H. A., Al-Kofahi, J. M., Pham, N. H. & Nguyen, T. N. (2009) Scalable and incremental clone detection for evolving software. In International Conference on Software Maintenance (ICSM'09), Edmonton, Canada.
Opdyke, W. F. (1992) Refactoring Object-Oriented Frameworks. PhD thesis, University of Illinois at Urbana-Champaign, IL.
ReSharper. (n.d.) Introductory web page. Available at: http://www.jetbrains.com/resharper/. Accessed 6 September 2013.
Roberts, D., Brant, J. & Johnson, R. (1997) A refactoring tool for smalltalk. Theory Pract. Object Syst. 3 (4), 253263.
Roy, C. K., et al. (2009) Comparison and evaluation of code clone detection techniques and tools: A qualitative approach. Sci. Comput. Program. 74 (7), 470495.
Sagonas, K. (2007) Detecting defects in Erlang programs using static analysis. In Proceedings of the 9th International ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming (PPDP '07), Wrocł aw, Poland. New York, NY: ACM, pp. 3737.
Sagonas, K. & Avgerinos, T. (2009) Automatic refactoring of Erlang programs. In Principles and Practice of Declarative Programming (PPDP'09), Coimbra, Portugal. New York, NY: ACM, pp. 1324.
Schaefer, M. & deMoor, O. Moor, O. (2010) Specifying and implementing refactorings. In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA '10), Reno, Nevada, USA. New York, NY: ACM, pp. 286301.
Soares, G. (2012) Automated behavioral testing of refactoring engines. In Proceedings of the 3rd Annual Conference on Systems, Programming, and Applications: Software for Humanity (SPLASH '12), Tucson, Arizona, USA. New York, NY: ACM, pp. 4952.
Sommerlad, P. (ed). (2012) Proceedings of the Fifth Workshop on Refactoring Tools (WRT '12), Rapperswil, Switzerland. New York, NY: ACM.
Sultana, N. & Thompson, S. (2008) Mechanical verification of refactorings. In Workshop on Partial Evaluation and Program Manipulation, San Francisco, California, USA. New York, NY: ACM SIGPLAN.
Thompson, S. & Reinke, C. (2003) A case study in refactoring functional programs. Brazilian Symposium on Programming Languages, Ouro Preto, MG, Brazil, May 2830.
Tóth, M. & Bozó, I. (2012) Static analysis of complex software systems implemented in Erlang. In Central European Functional Programming Summer School (CEFP 2011), Revisited Selected Lectures, Lecture Notes in Computer Science, vol. 7241. New York, NY: Springer-Verlag, pp. 451514.
Tullsen, M. (2002) PATH, A Program Transformation System for Haskell. PhD thesis, Yale University, Yale, CT.
Ubayashi, N., Piao, J., Shinotsuka, S. & University, T. (2008) Contract-based verification for aspect-oriented refactoring. In 1st International Conference on Software Testing, Verification, and Validation, 2008, Lillehammer, Norway. New York, NY: IEEE Press.
Vakilian, M., Chen, N., Negara, S., Rajkumar, B. A., Bailey, B. P. & Johnson, R. E. (2012) Use, disuse, and misuse of automated refactorings. In Proceedings of the 2012 International Conference on Software Engineering (ICSE 2012), Zurich, Switzerland. New York, NY: IEEE Press, pp. 233243.
Yin, X., Knight, J. & Weimer, W. (2009) Exploiting refactoring in formal verification. In IEEE/IFIP International Conference on Dependable Systems Networks (DSN '09), Estoril, Lisbon, Portugal. New York, NY: IEEE Press.

Metrics

Full text views

Total number of HTML views: 0
Total number of PDF views: 0 *
Loading metrics...

Abstract views

Total abstract views: 0 *
Loading metrics...

* Views captured on Cambridge Core between <date>. This data will be updated every 24 hours.

Usage data cannot currently be displayed

Refactoring tools for functional languages

  • SIMON THOMPSON (a1) and HUIQING LI (a1)
Submit a response

Discussions

No Discussions have been published for this article.

×

Reply to: Submit a response


Your details


Conflicting interests

Do you have any conflicting interests? *