Hostname: page-component-78c5997874-v9fdk Total loading time: 0 Render date: 2024-11-05T05:56:14.225Z Has data issue: false hasContentIssue false

Refactoring tools for functional languages

Published online by Cambridge University Press:  22 October 2013

SIMON THOMPSON
Affiliation:
School of Computing, University of Kent, Kent, UK (e-mail: [email protected], [email protected])
HUIQING LI
Affiliation:
School of Computing, University of Kent, Kent, UK (e-mail: [email protected], [email protected])
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

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.

Type
Articles
Copyright
Copyright © Cambridge University Press 2013 

References

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.Google Scholar
Armstrong, J. (2007) Programming Erlang: Software for a Concurrent World. The Pragmatic Bookshelf.Google Scholar
Baker, B. S. (1992) A program for identifying duplicated code. Comput. Sci. Stat. 24, 4957.Google Scholar
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.CrossRefGoogle Scholar
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.CrossRefGoogle Scholar
Brown, C. (2008) Tool Support for Refactoring Haskell Programs. PhD thesis, School of Computing, University of Kent, Kent, UK.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
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.CrossRefGoogle Scholar
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.Google Scholar
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.CrossRefGoogle Scholar
Chassell, R. J. (2004) An Introduction to Programming in Emacs Lisp. Boston, MA: Free Software Foundation.Google Scholar
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.CrossRefGoogle Scholar
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.Google Scholar
Darlington, J. (1982) Program transformation. In Functional Programming and Its Applications, Darlington, J., Henderson, P. & Turner, D. A. (eds), Cambridge, UK: Cambridge University Press.Google Scholar
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.Google Scholar
Erlang E-learning. (2011) Online e-Learning System. Available at: https://elearning.erlang-solutions.com. Accessed 6 September 2013.Google Scholar
ErlIDE. (n.d.) The Erlang IDE. Available at: http://erlide.sourceforge.net/. Accessed 6 September 2013.Google Scholar
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.Google Scholar
Fowler, M. (1999) Refactoring: Improving the Design of Existing Code. Object Technology Series. Boston, MA: Addison-Wesley.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
GHC API. (n.d.) GHC Commentary. Available at: http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/API. Accessed 6 September 2013.Google Scholar
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.Google Scholar
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.Google Scholar
Griswold, W. G. & Notkin, D. (1993) Automated assistance for program restructuring. ACM Trans. Softw. Eng. Methodol. 2, 228269.CrossRefGoogle Scholar
Hackage. (2010) HackageDB. Available at: http://hackage.haskell.org/. Accessed 6 September 2013.Google Scholar
Hallgren, T. (2003) Haskell tools from the programatica project (Demo Abstract). In ACM Sigplan Haskell Workshop, Uppsala, Sweden. New York, NY: ACM Press.Google Scholar
HaRe. (n.d.) The HaRe system. Available at: http://www.cs.kent.ac.uk/projects/refactor-fp/hare.html. Accessed 6 September 2013.Google Scholar
Haskell Platform. (2010) The Haskell Platform. Available at: http://hackage.haskell.org/platform/. Accessed 6 September 2013.Google Scholar
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.CrossRefGoogle Scholar
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.Google Scholar
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.Google Scholar
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.CrossRefGoogle Scholar
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.Google Scholar
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.CrossRefGoogle Scholar
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.Google Scholar
Komondoor, R. & Horwitz, S. (2001) Tool Demonstration: Finding Duplicated Code Using Program Dependences, Lecture Notes in Computer Science, 2028. New York, NY: LNCS.Google Scholar
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.CrossRefGoogle Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
Li, H. (2006) Refactoring Haskell programs. PhD thesis, School of Computing, University of Kent, Canterbury, Kent, UK.Google Scholar
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.Google Scholar
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.CrossRefGoogle Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
Li, H. & Thompson, S. (2009b) Testing-framework-aware refactoring. In 3rd ACM Workshop on Refactoring Tools, Orlando, FLA, USA, pp. 14.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
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.CrossRefGoogle Scholar
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.Google Scholar
Li, H., Thompson, S., Orosz, G. & Töth, M. (2008) Refactoring with wrangler, updated. In ACM SIGPLAN Erlang Workshop 2008, Victoria, British Columbia, Canada.Google Scholar
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.Google Scholar
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.CrossRefGoogle Scholar
Marlow, S. (ed). (2010) Haskell 2010 language report. Available at: http://www.haskell.org/onlinereport/haskell2010/. Accessed 6 September 2013.Google Scholar
Mens, T. & Tourwé, T. (2004) A survey of software refactoring. IEEE Trans. Softw. Eng. 30, 126139.CrossRefGoogle Scholar
Meszaros, G. (2007) xUnit Test Patterns: Refactoring Test Code. Boston, MA: Addison-Wesley.Google Scholar
Mitchell, N. (2011) HLint Manual. Available at: http://community.haskell.org/~ndm/hlint/. Accessed 6 September 2013.Google Scholar
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.Google Scholar
NetBeans. (n.d.) Wiki entry on refactoring. Available at: http://wiki.netbeans.org/Refactoring. Accessed 6 September 2013.Google Scholar
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.Google Scholar
Opdyke, W. F. (1992) Refactoring Object-Oriented Frameworks. PhD thesis, University of Illinois at Urbana-Champaign, IL.Google Scholar
ReSharper. (n.d.) Introductory web page. Available at: http://www.jetbrains.com/resharper/. Accessed 6 September 2013.Google Scholar
Roberts, D., Brant, J. & Johnson, R. (1997) A refactoring tool for smalltalk. Theory Pract. Object Syst. 3 (4), 253263.3.0.CO;2-T>CrossRefGoogle Scholar
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.CrossRefGoogle Scholar
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.Google Scholar
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.Google Scholar
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.CrossRefGoogle Scholar
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.CrossRefGoogle Scholar
Sommerlad, P. (ed). (2012) Proceedings of the Fifth Workshop on Refactoring Tools (WRT '12), Rapperswil, Switzerland. New York, NY: ACM.CrossRefGoogle Scholar
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.Google Scholar
Thompson, S. & Reinke, C. (2003) A case study in refactoring functional programs. Brazilian Symposium on Programming Languages, Ouro Preto, MG, Brazil, May 2830.Google Scholar
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.Google Scholar
Tullsen, M. (2002) PATH, A Program Transformation System for Haskell. PhD thesis, Yale University, Yale, CT.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.