Why Is Recursion Hard to Comprehend? An Experiment with Experienced Programmers in Python

Aviad Baron, Dror G. Feitelson

Research output: Chapter in Book/Report/Conference proceedingConference contributionpeer-review

Abstract

Recursion has the reputation of being hard to teach and understand. Our goal is to identify precisely what it is about recursion that makes it hard, and use this to devise a systematic teaching plan. We first make a distinction between regular recursion and tail recursion - - the special case where the recursive call is the last command that is executed by the function. Tail recursion is the preferred form used in functional programming, because it simplifies memory management, and we hypothesize that it is also easier to understand. We conducted a controlled experiment with 139 participants, in which they were asked to understand different recursive functions. This revealed that tail recursion, when it is natural to use, is indeed easier to understand than the more general form of recursion where significant processing is performed after the recursive call. But it also showed that using tail recursion may come with a price, as when achieving the tail form requires a transformation of the code that obfuscates the underlying recursive algorithm. We conclude that having significant processing after the recursive call, or distorting the code so as to remove such processing, are major factors that make recursion hard. We therefore suggest to start teaching recursion with a basic form of tail recursion, and then progress to more complicated cases with processing after the recursive call. Transformations to tail form should be taught last, if at all.

Original languageEnglish
Title of host publicationITiCSE 2024 - Proceedings of the 2024 Conference Innovation and Technology in Computer Science Education
PublisherAssociation for Computing Machinery
Pages115-121
Number of pages7
ISBN (Electronic)9798400706004
DOIs
StatePublished - 3 Jul 2024
Event29th Conference Innovation and Technology in Computer Science Education, ITiCSE 2024 - Milan, Italy
Duration: 8 Jul 202410 Jul 2024

Publication series

NameAnnual Conference on Innovation and Technology in Computer Science Education, ITiCSE
Volume1
ISSN (Print)1942-647X

Conference

Conference29th Conference Innovation and Technology in Computer Science Education, ITiCSE 2024
Country/TerritoryItaly
CityMilan
Period8/07/2410/07/24

Bibliographical note

Publisher Copyright:
© 2024 ACM.

Keywords

  • code comprehension
  • computer science education
  • recursion

Fingerprint

Dive into the research topics of 'Why Is Recursion Hard to Comprehend? An Experiment with Experienced Programmers in Python'. Together they form a unique fingerprint.

Cite this