1 / 21

Refactoring Erlang Programs

Refactoring Erlang Programs. Huiqing Li Simon Thompson University of Kent. Zoltán Horváth Eötvös Loránd Univ. Overview. Example refactorings General observations Challenges of Erlang Our two implementations Next steps … and conclusion. Soft-ware. There’s no single correct design …

Download Presentation

Refactoring Erlang Programs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

  4. -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). Generalisation Generalisation and renaming -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). EUC 2006

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

  6. -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). Generalisation EUC 2006

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

  8. 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? Refactoring = Transformation + Condition EUC 2006

  9. Transformations full stop one EUC 2006

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

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

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

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

  14. 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. EUC 2006

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

  16. Architectures EUC 2006

  17. Wrangler in Emacs EUC 2006

  18. Wrangler in Emacs EUC 2006

  19. 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? AST vsdatabase EUC 2006

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

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

More Related