Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/3649217.3653636acmconferencesArticle/Chapter ViewAbstractPublication PagesiticseConference Proceedingsconference-collections
research-article

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

Published: 03 July 2024 Publication History

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.

References

[1]
S. Ajami, Y. Woodbridge, and D. G. Feitelson. Syntax, predicates, idioms - what really affects code complexity? Empirical Software engineering, 24(1):287--328, Feb 2019.
[2]
A. Baron andD. G. Feitelson. Howa data structure's linearity affects programming and code comprehension: The case of recursion vs. iteration. In 34th Workshop Psychology of Programming Interest Group (PPIG), Aug 2023.
[3]
A. C. Benander, B. A. Benander, and H. Pu. Recursion vs. iteration: An empirical study of comprehension. J. Syst. Softw., 32(1):73--82, 1996.
[4]
A. C. Benander, B. A. Benander, and J. Sang. An empirical analysis of debugging performance - differences between iterative and recursive constructs. J. Syst. Softw., 54(1):17--28, 2000.
[5]
R. Cates, N. Yunik, and D. G. Feitelson. Does code structure affect comprehension? on using and naming intermediate variables. In 29th IEEE/ACM Intl. Conf. Program Comprehension, pages 118--126. IEEE, 2021.
[6]
D. Dicheva and J. Close. Mental models of recursion. J. Educational Computing Research, 14(1):1--23, 1996.
[7]
J. Gal Ezer and D. Harel. What (else) should cs educators know? Communications of the ACM, 41(9):77--84, Sep 1998.
[8]
C. E. George. EROSI - visualising recursion and discovering new errors. In Proc. 31st SIGCSE Technical Symp. Computer Science Education, pages 305--309, 2000.
[9]
T. Götschi, I. D. Sanders, and V. Galpin. Mental models of recursion. In Proc. 34th SIGCSE technical symp. Computer science education, pages 346--350, 2003.
[10]
J. E. Greer. A comparison of instructional treatments for introducing recursion. Computer Science Education, 1(2):111--128, 1989.
[11]
B. Haberman and H. Averbuch. The case of base cases: Why are they so difficult to recognize? Proc. 7th Conf. Innovation & Tech. in Comput. Sci. Education, pages 84--88, 2002.
[12]
H. Kahney. What do novice programmers know about recursion. Proc. SIGCHI Conf. Human Factors in Computing Systems, page 235--239, 1983.
[13]
C. Kessler and J. Anderson. Learning flow control: Recursive and iterative procedures. Human-Computer Interaction, 2(2):135--166, 1986.
[14]
N. Kiesler. Mental models of recursion: A secondary analysis of novice learners' steps and errors in java exercises. In 33rd Workshop Psychology of Programming Interest Group, pages 226--240, 2022.
[15]
E. Lee, V. Shan, B. Beth, and C. Lin. A structured approach to teaching recursion using cargo-bot. In 10th Conf. International Computing Education Research, page 59--66, July 2014.
[16]
R. A. McCauley, B. Hanks, S. Fitzgerald, and L. Murphy. Recursion vs. iteration: An empirical study of comprehension revisited. In 46th ACM Tech. Symp. Comput. Sci. Education, pages 350--355, 2015.
[17]
C. Mirolo. Is iteration really easier to learn than recursion for CS1 students? In Proc. 9th Conf. International Computing Education Research, pages 99--104, Sept 2012.
[18]
V. Rajlich and G. S. Cowan. Towards standard for experiments in program comprehension. In 5th International Workshop on Program Comprehension, pages 160--161, Mar 1997.
[19]
I. D. Sanders, V. Galpin, and T. Götschi. Mental models of recursion revisited. In 11th Innovation & Tech. in Comput. Sci. Education, pages 138--142, Jun 2006.
[20]
T. L. Scholtz and I. D. Sanders. Mental models of recursion: investigating students' understanding of recursion. In 15th Innovation & Tech. in Comput. Sci. Education, pages 103--107, Jun 2010.
[21]
J. Segal. Empirical studies of functional programming learners evaluating recursive functions. Instructional Science, 22:385--411, 1995.
[22]
S. Wiedenbeck. Learning iteration and recursion from examples. International Journal of Man-Machine Studies, 30(1):1--22, January 1989.

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
ITiCSE 2024: Proceedings of the 2024 on Innovation and Technology in Computer Science Education V. 1
July 2024
776 pages
ISBN:9798400706004
DOI:10.1145/3649217
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 03 July 2024

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. code comprehension
  2. computer science education
  3. recursion

Qualifiers

  • Research-article

Funding Sources

  • ISF

Conference

ITiCSE 2024
Sponsor:

Acceptance Rates

Overall Acceptance Rate 552 of 1,613 submissions, 34%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 73
    Total Downloads
  • Downloads (Last 12 months)73
  • Downloads (Last 6 weeks)10
Reflects downloads up to 25 Dec 2024

Other Metrics

Citations

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media