{"id":143,"date":"2006-04-12T23:23:13","date_gmt":"2006-04-12T22:23:13","guid":{"rendered":"http:\/\/www.nobugs.org\/blog\/?p=143"},"modified":"2006-04-12T23:23:40","modified_gmt":"2006-04-12T22:23:40","slug":"callstacks-of-the-future","status":"publish","type":"post","link":"https:\/\/www.nobugs.org\/blog\/archives\/2006\/04\/12\/callstacks-of-the-future\/","title":{"rendered":"Callstacks of the future"},"content":{"rendered":"<p>I read a blog entry recently (but can&#8217;t find the reference now, sorry) which changed my view about callstacks.  Now, these are pretty fundamental things and I&#8217;ve been aware of them for nearly twenty years.  So this was a pretty remarkable change.<\/p>\n<p>In my head, a callstack was a record of history.  When I drop into the debugger, I look at the callstack to see &#8220;where I&#8217;ve been&#8221;.<\/p>\n<p>That&#8217;s wrong.  The callstack isn&#8217;t a record of history.  It&#8217;s a record of the future.  It tells you where your computation is going to go next.  The &#8220;return addresses&#8221; on the stack are where computation will continue from in the future.<\/p>\n<p>Now, it&#8217;s easy to see why my misconception has continued for so long.  There&#8217;s usually not much difference between the two views.  Most of the time in a C-like language, you get called from some point in a function and then (later) you resume again from just after that point.  So is it really worth worrying about such a tiny different?<\/p>\n<p>Yes it is, because it gets your mind ready to understand concepts such as tail-call optimization and continuations much more easily.  In the &#8220;future&#8221; view of callstacks, tailcall optimization becomes obvious.  If we don&#8217;t need an activation record in the future, we don&#8217;t need it on the stack.  Similarly, continuations make much more sense.<\/p>\n<p>It&#8217;s a pretty small change in metaphor.  I haven&#8217;t magically learned anything new because of it.  But several bits of my knowledge now fit together in a much more satisfying way because of this switch.  Whoever wrote that original blog article, thank you! \ud83d\ude42<\/p>\n<p>UPDATE: Rar, finally found the <a href=\"http:\/\/calculist.blogspot.com\/2006\/03\/call-stack-is-not-history.html\">original blog article<\/a>.  Dave Herman was the man with the wisdom. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I read a blog entry recently (but can&#8217;t find the reference now, sorry) which changed my view about callstacks. Now, these are pretty fundamental things and I&#8217;ve been aware of them for nearly twenty years. So this was a pretty remarkable change. In my head, a callstack was a record of history. When I drop [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-143","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/comments?post=143"}],"version-history":[{"count":0,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/143\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/media?parent=143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/categories?post=143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/tags?post=143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}