WRT 2007 Refactoring Functional Programs Huiqing Li Simon Thompson Computing Lab Chris Brown Claus Reinke University of Kent.

Slides:



Advertisements
Similar presentations
HaRe The Haskell Refactorer Huiqing Li Claus Reinke Simon Thompson Computing Lab, University of Kent
Advertisements

Tool Support for Refactoring Functional Programs Huiqing Li Claus Reinke Simon Thompson Computing Lab, University of Kent
Progress on ‘HaRe: The Haskell Refactorer’ Huiqing Li, Claus Reinke, Simon Thompson Computing Laboratory, University of Kent Refactoring is the process.
An Abstract Interpretation Framework for Refactoring P. Cousot, NYU, ENS, CNRS, INRIA R. Cousot, ENS, CNRS, INRIA F. Logozzo, M. Barnett, Microsoft Research.
Debugging Natural Semantics Specifications Adrian Pop and Peter Fritzson Programming Environment Laboratory Department of Computer and Information Science.
Chapter 5: Abstraction, parameterization, and qualification Xinming (Simon) Ou CIS 505: Programming Languages Kansas State University Fall
Extended Static Checking for Haskell (ESC/Haskell) Dana N. Xu University of Cambridge advised by Simon Peyton Jones Microsoft Research, Cambridge.
CS7100 (Prasad)L16-7AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
1 Dependent Types for Termination Verification Hongwei Xi University of Cincinnati.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
CS 325: Software Engineering January 13, 2015 Introduction Defining Software Engineering SWE vs. CS Software Life-Cycle Software Processes Waterfall Process.
LIFE CYCLE MODELS FORMAL TRANSFORMATION
Refactoring Erlang Programs Huiqing Li Simon Thompson University of Kent.
Improving your (test) code with Wrangler Huiqing Li, Simon Thompson University of Kent Andreas Schumacher Ericsson Software Research Adam Lindberg Erlang.
Property-based Testing – ProTest FP7 Strep John Derrick University of Sheffield, and members of the ProTest team.
Train Control Language Teaching Computers Interlocking By: J. Endresen, E. Carlson, T. Moen1, K. J. Alme, Haugen, G. K. Olsen & A. Svendsen Synthesizing.
The Formalisation of Haskell Refactorings Huiqing Li Simon Thompson Computing Lab, University of Kent
Refactoring Haskell Programs Huiqing Li Computing Lab, University of Kent
COMP205 Comparative Programming Languages Part 1: Introduction to programming languages Lecture 3: Managing and reducing complexity, program processing.
Generative type abstraction and type-level computation (Wrestling with System FC) Stephanie Weirich, Steve Zdancewic University of Pennsylvania Dimitrios.
The Haskell Refactorer, HaRe, and its API Huiqing Li Claus Reinke Simon Thompson Computing Lab, University of Kent
Evaluate the Usability of a User Interface Tool or Toolkit Assignment 1 Assignment 1 Evaluate the Usability of a User Interface Tool or Toolkit T. H Ranasinghe.
A Formal Model of Modularity in Aspect-Oriented Programming Jonathan Aldrich : Objects and Aspects Carnegie Mellon University.
CASE Tools And Their Effect On Software Quality Peter Geddis – pxg07u.
1 Abstract Syntax Tree--motivation The parse tree –contains too much detail e.g. unnecessary terminals such as parentheses –depends heavily on the structure.
© 2012 IBM Corporation Rational Insight | Back to Basis Series Chao Zhang Unit Testing.
C++ Code Analysis: an Open Architecture for the Verification of Coding Rules Paolo Tonella ITC-irst, Centro per la Ricerca Scientifica e Tecnologica
Erlang/QuickCheck Thomas Arts, IT University John Hughes, Chalmers University Gothenburg.
Hands-on Refactoring with Wrangler Simon Thompson Huiqing Li, Xingdong Bian University of Kent.
CODE. Using Wrangler to refactor Erlang programs and tests Simon Thompson, Huiqing Li Adam Lindberg, Andreas Schumacher University of Kent, Erlang Solutions,
DIY Refactorings in Wrangler Huiqing Li Simon Thompson School of Computing University of Kent.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
Testing in Erlang. Different testing tools EUnit (standard lightweight xUnit solution for Erlang) Common Test (OTP based distributed testing tool) Qucik.
Software testing Main issues: There are a great many testing techniques Often, only the final code is tested.
Supported by ELTE IKKK, Ericsson Hungary, in cooperation with University of Kent Erlang refactoring with relational database Anikó Víg and Tamás Nagy Supervisors:
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Supported by ELTE IKKK, Ericsson Hungary, in cooperation with University of Kent Erlang refactoring with relational database Anikó Víg and Tamás Nagy Supervisors:
Eclipse Eclipse An IDE is an Integrated Development Environment Different IDEs meet different needs – BlueJ, DrJava are designed as teaching.
AdaSlicer: An Ada Program Slicer Ricky E. Sward Department of Computer Science USAF Academy, CO A.T. Chamillard Computer Science.
Refactoring Erlang Programs Huiqing Li Simon Thompson University of Kent Zoltán Horváth Eötvös Loránd Univ.
QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs By Koen Claessen, Juhn Hughes ME: Mike Izbicki.
High Integrity Ada in a UML and C world Peter Amey, Neil White Presented by Liping Cai.
1 An Aspect-Oriented Implementation Method Sérgio Soares CIn – UFPE Orientador: Paulo Borba.
Eclipse 24-Apr-17.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
CS5205Introduction1 CS5205: Foundation in Programming Languages Lecture 0 : Overview Lecturer : Chin Wei Ngan Office : COM2.
Getting the right module structure: using Wrangler to fix your projects Simon Thompson, Huiqing Li School of Computing, University of Kent, UK.
Toulouse, September 2003 Page 1 JOURNEE ALTARICA Airbus ESACS  ISAAC.
Function Definition by Cases and Recursion Lecture 2, Programmeringsteknik del A.
Scalable Clone Detection and Elimination for Erlang Programs Huiqing Li, Simon Thompson University of Kent Canterbury, UK.
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Version 02U-1 Computer Security: Art and Science1 Correctness by Construction: Developing a Commercial Secure System by Anthony Hall Roderick Chapman.
Object Oriented Programming Criteria: P2 Date: 07/10/15 Name: Thomas Jazwinski.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Introduction to Software Analysis CS Why Take This Course? Learn methods to improve software quality – reliability, security, performance, etc.
June 21, Reasoning about explicit strictness in a lazy language using mixed lazy/strict semantics Marko van Eekelen Maarten de Mol Nijmegen University,
Eclipse 27-Apr-17.
A Framework for Automated and Composable Testing of Component-based Services Miguel A. Jiménez, Ángela Villota, Norha M. Villegas, Gabriel Tamura, Laurence.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Functional Programming Lecture 1 - Introduction Professor Muffy Calder.
Towards trustworthy refactoring in Erlang
Software Design Methodology
Module 1: Getting Started
Multiple Aspect Modeling of the Synchronous Language Signal
Functional Programming and Haskell
Functional Programming and Haskell
Presentation transcript:

