The functional programming paradigm has a long and storied history, with its beginnings in the Lambda Calculus. In recent decades, pure functional languages such as Haskell have been shown to be highly effective in producing robust software due to immutable data structures, among other functional features. The advantages of programming with immutable data structures can also be had in non-functional languages such as Python. Over the years, non-functional languages have introduced immutable data structures as well as comprehension and lambda expressions, and it is possible to program in a purely functional style in them. In this paper, we present a ``best practice'' idea in introductory programming classes that forces students to learn and complete programming assignments in a purely functional subset of Python. By doing so, the student can learn functional ideas such as immutability, pure functions with no side effects, and stateless programming. We define a functional subset of Python and illustrate the best practice using small examples. We strongly feel that students in computing need familiarity with pure functional programming and argue that this can be taught in introductory programming courses that use Python.


翻译:函数式编程范式拥有悠久而丰富的历史,其起源可追溯至Lambda演算。近几十年来,诸如Haskell等纯函数式语言已被证明在生成稳健软件方面极为有效,这得益于不可变数据结构及其他函数式特性。使用不可变数据结构的编程优势同样可在非函数式语言(如Python)中实现。多年来,非函数式语言已引入不可变数据结构、推导式及lambda表达式,使得在这些语言中以纯函数式风格编程成为可能。本文提出一种在编程导论课程中的“最佳实践”理念,强制学生使用Python的纯函数式子集学习并完成编程作业。通过这种方式,学生可以掌握不可变性、无副作用的纯函数以及无状态编程等函数式概念。我们定义了Python的函数式子集,并通过小型示例阐述该最佳实践。我们强烈认为,计算机领域的学生需要熟悉纯函数式编程,并主张这可在使用Python的编程导论课程中教授。

0
下载
关闭预览

相关内容

人们为了让计算机解决各种棘手的问题,使用编程语言 编写程序代码并通过计算机运算得到最终结果的过程。
【剑桥大学-算法手册】Advanced Algorithms, Artificial Intelligence
专知会员服务
36+阅读 · 2024年11月11日
【NeurIPS2019】图变换网络:Graph Transformer Network
NAACL 2019 | 一种考虑缓和KL消失的简单VAE训练方法
PaperWeekly
20+阅读 · 2019年4月24日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员