Presentation is loading. Please wait.

Presentation is loading. Please wait.

Refactoring Erlang Programs Huiqing Li Simon Thompson University of Kent Zoltán Horváth Eötvös Loránd Univ.

Similar presentations


Presentation on theme: "Refactoring Erlang Programs Huiqing Li Simon Thompson University of Kent Zoltán Horváth Eötvös Loránd Univ."— Presentation transcript:

1 Refactoring Erlang Programs Huiqing Li Simon Thompson University of Kent Zoltán Horváth Eötvös Loránd Univ.

2 EUC 2006 Overview Example refactorings General observations Challenges of Erlang Our two implementations Next steps … and conclusion

3 EUC 2006 Soft-ware There’s no single correct design … … different options for different situations. Maintain flexibility as the system evolves.

4 EUC 2006 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

5 EUC 2006 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]).

6 EUC 2006 Generalisation -export([printList/1]). printList([H|T]) -> io:format("~p\n",[H]), printList(T); printList([]) -> true. -export([printList/1]). printList(F,[H|T]) -> F(H), printList(F, T); printList(F,[]) -> true. printList(L) -> printList( fun(H) -> io:format("~p\n", [H]) end, L).

7 EUC 2006 Asynchronous to synchronous pid! {self(),msg} {Parent,msg} -> body pid! {self(),msg}, receive {pid, ok}-> ok {Parent,msg} -> Parent! {self(),ok}, body

8 EUC 2006 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?

9 EUC 2006 Transformations fullstopone

10 EUC 2006 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."

11 EUC 2006 Tool support Bureaucratic and diffuse. Tedious and error prone. Semantics: scopes, types, modules, … Undo/redo Enhanced creativity

12 EUC 2006 Static vs dynamic Aim to check conditions statically. Static analysis tools possible … but some aspects intractable: e.g. dynamically manufactured atoms. Conservative vs liberal. Compensation?

13 EUC 2006 Compensate or fail? -export([oldFun/1, newFun/1]). oldFun(L) -> newFun(L). newFun(L) -> … …. -export([newFun/1]). newFun(L) -> … …. or?

14 EUC 2006 Erlang refactoring: challenges Multiple binding occurrences of variables. Indirect function call or function spawn: apply (lists, rev, [[a,b,c]]) Multiple arities … multiple functions: rev/1 Concurrency Refactoring within a design library: OTP. Side-effects.

15 EUC 2006 Haskell vs Erlang refactorings Haskell RefactoringsErlang Refactorings Type/type class-related refactorings. Monad-related refactorings... Introduce/remove concurrency, Asynchronous/synchronous communication, Refactoring to design patterns,...... Renaming, Removing unused definitions/parameters, Swapping arguments, Introduce new definitions,......

16 EUC 2006 Architectures

17 EUC 2006 Wrangler in Emacs

18 EUC 2006 Wrangler in Emacs

19 EUC 2006 AST vs database Lightweight. Better integration with interactive tools (e.g. emacs). Undo/redo external? Ease of implementing conditions? Higher entry cost. Better for a series of refactorings on a large project. Transaction support. Ease of implementing transformations?

20 EUC 2006 Next steps Refactor concurrency styles introduction Refactor Erlang/OTP within OTP towards OTP Release systems by the end of January. Performance comparisons on real systems.

21 EUC 2006 Ackonwledgements EPSRC ELTE IKKK, CNL Ericsson Hungary Bolyai Res Fellowship syntax-tools distel


Download ppt "Refactoring Erlang Programs Huiqing Li Simon Thompson University of Kent Zoltán Horváth Eötvös Loránd Univ."

Similar presentations


Ads by Google