Java初学者的重构:基于眼动研究的提取与内联方法比较
Refactoring for Novices in Java: An Eye Tracking Study on the Extract vs. Inline Methods
AI总结:
本研究通过眼动追踪分析,发现方法提取对初学者在复杂任务中提升性能有效,但对简单任务反而降低效率,强调了眼动追踪在软件重构评估中的重要性。
摘要:
开发者经常提取方法以提高可读性、理解和重用性,而内联则保持逻辑在一个块中。基于静态指标的先前研究未能显示这两种实践之间的明显差异,而人类的理解和导航方面仍需深入探索。我们通过动态方法研究内联方法与提取方法的重构:在参与者阅读和解决问题时进行眼动追踪。我们分析了关键代码区域,并比较了视觉努力和阅读行为(注视持续时间与次数、回退、重访),以及时间和尝试次数。我们对32名Java初学者进行了受控实验,随后进行了简短的访谈。每位参与者在四个内联版本和四个提取版本的程序上解决了八个简单任务。我们还对58名额外的初学者进行了调查,以获取补充的定量和定性数据。结果显示,效果取决于任务难度。在两个任务中,方法提取提高了性能并减少了视觉努力,时间减少了高达78.8%,回退减少了84.6%。对于更简单的任务(例如,正方形面积),提取损害了性能:时间增加了高达166.9%,回退增加了200%。即使有有意义的方法名,初学者也经常在调用站点和提取方法之间来回切换,增加了导航和认知负荷。偏好经常倾向于提取以提高可读性和重用性,但并不总是与测量性能相符。这些发现表明,教育者应谨慎对待初学者的提前模块化,并强调眼动追踪作为静态指标的有用补充。
英文摘要:
Developers often extract methods to improve readability, understanding, and reuse, while inlining keeps logic in one block. Prior work based on static metrics has not shown clear differences between these practices, and the human side of comprehension and navigation remains underexplored. We investigate Inline Method vs. Extract Method refactorings using a dynamic approach: eye tracking while participants read and solve tasks. We analyze key code areas and compare visual effort and reading behavior (fixation duration and count, regressions, revisits), alongside time and attempts. We ran a controlled experiment with 32 Java novices, followed by short interviews. Each participant solved eight simple tasks across four programs presented in an inlined version and four in an extracted version. We also surveyed 58 additional novices for complementary quantitative and qualitative data. Results show that effects depend on task difficulty. In two tasks, method extraction improved performance and reduced visual effort, with time decreasing by up to 78.8% and regressions by 84.6%. For simpler tasks (e.g., square area), extraction hurt performance: time increased by up to 166.9% and regressions by 200%. Even with meaningful method names, novices often switched back and forth between call sites and extracted methods, increasing navigation and cognitive load. Preferences frequently favored extraction for readability and reuse, but did not always match measured performance. These findings suggest educators should be cautious about premature modularization for novices and highlight eye tracking as a useful complement to static metrics.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。