{"id":236,"date":"2009-02-20T17:23:36","date_gmt":"2009-02-21T01:23:36","guid":{"rendered":"http:\/\/www.sauria.com\/blog\/2009\/02\/20\/refactoring-in-the-functional-programming-world\/"},"modified":"2020-04-13T10:29:27","modified_gmt":"2020-04-13T18:29:27","slug":"refactoring-in-the-functional-programming-world","status":"publish","type":"post","link":"https:\/\/www.sauria.com\/blog\/2009\/02\/20\/refactoring-in-the-functional-programming-world\/","title":{"rendered":"Refactoring in the Functional Programming world"},"content":{"rendered":"<p>I&#8217;m an Emacs guy. I was first exposed to Emacs back in 1984 on a VAX running BSD. This was prior to GNU Emacs, so the Emacs that I saw was James Gosling&#8217;s Emacs. At the time, I was working on a compiler for a functional programming language called SUPER, which was evaluated using combinator graph reduction.<\/p>\n<p>For many years, and across many languages, including Scheme, C, C++, Perl, TCL, and Java, Emacs was my tool of choice. My hands had the muscle memory for the keystrokes, and over those years I accumulated a file full of Emacs-Lisp customizations for Emacs (by this time, mostly GNU Emacs). When Eclipse started to support refactoring I started using Eclipse as my primary tool for editing Java programs. Refactoring is an example of the kind of high leverage features that I want in my programming tool set.<\/p>\n<p>A few days ago I found some gems <a href=\"http:\/\/www.nabble.com\/Re%3A--scala--Re%3A-Scala%3A-Great-potential%2C-but-not-ready-for-production-p22082676.html\">buried<\/a> in a thread on the Scala mailing list. Dave Griffith has been accumulating a list of refactorings for Scala. Here&#8217;s his complete list:<\/p>\n<blockquote>\n<p>Curry Method (split a parameter list, and the arg lists of all callers).<\/p>\n<p>Uncurry Method (merge split parameter list, including merging the arg lists of callers. If method is called with partial args, either complain or automatically create a helper method which represents the partial application, and replace partial calls with it.)<\/p>\n<p>Extract Trait (including searching for other classes which can have the same trait extracted. Tricky with super calls, but not impossible)<\/p>\n<p>Split Trait (splits trait into two traits (putting in self-types if needed), change all extending classes to extend both traits)<\/p>\n<p>Extract Extractor (select a pattern, automatically create an extractor)<\/p>\n<p>Extract Closure (similar to extract method, but creating a function object)<\/p>\n<p>Introduce by-name parameter<\/p>\n<p>Extract type definition (obvious)<\/p>\n<p>Merge nested for-comprehensions into single for-comprehension (and converse)<\/p>\n<p>Split guard from for-comprehension into nested if (and converse)<\/p>\n<p>Convert for-comprehension into map\/filter\/flatmap chain (and converse)<\/p>\n<p>Wrap parameter as Option (converting null checks, etc.)<\/p>\n<p>Convert instanceOf\/asInstance pair to match<\/p>\n<p>Replace case clause with if body to guarded case clause(s)<\/p>\n<\/blockquote>\n<p>I was particularly interested in those refactorings related to functional\/higher-order programming and pattern matching. Between the surge of interest in Scala, F# and Haskell, it looks like there&#8217;s room for some more work in refactoring.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m an Emacs guy. I was first exposed to Emacs back in 1984 on a VAX running BSD. This was prior to GNU Emacs, so the Emacs that I saw was James Gosling&#8217;s Emacs. At the time, I was working on a compiler for a functional programming language called SUPER, which was evaluated using combinator [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[26,6,117],"tags":[118,152,157],"class_list":["post-236","post","type-post","status-publish","format-standard","hentry","category-programming","category-programming-languages","category-tools","tag-functional-programming","tag-programming","tag-tools"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/phUVc-3O","_links":{"self":[{"href":"https:\/\/www.sauria.com\/blog\/wp-json\/wp\/v2\/posts\/236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sauria.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sauria.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sauria.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sauria.com\/blog\/wp-json\/wp\/v2\/comments?post=236"}],"version-history":[{"count":1,"href":"https:\/\/www.sauria.com\/blog\/wp-json\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":480,"href":"https:\/\/www.sauria.com\/blog\/wp-json\/wp\/v2\/posts\/236\/revisions\/480"}],"wp:attachment":[{"href":"https:\/\/www.sauria.com\/blog\/wp-json\/wp\/v2\/media?parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sauria.com\/blog\/wp-json\/wp\/v2\/categories?post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sauria.com\/blog\/wp-json\/wp\/v2\/tags?post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}