WRT 2007 Refactoring Functional Programs Huiqing Li Simon Thompson Computing Lab Chris Brown Claus Reinke University of Kent

WRT 2007 Overview Refactoring tools. Functional programming. Haskell and Erlang. Tools and tool building. Tool design. Experience.

WRT 2007 Introduction

WRT 2007 Refactoring tool support Bureaucratic and diffuse. Tedious and error prone. Semantics: scopes, types, modules, … Undo/redo Enhanced creativity

WRT 2007 Functional Programming Values not variables. Expressions not :=. Functions as data. Rich data and types. Controlled side-effects. Declarative descriptions of refactorings.

WRT 2007 Haskell Erlang Strong, static types. Lazy evaluation. Layout sensitive. Concurrency library. Haskell 98 standard. GHC, NHC, Hugs, … Academic, O/S apps. Weak, dynamic types. Strict evaluation. Hot code swap, apply etc. Concurrency built-in. OTP, design patterns. Single system. Industrial applications.

WRT 2007 Generalisation -module (test). -export([f/1]). add_one ([H|T]) -> [H+1 | add_one(T)]; add_one ([]) -> []. f(X) -> add_one(X). -module (test). -export([f/1]). add_one (N, [H|T]) -> [H+N | add_one(N,T)]; add_one (N,[]) -> []. f(X) -> add_one(1, X). -module (test). -export([f/1]). add_int (N, [H|T]) -> [H+N | add_int(N,T)]; add_int (N,[]) -> []. f(X) -> add_int(1, X). Generalisation and renaming

