{"id":309,"date":"2009-05-14T09:46:01","date_gmt":"2009-05-14T14:46:01","guid":{"rendered":"http:\/\/vgable.com\/blog\/2009\/05\/14\/emergent-libraries\/"},"modified":"2009-10-20T08:01:34","modified_gmt":"2009-10-20T13:01:34","slug":"emergent-libraries","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2009\/05\/14\/emergent-libraries\/","title":{"rendered":"Emergent Libraries"},"content":{"rendered":"<p>I have latched onto an idea, but don&#8217;t have the resources to follow up on it: could <a href=\"http:\/\/llvm.org\/\">a static-analysis tool<\/a> identify repeated patterns of code, across <a href=\"http:\/\/github.com\/\">many<\/a> <a href=\"http:\/\/code.google.com\/\">code<\/a> <a href=\"http:\/\/sourceforge.net\/\">bases<\/a>, that should be extracted out as subroutines and higher-level functions? How universal would these &#8220;emergent libraries&#8221; be?<\/p>\n<p>My inspiration here is <cite>Section 4.1 Identifying Common Functions<\/cite>, in the <strong>excellent paper<\/strong> <a href=\"http:\/\/cr.yp.to\/qmail\/qmailsec-20071101.pdf\"><cite>Some Thoughts on Security After Ten Years of qmail 1.0<\/cite> (PDF)<\/a>, by Daniel J. Bernstein,<\/p>\n<blockquote><p> Most programmers would never bother to create such a small  function. But several words of code are saved whenever one  occurrence of the <code>dup2()<\/code>\/<code>close()<\/code> pattern is replaced with  one call to <code>fd_move();<\/code> replacing a dozen occurrences saves  considerably more code than were spent writing the function  itself. (The function is also <strong>a natural target for tests<\/strong>.)  The same benefit scales to larger systems and to a huge variety of functions; <code>fd_move()<\/code> is just one example. In many cases an automated scan for common operation sequences  can suggest <strong>helpful new functions<\/strong>, but even without automation I frequently find myself thinking \u201cHaven\u2019t I seen this  before?\u201d and extracting a new function out of existing code.<\/p><\/blockquote>\n<p>What&#8217;s particularly fascinating to me are <strong>the <em>new<\/em> operations we might find<\/strong>.<\/p>\n<p>Before I was exposed to the <a href=\"http:\/\/www.haskell.org\/onlinereport\/standard-prelude.html\">Haskell prelude<\/a> I hadn&#8217;t known about the fundamentally useful <a href=\"http:\/\/en.wikipedia.org\/wiki\/Foldl\"><code>foldl<\/code> and <code>foldr<\/code><\/a> operations.  I had written dozens of programs that used accumulation, but it&#8217;s generalization hadn&#8217;t occurred to me &#8212; and probably never would have. Static analysis can help uncover generalizations that we might have missed, or didn&#8217;t think were important, but turn out <em>in practice<\/em> to be widely used operations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have latched onto an idea, but don&#8217;t have the resources to follow up on it: could a static-analysis tool identify repeated patterns of code, across many code bases, that should be extracted out as subroutines and higher-level functions? How universal would these &#8220;emergent libraries&#8221; be? My inspiration here is Section 4.1 Identifying Common Functions, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,11],"tags":[613,326,419,417,242,169,418],"class_list":["post-309","post","type-post","status-publish","format-standard","hentry","category-programming","category-research","tag-c","tag-functional-programming","tag-llvm","tag-programming-language-design","tag-programming-style","tag-software-development","tag-static-analysis"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=309"}],"version-history":[{"count":2,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/309\/revisions"}],"predecessor-version":[{"id":467,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/309\/revisions\/467"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}