{"id":2752,"date":"2014-08-23T08:00:55","date_gmt":"2014-08-23T13:00:55","guid":{"rendered":"http:\/\/admin.patheos.com\/blogs\/crywoof\/?p=2752"},"modified":"2014-08-22T18:37:45","modified_gmt":"2014-08-22T23:37:45","slug":"software-development-and-the-memory-palace-of-matteo-ricci","status":"publish","type":"post","link":"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/","title":{"rendered":"Software Development and the Memory Palace of Matteo Ricci"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<html><head><meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\"><meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\"><\/head><body><p><a href=\"https:\/\/wp-media.patheos.com\/blogs\/sites\/384\/2014\/08\/medium_5999261134.jpg\" class=\" decorated-link\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-media.patheos.com\/blogs\/sites\/384\/2014\/08\/medium_5999261134-189x300.jpg\" alt=\"Quill\" width=\"189\" height=\"300\" class=\"alignleft size-medium wp-image-2612\"><\/a> One of my regular goals as a software developer is the intentional reduction of cognitive load\u2014that is, I try to reduce the number of things I have to think about to get the job done.  This applies to interfaces used by the customer, but it applies in spades to the interfaces used by the programmer: which is to say, APIs of the modules of code in the system, and the interfaces of the tools used during development.<\/p>\n<p>It\u2019s like this.  A large software system is fiendishly, horrendously, amazingly, enormously, annoyingly complex.  It is simply not possible, even if you\u2019re the only author, to keep all of the details in your head over a long period of time.  (I\u2019ve been working on one project at work for almost ten years, and every so often I run across pieces of code that I know I must have written but that I have no memory of.)  Consequently, I try to design my systems so that I don\u2019t <em>need<\/em> to keep all of the details in mind.<\/p>\n<p>Despite the title of this post, there are many tricks.  The first is picking the right architecture.  In this sense, your system\u2019s architecture is the way you split it up into pieces.  Your architecture should be simple enough that you can keep it in mind; and then, when you\u2019re faced with a bug, or with a new feature to add, you can easily say, \u201cAha\u2014it has to be over here, in this part of the system.\u201d  And then, once you dive into that part of the system it should have its own architecture as well that helps you navigate around in it; and so on.<\/p>\n<p>The result is not unlike <i><a href=\"http:\/\/www.amazon.com\/gp\/product\/0140080988\/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0140080988&amp;linkCode=as2&amp;tag=crwo-20&amp;linkId=NGW64QDCZOM7FBCS\" class=\" decorated-link\" target=\"_blank\" rel=\"nofollow\">The Memory Palace of Matteo Ricci<\/a><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ir-na.amazon-adsystem.com\/e\/ir?t=crwo-20&amp;l=as2&amp;o=1&amp;a=0140080988\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\"><\/i>. <a href=\"http:\/\/en.wikipedia.org\/wiki\/Matteo_Ricci\" class=\" decorated-link\" target=\"_blank\" rel=\"nofollow\">Ricci<\/a> was a Jesuit missionary to China in the long and long ago; and he came up with a scheme for memorization.  You imagine a castle of many rooms; and in your imagination you furnish each of the rooms in great detail; and you attach the things you need to remember to the furnishings in the room.  If you wanted to remember the names of the Seven Wonders of the World, you might attach them to seven colored handkerchiefs in the little drawer at the top of the baroque cabinet in the niche on the left side of the blue marble room just inside the garden door, the one with the carving of Alexander the Great on the front.<\/p>\n<p>Now me, my skills at envisioning such complex scenes in great visual detail are lacking; which is no doubt part of way I\u2019m not a Jesuit.  But Ricci could do it, and I\u2019ve seen the same scheme described often enough that it must work for somebody.<\/p>\n<p>In my case, I do it differently.  I partition up the system, and remember the pieces; and I partition up the pieces; and so on.  And there has to be a logic to the partitioning, because that logic means that I can find my way about, and keep the bits of complexity in different boxes.  And that\u2019s key\u2014you only want to deal with one or two boxes at a time.<\/p>\n<p>That\u2019s decreasing the cognitive load.<\/p>\n<p>Another aspect is the careful design of code interfaces.  Module A calls module B using module B\u2019s \u201capplication programming interface\u201d or API.  (Module A and Module B are two of the boxes, and the API is where I drew the line between them.) Now APIs can be designed to make things easy for the caller; or they can be thrown together such that the caller has to do a lot of work understanding them each and every time he looks at them.  You want to do the former.<\/p>\n<p>Here\u2019s an example (some of you might to gloss over this, down to the bottom line).  On most systems, the Tcl interpreter (or \u201cTcl Shell\u201d) is a program called <tt>tclsh<\/tt>.  <a href=\"https:\/\/github.com\/wduquette\/tcl-quill\" class=\" decorated-link\" target=\"_blank\" rel=\"nofollow\">Quill<\/a> often calls the <tt>tclsh<\/tt> to do things: run tests, run the user\u2019s application, or any number of other things.  Suppose I want to run a test script, <code>mytest.test<\/code>.  Tcl makes it really easy to call external programs, and so I might just do this:<\/p>\n<pre> exec tclsh mytest.test <\/pre>\n<p>That executes <code>mytest.test<\/code> as if I\u2019d entered <code>tclsh mytest.test<\/code> at the system command line.  And on many systems, it will work.  On Windows, though, the Tcl shell is called <code>tclsh.exe<\/code>.  <\/p>\n<pre>\r\nif {[os flavor] eq \"windows\"} {\r\n    set tclsh \"tclsh.exe\"\r\n} else {\r\n    set tclsh \"tclsh\"\r\n}\r\n\r\nexec $tclsh mytest.test\r\n<\/pre>\n<p>Well, now, that\u2019s ugly.  I certainly don\u2019t want to have to do that everytime I want to use the <tt>tclsh<\/tt> to execute a script.  So I added a command to add the appropriate extension to the program name, when running on Windows:<\/p>\n<pre> exec [os exename tclsh] mytest.test <\/pre>\n<p>Since the logic to determine whether \u201c.exe\u201d is needed or not is in the <code>os exename<\/code> command, the user doesn\u2019t need to think about it.  <\/p>\n<p>But there\u2019s another problem.  The <code>exec<\/code> command will search for the <code>tclsh<\/code> program, but might not find it.  Things would be smoother if we found the Tcl shell ourselves, and gave <code>exec<\/code> its precise location.  And then, we could search for the Tcl shell in a number of ways, or even read its location from a configuration file.  So we get this:<\/p>\n<pre> exec [plat pathto tclsh] mytest.test <\/pre>\n<p>The <code>plat pathto<\/code> command not only looks for the <code>tclsh<\/code>, who cares how, it also takes care of adding the \u201c.exe\u201d if its needed.<\/p>\n<p>So this is better.  But what if the Tcl shell cannot be found?  Maybe we\u2019ve been given an explicit location to use, but the file isn\u2019t there, or perhaps none of our search mechanisms worked, and we found nothing. In that case, the above command will fail with an error; and we want it to be a useful error that makes the problem clear to the user.<\/p>\n<p>So try this:<\/p>\n<pre> exec [plat pathto tclsh -required] mytest.test <\/pre>\n<p>The <code>-required<\/code> option tells <code>plat pathto<\/code> to output a error message to the user when it cannot find the Tcl shell program, explaining that it cannot find it and what they might do about it.<\/p>\n<p>Now, we usually need to set up some things before we invoke the Tcl shell.  In particularly, we often need to set the TCL_LIB_PATH environment variable so that the Tcl shell can find the project\u2019s libraries.  So we get this:<\/p>\n<p><\/p><pre>\r\nset ::env(TCL_LIB_PATH) [project libpath]\r\nexec [plat pathto tclsh -required] mytest.test\r\n<\/pre>\n<p>When there\u2019s work that the caller of an API needs to do every single time, that\u2019s a sign that you\u2019re not providing the right API.  Every time I call the Tcl shell in this way, I\u2019m going to need to do all of these things.  Why don\u2019t I just define a proxy command that represents the Tcl shell program and handles all of this unpleasantness?  Then my program can simply say,<\/p>\n<pre> tclshell mytest.test <\/pre>\n<p>The new <code>tclshell<\/code> command looks up the path to the <code>tclsh<\/code> program, taking the operating system into account, and displays a useful error if it cannot find it.  But if it can, it sets the TCL_LIB_PATH environment variable, and executes the Tcl shell, passing its own arguments along, and returns the result.<\/p>\n<p>Having to think about whether the Tcl shell executable is available, and how to find out, and what to do if it isn\u2019t, and setting it up properly, all of that places an enormous cognitive load on the programmer.  The new <code>tclshell<\/code> command, by contrast, \u201cdoes the right thing\u201d.  It does what\u2019s wanted under the circumstances, and so the programmer no longer needs to think about it.  It reduces the cognitive load\u2014which frees up mental resources for other things.<\/p>\n<p><b>And here\u2019s the bottom line.<\/b>  That\u2019s really what the <a href=\"https:\/\/github.com\/wduquette\/tcl-quill\" class=\" decorated-link\" target=\"_blank\" rel=\"nofollow\">Quill<\/a> project is all about: reducing cognitive load.  Quill automates common development tasks such that the user can rely on them without having to think about them too much.  For example, I want to start work on a new project.  There\u2019s a lot to put together to make that happen; but at the highest level, it\u2019s all pretty much the same as the previous project.  So let\u2019s automate that:<\/p>\n<pre>\r\n$ kite new app my-project myapp\r\n<\/pre>\n<p>Bang!  I\u2019ve got a project tree that I know works just like my last project tree; all of the things I\u2019ve learned to do by reflex still apply, because everything is in the same place and follows the same standards.<\/p>\n<p>____<br>\nphoto credit: <a href=\"https:\/\/www.flickr.com\/photos\/campra\/5999261134\/\" class=\" decorated-link\" target=\"_blank\" rel=\"nofollow\">campra<\/a> via <a href=\"http:\/\/photopin.com\" class=\" decorated-link\" target=\"_blank\" rel=\"nofollow\">photopin<\/a> <a href=\"http:\/\/creativecommons.org\/licenses\/by-nc-nd\/2.0\/\" class=\" decorated-link\" target=\"_blank\" rel=\"nofollow\">cc<\/a><\/p>\n<\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>One of my regular goals as a software developer is the intentional reduction of cognitive load\u2014that is, I try to reduce the number of things I have to think about to get the job done. This applies to interfaces used by the customer, but it applies in spades to the interfaces used by the programmer: [&hellip;]<\/p>\n","protected":false},"author":1131,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[530],"tags":[531,522],"class_list":["post-2752","post","type-post","status-publish","format-standard","hentry","category-software-development","tag-quill","tag-tcl"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Software Development and the Memory Palace of Matteo Ricci<\/title>\n<meta name=\"description\" content=\"One of my regular goals as a software developer is the intentional reduction of cognitive load\u2014that is, I try to reduce the number of things I have to\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Software Development and the Memory Palace of Matteo Ricci\" \/>\n<meta property=\"og:description\" content=\"One of my regular goals as a software developer is the intentional reduction of cognitive load\u2014that is, I try to reduce the number of things I have to\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/\" \/>\n<meta property=\"og:site_name\" content=\"Cry &#039;Woof&#039;\" \/>\n<meta property=\"article:published_time\" content=\"2014-08-23T13:00:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-08-22T23:37:45+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/wp.production.patheos.com\/blogs\/crywoof\/files\/2014\/08\/medium_5999261134-189x300.jpg\" \/>\n<meta name=\"author\" content=\"willduquette\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"willduquette\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/\",\"url\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/\",\"name\":\"Software Development and the Memory Palace of Matteo Ricci\",\"isPartOf\":{\"@id\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/#website\"},\"datePublished\":\"2014-08-23T13:00:55+00:00\",\"dateModified\":\"2014-08-22T23:37:45+00:00\",\"author\":{\"@id\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/#\/schema\/person\/ff6351804d01f835d127aa686467fa2c\"},\"description\":\"One of my regular goals as a software developer is the intentional reduction of cognitive load\u2014that is, I try to reduce the number of things I have to\",\"breadcrumb\":{\"@id\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Software Development and the Memory Palace of Matteo Ricci\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/#website\",\"url\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/\",\"name\":\"Cry &#039;Woof&#039;\",\"description\":\"And let slip the dogs of whimsy!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/#\/schema\/person\/ff6351804d01f835d127aa686467fa2c\",\"name\":\"willduquette\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8075b1526bb772efdba031f0e814158b?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8075b1526bb772efdba031f0e814158b?s=96&r=g\",\"caption\":\"willduquette\"},\"url\":\"https:\/\/www.patheos.com\/blogs\/crywoof\/author\/willduquette\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Software Development and the Memory Palace of Matteo Ricci","description":"One of my regular goals as a software developer is the intentional reduction of cognitive load\u2014that is, I try to reduce the number of things I have to","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/","og_locale":"en_US","og_type":"article","og_title":"Software Development and the Memory Palace of Matteo Ricci","og_description":"One of my regular goals as a software developer is the intentional reduction of cognitive load\u2014that is, I try to reduce the number of things I have to","og_url":"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/","og_site_name":"Cry &#039;Woof&#039;","article_published_time":"2014-08-23T13:00:55+00:00","article_modified_time":"2014-08-22T23:37:45+00:00","og_image":[{"url":"http:\/\/wp.production.patheos.com\/blogs\/crywoof\/files\/2014\/08\/medium_5999261134-189x300.jpg"}],"author":"willduquette","twitter_card":"summary_large_image","twitter_misc":{"Written by":"willduquette","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/","url":"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/","name":"Software Development and the Memory Palace of Matteo Ricci","isPartOf":{"@id":"https:\/\/www.patheos.com\/blogs\/crywoof\/#website"},"datePublished":"2014-08-23T13:00:55+00:00","dateModified":"2014-08-22T23:37:45+00:00","author":{"@id":"https:\/\/www.patheos.com\/blogs\/crywoof\/#\/schema\/person\/ff6351804d01f835d127aa686467fa2c"},"description":"One of my regular goals as a software developer is the intentional reduction of cognitive load\u2014that is, I try to reduce the number of things I have to","breadcrumb":{"@id":"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.patheos.com\/blogs\/crywoof\/2014\/08\/software-development-and-the-memory-palace-of-matteo-ricci\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.patheos.com\/blogs\/crywoof\/"},{"@type":"ListItem","position":2,"name":"Software Development and the Memory Palace of Matteo Ricci"}]},{"@type":"WebSite","@id":"https:\/\/www.patheos.com\/blogs\/crywoof\/#website","url":"https:\/\/www.patheos.com\/blogs\/crywoof\/","name":"Cry &#039;Woof&#039;","description":"And let slip the dogs of whimsy!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.patheos.com\/blogs\/crywoof\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.patheos.com\/blogs\/crywoof\/#\/schema\/person\/ff6351804d01f835d127aa686467fa2c","name":"willduquette","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.patheos.com\/blogs\/crywoof\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8075b1526bb772efdba031f0e814158b?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8075b1526bb772efdba031f0e814158b?s=96&r=g","caption":"willduquette"},"url":"https:\/\/www.patheos.com\/blogs\/crywoof\/author\/willduquette\/"}]}},"_links":{"self":[{"href":"https:\/\/www.patheos.com\/blogs\/crywoof\/wp-json\/wp\/v2\/posts\/2752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.patheos.com\/blogs\/crywoof\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.patheos.com\/blogs\/crywoof\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.patheos.com\/blogs\/crywoof\/wp-json\/wp\/v2\/users\/1131"}],"replies":[{"embeddable":true,"href":"https:\/\/www.patheos.com\/blogs\/crywoof\/wp-json\/wp\/v2\/comments?post=2752"}],"version-history":[{"count":0,"href":"https:\/\/www.patheos.com\/blogs\/crywoof\/wp-json\/wp\/v2\/posts\/2752\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.patheos.com\/blogs\/crywoof\/wp-json\/wp\/v2\/media?parent=2752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.patheos.com\/blogs\/crywoof\/wp-json\/wp\/v2\/categories?post=2752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.patheos.com\/blogs\/crywoof\/wp-json\/wp\/v2\/tags?post=2752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}