Scoped: Evaluating A Composite Visualisation of the Scope Chain Hierarchy Within Source Code

Ivan Bacher, Brian Mac Namee, John D. Kelleher

Abstract

Programmers dedicate a substantial portion of their workflow to understanding existing codebases. A significant challenge in this process is navigating the scope chain hierarchy—the rules governing the visibility and lifetime of identifiers. This paper evaluates "Scoped," a tool that integrates a composite visualization directly into source code editors. By combining a packed circle tree overview with a detailed identifier list, Scoped aims to clarify nested scopes and behaviors like JavaScript "hoisting." Our experimental results indicate that these visualizations significantly enhance code comprehension accuracy, providing a reliable "ground truth" where textual representations may be misleading.

Introduction

Modern software development involves complex nesting of functions and variables. While Integrated Development Environments (IDEs) offer syntax highlighting, they frequently fail to represent the hierarchical nature of scopes effectively. This is particularly evident in languages like JavaScript, where "hoisting" moves variable declarations to the top of their functional scope during compilation. Consequently, the physical location of code often diverges from its logical behavior, leading to developer disorientation and bugs. The Scoped tool addresses this by providing real-time, cursor-linked visual feedback on the scope hierarchy.

Methodology: The Scoped Tool

The Scoped tool consists of two primary visual components designed to reduce cognitive load and context switching:

  1. Overview Component (Packed Circle Tree): This provides an abstract "mini-map" of the scope hierarchy. Scopes are represented as nested circles, with color-coding to indicate the current scope (green), accessible parent scopes (blue), and inaccessible scopes (grey).
  2. Detail View Component (List View): A sidebar that lists all identifiers (variables, functions, parameters) accessible from the current cursor position, including their declaration type and line number.
The Scoped tool interface featuring (A) the Packed Circle Tree overview, (B) the Detail View list, and (C) the integrated code editor.

To evaluate the effectiveness of these components, two between-subject user studies were conducted with 145 participants. Study 1 compared a baseline (standard editor) against the full composite visualization. Study 2 isolated the Overview and Detail View components to determine their individual contributions to comprehension. Participants answered six questions based on complex JavaScript snippets involving deep nesting and hoisting.

Results and Analysis

The experimental data revealed a clear advantage for developers using the Scoped visualization. In Study 1, the group utilizing the composite view achieved an average correctness score of 5 out of 6, whereas the baseline group averaged 4 out of 6. A Kruskal-Wallis test confirmed this difference as statistically significant (p < 0.05).

Comparative performance results across the four experimental groups, showing higher correctness scores for groups with visualizations.

The "Hoisting" Advantage

The most pronounced performance gains were observed in tasks involving JavaScript hoisting. In these scenarios, where the visual layout of the code is counter-intuitive, the Scoped visualization provided the necessary "ground truth" for participants to correctly identify variable visibility.

The Power of Composition

Study 2 showed that while both the Overview and Detail View components individually improved performance over the baseline (averaging scores of 5), the researchers concluded that the composite view offers the most robust support. Seeing the "where" (hierarchy) and "what" (specific identifiers) simultaneously allows for a more comprehensive mental model of the code. Furthermore, the tool benefited both novice and experienced programmers, suggesting that scope complexity is a universal hurdle.

Discussion and Future Work

While Scoped demonstrates clear benefits for code comprehension, several avenues for future research remain. The current evaluation focused on static understanding; future studies should assess the tool's impact during active debugging tasks where cognitive load is higher. Additionally, the scalability of the packed circle tree for extremely large files with hundreds of nested scopes requires further investigation. Finally, while this study focused on JavaScript, the principles of Scoped could be extended to other languages with complex scoping rules, such as C++ or Java, to test its generalizability across the programming landscape.

Conclusion

Scoped successfully bridges the gap between the textual representation of code and its logical scope hierarchy. By integrating hierarchical visualizations directly into the editor, the tool significantly improves developer accuracy in understanding complex code, particularly when dealing with non-intuitive language behaviors like hoisting.

Summary updated

Abstract

This paper presents two studies that evaluate the effectiveness of a software visualisation tool which uses a com-posite visualisation to encode the scope chain and information related to the scope chain within source code. The first study evaluates the effectiveness of adding the composite visualisation to a source code editor to help programmers understand scope relationships within source code. The second study evaluates the effectiveness of each individual component within the composite visualisation. The composite visualisation is composed of a packed circle tree diagram (overview component) and a list view (detail view component). The packed circle tree functions as an abstract mini-map to provide viewers with a high-level overview of the scope chain hierarchy within a source code document. The list view provides additional information about identifiers (variables, functions, and parameters) that are accessible from the scope within which the cursor is located, in the source code document. Both studies utilise a between-subject design, in which groups of participants were presented with source code fragments and asked to answer a series of code understanding questions. The results of the studies indicate that adding a composite visualisation to a source code editor can have a positive effect on code understanding, especially when the textual representation of the code no longer corresponds to the actual behaviour of the code (as is the case, for example, in languages such as JavaScript that implement variable hoisting).
BibTeX
@inproceedings{bacher2018scoped,
  author = {Ivan Bacher and Brian Mac Namee and John D. Kelleher},
  title = {{Scoped: Evaluating A Composite Visualisation of the Scope Chain Hierarchy Within Source Code}},
  booktitle = {VISSOFT},
  year = {2018},
  doi = {10.1109/vissoft.2018.00021},
}
Figure