{"id":88,"date":"2008-02-25T19:40:32","date_gmt":"2008-02-26T00:40:32","guid":{"rendered":"http:\/\/alarmingdevelopment.org\/?p=88"},"modified":"2008-03-22T19:02:05","modified_gmt":"2008-03-23T00:02:05","slug":"the-modular-transformation-challenge","status":"publish","type":"post","link":"https:\/\/alarmingdevelopment.org\/?p=88","title":{"rendered":"The modular transformation challenge"},"content":{"rendered":"<p>I got some good feedback here on my last paper. I want to see if I can get some equally good advice about what my next paper should be. My past papers have been about making programming easier. I would like to move on to making programming more powerful. Specifically, by making transformations and views a fundamental language feature. I have thought of a simple challenge problem that I might use to motivate and evaluate this idea. Please let me know whether you agree that a) this is actually an unsolved problem, and b) whether it is a worthwhile challenge. If there is interest, I will post this onto some collaborative editing surface. Thanks!\n<\/p>\n<p><!--more--><\/p>\n<hr \/>\n<p>It is often suggested that software designs can profitably be seen as the transformation of information from one structure into another. Such transformations are also called mappings or views. The appeal of this idea is the potential to construct complex systems by modularly combining simple transformations. But our programming languages do not express transformations very well, forfeiting their potential.\n<\/p>\n<p>I want to present a simple challenge problem to motivate and evaluate techniques of programming with transformations. This challenge is the archetypal problem of presenting data fields on a screen form, and the input of user changes to that data. Conceptually, this is merely a matter of mapping the internal data structure to a screen-form structure, and then inversely mapping user inputs back again. But actual practice typically involves complex frameworks and multiple languages that are not structured in terms of transformations.\n<\/p>\n<p>We start with a simple record of data fields. Expressed in Java, it is:\n<\/p>\n<blockquote>\n<pre><code>class Customer {\r\n  int id;\r\n  String name;\r\n  String phone;\r\n  String address;\r\n}<\/code><\/pre>\n<\/blockquote>\n<p>For this challenge, the data can alternatively be expressed in any preferred format, such as XML:\n<\/p>\n<blockquote><p><code><\/p>\n<pre>\r\n&lt;Customer&gt;\r\n  &lt;id&gt;1234&lt;\/id&gt;\r\n  &lt;name&gt;John Smith&lt;\/name&gt;\r\n  &lt;phone&gt;555-1212&lt;\/phone&gt;\r\n  &lt;address&gt;32 Vassar St\r\n  Cambridge, MA 02139\r\n  &lt;\/address&gt;\r\n&lt;\/Customer&gt;<\/pre>\n<p><\/code><\/p><\/blockquote>\n<p>The problem is to transform an instance of this data into a screen form, using any desired presentation language. In HTML, the result would be:\n<\/p>\n<blockquote><p><code><\/p>\n<pre>&lt;form method=\"post\" action=\"\"&gt;\r\n  id: &lt;input name=\"id\" type=\"text\" value=\"1234\"\/&gt;&lt;p&gt;\r\n  name: &lt;input name=\"name\" type=\"text\" value=\"John Smith\"\/&gt;&lt;p&gt;\r\n  phone: &lt;input name=\"phone\" type=\"text\" value=\"555-1212\" \/&gt;&lt;p&gt;\r\n  address: &lt;textarea name=\"address\" rows=\"3\"&gt;32 Vassar St\r\n  Cambridge, MA 02139&lt;\/textarea&gt;&lt;p&gt;\r\n&lt;\/form&gt;<\/pre>\n<p><\/code><\/p><\/blockquote>\n<p>The challenge comes from the fact that both the data definition and the form layout can change. The data definition will evolve due to changing requirements. The form layout will be customized to add features and improve the usability of the presentation. These changes pose a dilemma. If we generate the form from the data, it is easy to accommodate change to the data, but hard to allow change to the form. On the other hand, we can sever the relationship between the data and the form, maintaining them as independent artifacts, and so easily customize the form, but changing the data will then require manual adaptation of the form.\n<\/p>\n<p>The latter option is the standard approach, treating the screen form as an independently maintained source artifact. To deal with online changes to data, some kind of &#8220;binding&#8221; occurs in the form to pull the data fields in and push user inputs back out again. Some UI frameworks offer bidirectional binding as a service between data and presentation classes. Template languages, common in use on the web, use &#8220;escapes&#8221; containing interpreted code that pull in data values in the right places at the right time.\n<\/p>\n<p>The problem with the standard approach is that it leaves the forms internally hard-wired into the data definitions. If the data definitions evolve, the forms must be manually adjusted. To make the problem precise, we will specify that the following data evolutions are to be handled:\n<\/p>\n<ol>\n<li>Inserting new fields, and\n<\/li>\n<li>Renaming existing fields.\n<\/li>\n<\/ol>\n<p>One approach to solving this problem would be to treat these evolutions as refactorings that automatically make the appropriate changes to the form. To be an acceptable solution to this challenge, such refactorings must be decidable and sound. Good luck with that, as bindings and escapes are typically expressed in general purpose Turing-complete languages. The form language would have to be a limited special-purpose language of some sort. That is the approach taken in so-called Model-Driven Development (MDD), where domain specific models are defined declaratively. MDD raises the &#8220;round-trip engineering&#8221; problem, which is the need to map changes in one model into the others to keep them consistent. MDD is based on transformations, but ones that map changes between independent artifacts. I challenge MDD proponents to show how they would solve this simple problem. To make the problem more precise, I will list the customizations that the form language must support:\n<\/p>\n<ol>\n<li>Introducing a hierarchy of form layout containers to control where fields are displayed. For example, splitting the form into two side-by-side panels.\n<\/li>\n<li>Distributing fields across different layout containers, and changing the order of fields within a layout container. For example, moving the address field into the right-hand panel created above, and moving the id field to be after the name field.\n<\/li>\n<li>Renaming field labels, for example &#8220;id&#8221; to &#8220;customer id&#8221;.\n<\/li>\n<\/ol>\n<p>These customizations must be invariant in the presence of the data evolutions stipulated earlier: introducing new data fields (which should pop up within the form, preserving relative order with other fields that have not been explicitly moved), and renaming data fields (which should have no effect other than to replace displayed labels that haven&#8217;t been explicitly renamed).\n<\/p>\n<p>The purpose of this challenge is to evaluate an alternative resolution of the dilemma of coordinating change in software designs. I want to treat the form as being directly generated from the data definition, not as an independent artifact. The generator will be specified in a special language designed to express transformations between structures. Customizations to the form will also be transformations, which are composed together to convert the generated generic form into the desired customized form. The key technical hurdle is that these customizing transformations must be invariant under the stipulated evolutions of the input data. I challenge existing transformation languages to handle this short list of customizations and evolutions. I think they will be hard-pressed, because those customizations and evolutions, while commonplace and natural, play havoc with the ways we typically express structure in languages.\n<\/p>\n<p>Renaming is particularly nasty, for the na\u00c3\u00afve way to specify most of these transformations is by keying off of the names. Any reasonably expressive transformation language is unlikely to support decidable and sound refactoring of its matching semantics. Order is another stumbling block, for insertion is often specified in terms of integer ordinals, which are unstable in the presence of other insertions, violating the data evolution requirement. So for example moving the id field after the name field, if encoded in terms of ordinal positions, would be incorrect after inserting a new field before the id field.\n<\/p>\n<p>These technical problems reveal a surprising, even scandalous, situation: that in this day and age we still don&#8217;t understand sequential and hierarchical structures well enough to build modular transformations on them. It is not my purpose here to present a solution, but those familiar with my past work will not be surprised to hear me claim that the root cause of the problem is that we have adopted the wrong way to encode such structure: text strings. Strings (or the morally equivalent ASTs\/DOMs parsing them) are not a useful way to represent complex information artifacts. I claim that once we get over our textual fixation, the transformation challenge becomes tractable. By an odd coincidence, it turns out that the internal data model of Subtext is close to a solution.\n<\/p>\n<p>Meeting the challenge of transformations would yield a pleasing result: that instead of building a system as a set of artifacts with subtle internal interdependencies that must be manually maintained, we can instead plug together a set of modular transformations. Note that the data definition artifact itself can be replaced by a history of evolutions, seen as transformations, starting from the empty definition. It&#8217;s transformations all the way down. We win because the transformations are modular, unlike the structures they generate. I call this approach <em>Transformative Programming<\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I got some good feedback here on my last paper. I want to see if I can get some equally good advice about what my next paper should be. My past papers have been about making programming easier. I would like to move on to making programming more powerful. Specifically, by making transformations and views &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/alarmingdevelopment.org\/?p=88\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;The modular transformation challenge&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_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_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-general"],"jetpack_shortlink":"https:\/\/wp.me\/pfEnU-1q","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/posts\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=88"}],"version-history":[{"count":0,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/posts\/88\/revisions"}],"wp:attachment":[{"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}