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.


翻译:开发者常通过提取方法来提升代码的可读性、可理解性与复用性,而内联方法则将逻辑保持在一个代码块内。先前基于静态度量的研究未能明确揭示这两种实践之间的差异,且对于理解与导航过程中的人为因素仍缺乏深入探讨。本研究采用动态方法——在参与者阅读与完成任务时进行眼动追踪——来探究内联方法与提取方法这两种重构方式。我们分析了关键代码区域,并对比了视觉努力与阅读行为(注视时长与次数、回视、重访),同时记录了任务完成时间与尝试次数。我们开展了一项受控实验,共有 32 位 Java 新手参与,实验后进行了简短访谈。每位参与者需完成八项简单任务,这些任务涉及四个以内联版本呈现的程序和四个以提取方法版本呈现的程序。此外,我们还对另外 58 位新手进行了调查,以获取补充的定量与定性数据。结果表明,重构效果取决于任务难度。在两项任务中,方法提取提升了任务表现并降低了视觉努力,其中任务完成时间最多减少了 78.8%,回视次数减少了 84.6%。对于较简单的任务(例如计算正方形面积),提取方法反而损害了表现:任务完成时间最多增加了 166.9%,回视次数增加了 200%。即使方法命名具有明确含义,新手仍频繁在调用点与提取出的方法之间来回切换,从而增加了导航负担与认知负荷。参与者的主观偏好常倾向于提取方法,认为其提升了可读性与复用性,但这些偏好并不总是与实测表现相符。这些发现提示教育者应对新手过早进行模块化保持谨慎,并凸显了眼动追踪作为静态度量方法有益补充的价值。

0
下载
关闭预览

相关内容

基于内在动机的深度强化学习探索方法综述
专知会员服务
40+阅读 · 2023年5月13日
北航《深度学习事件抽取》文献综述和当前趋势
专知会员服务
87+阅读 · 2021年7月6日
专知会员服务
16+阅读 · 2021年1月23日
论文浅尝 | GraphIE:基于图的信息抽取框架
开放知识图谱
17+阅读 · 2019年6月2日
一种关键字提取新方法
1号机器人网
21+阅读 · 2018年11月15日
干货|当深度学习遇见自动文本摘要,seq2seq+attention
机器学习算法与Python学习
10+阅读 · 2018年5月28日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
5+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
最新内容
人工智能在战场行动中的演进及伊朗案例
专知会员服务
7+阅读 · 4月18日
美AI公司Anthropic推出网络安全模型“Mythos”
专知会员服务
4+阅读 · 4月18日
【博士论文】面向城市环境的可解释计算机视觉
大语言模型的自改进机制:技术综述与未来展望
《第四代军事特种作战部队选拔与评估》
专知会员服务
3+阅读 · 4月18日
相关VIP内容
基于内在动机的深度强化学习探索方法综述
专知会员服务
40+阅读 · 2023年5月13日
北航《深度学习事件抽取》文献综述和当前趋势
专知会员服务
87+阅读 · 2021年7月6日
专知会员服务
16+阅读 · 2021年1月23日
相关资讯
论文浅尝 | GraphIE:基于图的信息抽取框架
开放知识图谱
17+阅读 · 2019年6月2日
一种关键字提取新方法
1号机器人网
21+阅读 · 2018年11月15日
干货|当深度学习遇见自动文本摘要,seq2seq+attention
机器学习算法与Python学习
10+阅读 · 2018年5月28日
相关基金
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
5+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员