Table of Contents
Fetching ...

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

Ivan Tan, Christopher M. Poskitt

TL;DR

A new approach to teaching refactoring is proposed, in which students must first complete a programming exercise constrained to ensure they will produce a code smell, based on the idea that learning refactoring is easier if students are familiar with the code, and that it brings refactoring closer to their regular development practice.

Abstract

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.

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

TL;DR

A new approach to teaching refactoring is proposed, in which students must first complete a programming exercise constrained to ensure they will produce a code smell, based on the idea that learning refactoring is easier if students are familiar with the code, and that it brings refactoring closer to their regular development practice.

Abstract

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.
Paper Structure (14 sections, 7 figures)

This paper contains 14 sections, 7 figures.

Figures (7)

  • Figure 1: High-level overview of the experiment protocol: participants are randomly allocated into two flows (A or B), and apply the two approaches to different code smell groups
  • Figure 2: Post-experiment survey (Likert scales are 7-point)
  • Figure 3: Number of code smells identified (out of 3)
  • Figure 4: Number of code smells successfully refactored (out of a possible 3)
  • Figure 5: How effective the students found the traditional vs. mistake-based approaches (7-point Likert)
  • ...and 2 more figures