在命令式编程之前是否应该学习函数式编程? [英] Should functional programming be taught before imperative programming?

查看:103
本文介绍了在命令式编程之前是否应该学习函数式编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,函数式编程是一件好事。它消除了状态,并使自动代码并行运行变得更加容易。

许多第一次学习命令式编程风格的程序员发现学习函数式编程非常困难,因为它是如此不同。我开始怀疑先接受过函数式编程的程序员是否会很难开始命令式编程。看起来它不会像其他方式那样困难,所以我认为如果更多的程序员首先被教给函数式编程,这将是一件好事。所以,我的问题是,函数式编程是否应该在学习之前在学校教授,如果是的话,为什么它不是更常见的开始?

解决方案

我认为它运作得非常好,我同意你的观点比其他方式更好。
函数式编程对于不是程序员的人来说相当直观。它更好地映射了我们在高中或更早的时候学过的数学知识,因此那些还没有接触过强制性编程的人通常不会遇到太多麻烦。


事实上,有一种趋势是,在注册SML的时候新编程的人比那些已经学过Java或C ++的人更快。



从命令式到功能式看起来有一个很大的概念上的跳跃,但倒向大多数人看起来要容易得多。在学习SML之后,学生通常不会觉得Java很难学习。一旦你了解了编程的纯粹概念,对副作用的粘合就相当简单。但如果你对编程的全部理解都是基于副作用的话,那么很难想象没有的任何东西都是可能的。



我认为这种方法的一大好处是,函数式编程原则成为编程工具箱的重要组成部分,而不是您可能会炫耀的某些深奥附加组件。即使使用命令式语言进行编程,我认为使用功能语言的背景也是有好处的。即使编程为C这样低级的东西,考虑最小化状态和副作用,以及习惯高阶函数的概念(即使它们在语言中不可用)也是有好处的。


It seems to me that functional programming is a great thing. It eliminates state and makes it much easier to automatically make code run in parallel.

Many programmers who were first taught imperative programming styles find it very difficult to learn functional programming, because it is so different. I began to wonder if programmers who were taught functional programming first would find it hard to begin imperative programming. It seems like it would not be as hard as the other way around, so I thought it would be a good thing if more programmers were taught functional programming first.

So, my question is, should functional programming be taught in school before imperative, and if so, why is it not more common to start with it?

解决方案

Actually, some schools already do it this way around. Where I study (University of Copenhagen), they teach SML in the first semester, as an intro to programming. Then they teach Java afterwards, as an intro to OOP.

I think it works extremely well, and I agree with you it's better than the other way around. Functional programming is fairly intuitive to someone who's not (yet) a programmer. It maps much better to what we were taught as math in high school or earlier, so people who have not yet been exposed to imperative programming usually pick it up without too much trouble.

In fact, there's a trend that people who are new to programming when they enroll pick SML up faster than those who've already learned Java or C++.

It seems like there's a big conceptual jump in going from imperative to functional, but the reverse seems much easier to most. Students generally don't find Java difficult when they're exposed to that after learning SML. Once you know about the "pure" concepts of programming, gluing on side effects is fairly straightforward. But if your entire understanding of programming is based in side effects, it's much harder to imagine that anything is possible without them.

I think a big benefit of this approach is that functional programming principles become an essential part of your programming toolbox, rather than some esoteric add-on you might use if you want to show off. Even when programming in imperative languages, I think there's a benefit in having your background in a functional language. Even when programming in something as low-level as C, there's a benefit to thinking about minimizing state and side effects, and being used to the concept of higher-order functions (even though they're not available in the language)

这篇关于在命令式编程之前是否应该学习函数式编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