arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2401.01011cs.SE
收藏

修正你自己的代码坏味道:在代码重构教学中加入基于错误的熟悉步骤

Fixing Your Own Smells: Adding a Mistake-Based Familiarisation Step When Teaching Code Refactoring

Ivan Tan, Christopher M. Poskitt

AI总结:

针对传统重构教学用陌生代码导致新手难内化的问题,提出让学生先写带坏味道的代码再重构的教学法,实验证明其能显著提升新手的重构效率与信心。

摘要:

编程问题可以通过多种功能正确的方式解决,但这些解决方案的质量(如可读性、可维护性)差异极大。当代码质量不佳时,会以“code smells(代码坏味道)”的形式表现出相关症状,它们是可通过应用重构模式解决的特定负面特征(如重复代码)。许多本科计算机课程会对学生进行这项软件工程实践的培训,通常采用由教师提供的陌生代码开展练习。然而我们观察到,这会让新手更难将重构内化为自身开发实践的一部分。本文提出了一种新的重构教学方法:学生必须先完成一项受约束的编程练习,确保他们会产生代码坏味道。这一简单干预基于以下理念:如果学生熟悉代码(自己构建的),学习重构会更容易;它能让重构更贴近学生的日常开发实践;还提供了从“错误”中学习的绝佳机会。我们对35名本科新手开展了一项研究,让他们交替使用传统方法和我们的“基于错误”的方法完成各类重构练习,结果发现学生使用后者完成练习的效率和信心都显著更高。

英文摘要:

Programming problems can be solved in a multitude of functionally correct ways, but the quality of these solutions (e.g. readability, maintainability) can vary immensely. When code quality is poor, symptoms emerge in the form of 'code smells', which are specific negative characteristics (e.g. duplicate code) that can be resolved by applying refactoring patterns. Many undergraduate computing curricula train students on this software engineering practice, often doing so via exercises on unfamiliar instructor-provided code. Our observation, however, is that this makes it harder for novices to internalise refactoring as part of their own development practices. In this paper, we propose a new approach to teaching refactoring, in which students must first complete a programming exercise constrained to ensure they will produce a code smell. This simple intervention is based on the idea that learning refactoring is easier if students are familiar with the code (having built it), that it brings refactoring closer to their regular development practice, and that it presents a powerful opportunity to learn from a 'mistake'. We designed and conducted a study with 35 novice undergraduates in which they completed various refactoring exercises alternately taught using a traditional and our 'mistake-based' approach, finding that students were significantly more effective and confident at completing exercises using the latter.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