Program tracing, or mentally simulating a program on concrete inputs, is an important part of general program comprehension. Programs involve many kinds of virtual state that must be held in memory, such as variable/value pairs and a call stack. In this work, we examine the influence of short-term working memory (WM) on a person's ability to remember program state during tracing. We first confirm that previous findings in cognitive psychology transfer to the programming domain: people can keep about 7 variable/value pairs in WM, and people will accidentally swap associations between variables due to WM load. We use a restricted focus viewing interface to further analyze the strategies people use to trace through programs, and the relationship of tracing strategy to WM. Given a straight-line program, we find half of our participants traced a program from the top-down line-by-line (linearly), and the other half start at the bottom and trace upward based on data dependencies (on-demand). Participants with an on-demand strategy made more WM errors while tracing straight-line code than with a linear strategy, but the two strategies contained an equal number of WM errors when tracing code with functions. We conclude with the implications of these findings for the design of programming tools: first, programs should be analyzed to identify and refactor human-memory-intensive sections of code. Second, programming environments should interactively visualize variable metadata to reduce WM load in accordance with a person's tracing strategy. Third, tools for program comprehension should enable externalizing program state while tracing.
翻译:程序追踪或者在精神上模拟具体投入的程序,是一般程序理解的一个重要部分。方案涉及许多必须保存在记忆中的虚拟状态,例如变量/价值配对和调用堆叠。在这项工作中,我们检查短期工作记忆(WM)对一个人在追踪过程中记忆程序状态的能力的影响。我们首先确认,先前在认知心理学转移到编程领域方面的调查结果:在WM中,人们可以保留大约7个变量/价值配对,人们会意外地互换因WM负载而导致的变量之间的关联。我们使用限制的重点查看界面,进一步分析人们通过程序追踪的战略,以及追踪战略与WM的关系。在直线程序追踪过程中,我们发现一半的参与者从上下逐行(线线性)追踪程序状态(WM)对一个人记忆状态的影响,而另一半是从数据依赖数据(随需)开始的向上移动。 点战略参与者在追踪直线代码而不是直线战略时会发现WM的错误,但两个战略含有相同数量的第二个战略,在追踪外线段的编程过程中,我们发现这些编程过程的代码时,我们应该用直线码来分析。