WRT 2007 Generalisation -export([printList/1]). printList([H|T]) -> io:format("~p\n",[H]), printList(T); printList([]) -> true. printList([1,2,3]) -export([printList/2]). printList(F,[H|T]) -> F(H), printList(F, T); printList(F,[]) -> true. printList( fun(H) -> io:format("~p\n", [H]) end, [1,2,3]).

WRT 2007 Asynchronous to synchronous pid! {self(),msg} {Parent,msg} -> body pid! {self(),msg}, receive {pid, ok}-> ok {Parent,msg} -> Parent! {self(),ok}, body

WRT 2007 The tools

WRT 2007 HaRe: the Haskell Refactorer Structural, data type, and module-level. In Haskell: embedded in gvim and emacs. Uses the Programatica framework … … + Strafunski program transformation library.

WRT 2007 Wrangler: refactoring Erlang Structural, data type and module-level refactorings. In Erlang plus emacs. Uses the Erlang system framework … … + untyped Erlang transformation library. Respects aspects of the macro system.

WRT 2007 Design to be usable

WRT 2007 Coverage and Standards De jure standard, Haskell 98, … vs de facto standard Glasgow Haskell. Standard release pattern of Open Source Erlang supervised by the OTP team at Ericsson.

WRT 2007 Integration … with IDEs Back to the future? Programmers' preference for emacs and gvim … … though some IDE interest: Visual Studio, Eclipse, NetBeans. Issue of integration with multiple IDEs: HaRe interfaces with emacs and gvim.

WRT 2007 Integration … with tools Test data sets and test generation. Makefiles, etc. Working with macros e.g. QuickCheck uses Erlang macros … … in a particular idiom.

WRT 2007 Preserving appearance -- This is an example module Main where sumSquares x y = sq x + sq y where sq :: Int->Int sq x = x ^ pow pow = 2 :: Int main = sumSquares module Main where sumSquares x y = sq pow x + sq pow y where pow = 2 :: Int sq :: Int->Int->Int sq pow x = x ^ pow main = sumSquares This is an example module Main where sumSquares x y = sq pow x + sq pow y where pow = 2 :: Int sq :: Int->Int->Int sq pow x = x ^ pow main = sumSquares 10 20

WRT 2007 Experience

WRT 2007 Refactoring = Transformation + Condition Transformation Ensure change at all those points needed. Ensure change at only those points needed. Condition Is the refactoring applicable? Will it preserve the semantics of the module? the program?

WRT 2007 Condition > Transformation Renaming an identifier "The existing binding structure should not be affected. No binding for the new name may intervene between the binding of the old name and any of its uses, since the renamed identifier would be captured by the renaming. Conversely, the binding to be renamed must not intervene between bindings and uses of the new name."

WRT 2007 Which refactoring exactly? Generalise f by making 23 a parameter of f: f x = 23 + g x where g x = x con con = 23 This one occurrence? All occurrences (in the body)? Some of the occurrences … to be selected.

WRT 2007 Compensate or fail? Lift g to a global definition in f x = x + g x where g x = x + con con = 37 Fail because con not defined globally? Add extra parameter to g, and pass in con? Lift con as well?

WRT 2007 Compensate or crash? -export([oldFun/1, newFun/1]). oldFun(L) -> newFun(L). newFun(L) -> … …. -export([newFun/1]). newFun(L) -> … …. or?

WRT 2007 Infrastructure Requirement for heavyweight infrastructure. Best not to write your own! Compiler APIs. Often non-existent. Can change with releases. Clearly system specific. Tracking changes in systems and libraries.

WRT 2007 APIs … programmer / user API in Haskell / Erlang to support user- programmed refactorings: declarative, straightforward and complete but relatively low-level. Higher-level combining forms? OK for transformations, but need a separate condition language?

WRT 2007 Verification and validation Possible to write formal proofs of correctness: check conditions and transformations different levels of abstraction possibly-name binding substitution for renaming etc. more abstract formulation for e.g. data type changes. Use of QuickCheck to verify refactorings in both Haskell and Erlang.

WRT 2007 Future work Concurrency. Refactoring within a design library: OTP. Side-effects. Working with Erlang Training and Consulting. Data-type refactorings in Haskell. Integration with other IDEs / compilers. Test and property refactoring.

WRT 2007 Conclusion