在命令式编程之前是否应该教授函数式编程?

时间:2022-09-11 10:27:54

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?

所以,我的问题是,如果在命令式之前在学校教授函数式编程,那么,为什么从它开始并不常见?

15 个解决方案

#1


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.

实际上,有些学校已经这样做了。在我学习的地方(哥本哈根大学),他们在第一学期教授SML,作为编程的介绍。然后,他们之后教Java,作为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++.

实际上,有一种趋势是,那些刚接触编程的人比那些已经学习过Java或C ++的人更快地选择SML。

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.

从命令到功能似乎有一个很大的概念上的跳跃,但反过来似乎更容易。学习SML后,学生在接触Java时通常不会发现Java困难。一旦你了解了编程的“纯粹”概念,粘贴副作用就相当简单了。但如果您对编程的全部理解都是基于副作用,那么很难想象没有它们就可能发生任何事情。

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)

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

#2


Many schools teach functional programming. Some of them even teach it first. I think MIT, for a long time, used to teach scheme in its introduction to computer programing classes.

许多学校教授函数式编程。他们中的一些人甚至先教它。我认为麻省理工学院长期以来习惯于在计算机编程课程的介绍中教授计划。

At my school we covered ML as part of a "comparative programing languages class" that everyone was required to take.

在我的学校,我们将ML作为“比较编程语言课”的一部分,每个人都需要参加。

In any case, I don't think functional programming is that difficult to learn for people coming from imperative languages. At least it wasn't for me.

无论如何,我不认为函数式编程对于来自命令式语言的人来说难以学习。至少它不适合我。

A lot of people think the reason languages like Haskell and Scheme haven't gotten wider adoption is because people are "ruined" from them by imperative programming. That's nonsense.

很多人认为像Haskell和Scheme这样的语言没有得到更广泛采用的原因是因为人们被命令式编程“毁掉”了。那是胡说八道。

The real reason those languages haven't seen wide adoption is because they don't use curly braces. Seriously.

这些语言未被广泛采用的真正原因是因为它们不使用花括号。认真。

The C/Algol syntax style is prevalent because people like the way it looks.

C / Algol语法风格很流行,因为人们喜欢它的外观。

The key to increasing adoption of functional programing is not to talk about how great Haskell is and how evil side effects are, or to say the word "monad" repeatedly. Instead, just create a functional language that uses curly braces and semi-colons. People will use it.

增加功能性编程的关键不是谈论Haskell是多么伟大,副作用有多恶心,或者反复说“monad”这个词。相反,只需创建一个使用花括号和分号的函数式语言。人们会用它。

#3


Many (most ?) schools teach functionnal programming. Very few teach it first tough, for many reasons.

许多(大多数?)学校教授功能编程。由于很多原因,很少有人会先教它。

  • Most development environments for functionnal languages suck, and require extensive programming knowledge to use adequately. This is becoming less and less true, but we're still far away from Visual Studio for Haskell.

    功能语言的大多数开发环境都很糟糕,需要大量的编程知识才能充分利用。这变得越来越不真实,但我们仍然远离Visual Studio for Haskell。

  • It's harder to jump in the 'flashy stuff'. GUI toolkits and libs suck for most functionnal languages. Showing stuff on-screen and rewarding the student is important.

    跳进'华而不实的东西'更难。 GUI工具包和库很适合大多数功能语言。在屏幕上显示内容并奖励学生非常重要。

  • Self-taught programmers tend to gravitate to imperative/OO languages for historical reasons. Availability of BASIC in their youth, knowing that their favorite game was written in C or C++, you name it.

    由于历史原因,自学成才的程序员倾向于使用命令式/ OO语言。 BASIC年轻时的可用性,知道他们最喜欢的游戏是用C或C ++编写的,你可以说出来。

  • Simple resources and tutorials for functional programming languages are harder to come by. Compare the number of C# samples to Lisp samples on Code Project. Keep in mind that Lisp is over 5 times as old.

    简单的资源和函数式编程语言教程很难得到。在Code Project上将C#样本的数量与Lisp样本进行比较。请记住,Lisp已经超过5倍了。

#4


It could possibly be a mindshare issue, as most teachers/professors probably learned imperative styles first as well.

这可能是一个思想共享的问题,因为大多数教师/教授也可能首先学习命令式的风格。

Also, I would guess that there is far larger body of work available for teaching imperitive styles.

此外,我猜想有更多的工作可用于教授不完美的风格。

#5


I can only assume its the fact that OOP seemed to be a favorite buzzword / style, So Schools stuck to that,

我只能假设OOP似乎是一个最喜欢的流行语/风格,所以学校坚持这一点,

I was taught OOP design from the get go, its only recently ive been teaching myself the Functional style of programming and i can see it has its advantages.

我从一开始就被教授OOP设计,它最近才一直在教自己编程的功能风格,我可以看到它有它的优点。

#6


Edit: What follows reflects the original title, "Why is functional programming not taught in schools," Schools have teachers, not professors. Schoolteachers do not write their own textbooks.

编辑:以下内容反映了原始标题,“为什么函数式编程没有在学校教授”,学校有教师,而不是教授。教师不写自己的教科书。

The textbook companies from which the teachers are allowed to purchase their materials are the largest problem. The textbook companies are quick to jump on "the next big thing", which was OOP a few years ago. Functional programming has fallen by the wayside. Many teachers cannot or are not allowed to teach a course without a textbook, so the course selection generally follows the availability of textbooks from the big vendors.

允许教师购买材料的教科书公司是最大的问题。教科书公司很快就会跳上“下一件大事”,这是几年前的OOP。功能性编程已经被淘汰。许多教师不能或不允许在没有教科书的情况下教授课程,因此课程选择通常遵循大型供应商提供的教科书。

#7


First, I find the basis of your question faulty because I was taught functional programming at school. (It wasn't what I started with, but we did do some functional programming.)

首先,我发现你的问题的基础是错误的,因为我在学校教过函数式编程。 (这不是我开始的,但我们确实做了一些函数式编程。)

Second, I question the ease of transferring from functional coding to imperative coding. I don't think it'd be as easy as you make it out to be.

其次,我质疑从功能编码转移到命令式编码的难易程度。我认为它不像你想象的那么容易。

Third, programming is (for most people) a job skill. The vast majority of shops use imperative programming. Therefore, it's most useful to future coders to learn imperative programming.

第三,编程(对大多数人来说)是一种工作技能。绝大多数商店使用命令式编程。因此,对未来的编码人员来说,学习命令式编程是最有用的。

#8


The clear control flow of imperative programming lends itself well to implementation and analysis of algorithms in a teaching environment. Object-oriented programming is a convenient extension of that, so it is naturally what gets used most often. Functional programming (declarative programming of any kind really), on the other hand, is a completely separate paradigm that requires a whole new set of considerations (performance and otherwise) many of which are much easier to visualize if you understand imperative programming first. After all, it all boils down to an imperative language in the end.

命令式编程的清晰控制流程非常适合在教学环境中实现和分析算法。面向对象编程是一种方便的扩展,因此它最常被使用。另一方面,函数式编程(实际上是任何类型的声明式编程)是一个完全独立的范例,需要一整套新的考虑因素(性能和其他方面),如果您首先理解命令式编程,其中许多考虑因素都更容易可视化。毕竟,这最终归结为一种必要的语言。

#9


There has to be an historical angle to this (showing my age) for the curriculums in school. Functional was all I had to learn when I started.

对于学校的课程,必须有一个历史角度(显示我的年龄)。当我开始时,功能是我必须学习的。

But putting that aside, you have to start somewhere so one of them has to be first. If you start with imperative then there will be things you reach for that wont be there when you learn functional and you'll have to get used to doing things differently. If you start with functional and move onto imperative then you'll have to get used to learning new concepts/constructs and remembering that they are there it use.

但是把它放在一边,你必须从某个地方开始,所以其中一个必须是第一个。如果你从命令开始,那么当你学习功能时,你将会遇到的事情不会存在,你将不得不习惯以不同的方式做事。如果你从功能开始并转向命令式,那么你将不得不习惯于学习新概念/结构并记住它们在那里使用。

Whenever you are programming you are trying to solve a problem. It is good to have both in your toolbox to reach for to solve the problem at hand. That's why I think it would be best to start with imerative and then learn functional: if you find yourself reaching for something not there that's indicative of having chosen the wrong tool to solve your problem.

无论何时编程,您都在尝试解决问题。最好在工具箱中同时使用以解决手头的问题。这就是为什么我认为最好从imerative开始,然后学习功能:如果你发现自己找不到那些表明选择了错误工具来解决问题的东西。

Other than that methinks it's a toss up.

除此之外,它是一个折腾。

#10


I was actually just at a talk given by the person who's developing Bootstrap (a programming curriculum currently run by Citizen Schools). He seemed to think the functional programming style provided a better background for algebra, since it hits on the concept of functions as both processes and objects (with properties of their own). (Of course, declarative programming languages can have first-class functions, too, but the focus is not on that nearly as much.)

我实际上只是在开发Bootstrap(一个目前由公民学校运营的编程课程)的人发表的演讲中。他似乎认为函数式编程风格为代数提供了更好的背景,因为它将函数的概念作为进程和对象(具有自己的属性)。 (当然,声明性编程语言也可以拥有一流的功能,但重点并不是那么多。)

Personally, I think that teaching functional programming first is worthwhile. The declarative approach is taught very early on in math class, so functional programming provides some new concepts that declarative programming does not. I agree with many of the above posters that the bit about it being "too hard" is a myth, it's been done.

就个人而言,我认为首先教授函数式编程是值得的。声明式方法很早就在数学类中讲授,因此函数式编程提供了一些声明式编程所没有的新概念。我同意上面的许多海报,认为它“太难”是一个神话,它已经完成了。

#11


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?

所以,我的问题是,如果在命令式之前在学校教授函数式编程,那么,为什么从它开始并不常见?

Though I was not fortunate enough to start off with a functional language, I do have colleagues who did. I also had a friend who studied Math, and the only language he learned while in school was Haskell!

虽然我没有幸运能够开始使用功能性语言,但我确实有同事做过。我还有一个学习数学的朋友,他在学校学到的唯一语言是Haskell!

There really are two things: Computer Science and Computer Engineering. Though the line is very thin, IMO, it depends a lot on the course (as mentioned above) and the concerned department's focus area which language to cut your teeth with. Most engineering schools start with one of C, C++ or Java -- which have a potentially large job market. Others, may start with Lisp, Haskell etc.

真的有两件事:计算机科学和计算机工程。虽然线条非常薄,IMO,但它在很大程度上取决于课程(如上所述)和相关部门的重点领域,哪种语言可以用来切割。大多数工程学院都是从C,C ++或Java开始的 - 它们有着巨大的就业市场。其他人,可以从Lisp,Haskell等开始。

#12


Functional programming is taught in most universities. Part of the reason it's not taught in high school is probably due to the "Functional programming is to hard" myth.

大多数大学都教授功能编程。高中没有教过它的部分原因可能是由于“功能编程难以”的神话。

#13


Dunno about your school by in my undergrad studies ML was an essential part of the basic programming languages course and there was an extra curriculum course dedicated to Haskel.

关于你的学校的Dunno在我的本科学习ML中是基础编程语言课程的重要组成部分,还有一个专门用于Haskel的课程。

#14


Honestly, I think this is the wrong question to ask.

老实说,我认为这是一个错误的问题。

If the goal of an introductory class is to teach basic computer science, algorithms, programmatically solving problems, then your course is fundamental and you can choose one based on clarity, simplicity, and getting your ideas across. Some functional languages will be great for this. Particularly if the students have little or no previous experience.

如果入门课程的目标是教授基本的计算机科学,算法,以编程方式解决问题,那么您的课程是基础,您可以选择基于清晰度,简单性和提出想法的课程。一些函数式语言对此非常有用。特别是如果学生很少或没有以前的经验。

Usually this isn't really the goal of many introductory classes, though. They may require certain techniques or certain languages for a later course. They may want to leverage particular libraries, etc. They may just have to match someone elses checkbox list of "features".

但是,这通常不是许多入门课程的目标。他们可能需要某些技术或某些语言用于以后的课程。他们可能想要利用特定的库等。他们可能只需要匹配某些人的“功能”复选框列表。

So I think you want to turn your question on its head. Figure out what it is the course is actually trying to achieve, and pick the best language you can for that purpose. In some cases, this may be a functional language.

所以我想你想把问题放在首位。弄清楚课程实际上要实现的目标,并为此目的选择最佳语言。在某些情况下,这可能是一种功能语言。

If what you are really asking is how best to teach introductory level programming and computer science, that's a different can of worms.

如果你真正问的是如何最好地教授入门级编程和计算机科学,那就是一种不同的蠕虫病毒。

#15


I think, it should, yes.

我想,它应该,是的。

Also - no console applications and no "color palette mixers", but unit tests first.

此外 - 没有控制台应用程序和没有“调色板混音器”,但首先进行单元测试。

Only if the students behave well and write test cases with extremely high coverage, they MAY be allowed to have a quick look at how to read characters from keyboard.

只有学生表现良好并编写具有极高覆盖率的测试用例,才可以让他们快速了解如何从键盘读取字符。

In my opinion, most bad coding practices (code smells, antipatterns) come from a total ignorance towards the theory and best practices.

在我看来,大多数糟糕的编码实践(代码味道,反模式)来自对理论和最佳实践的完全无知。

So - teach them F# first, forbid the use of console i / o and GUIs and only use unit tests.

所以 - 首先教他们F#,禁止使用控制台i / o和GUI,只使用单元测试。

Second, teach them imperative / functional mixed style in an OOP context with full use and explanation of design patterns.

其次,在OOP环境中教授命令性/功能性混合风格,充分利用和解释设计模式。

Then - and ONLY then they can try to put clickybuttons somewhere, maybe as a reward. But theory and good coding practices first. Otherwise we create the next generation of "RAD" - victims that can't even use indentation correctly and mistaken ctrl+c / ctrl+v for software development.

然后 - 然后他们可以尝试将clickybuttons放在某处,也许作为奖励。但首先是理论和良好的编码实践。否则我们会创建下一代“RAD” - 受害者甚至无法正确使用缩进,并将ctrl + c / ctrl + v误认为是软件开发。

#1


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.

实际上,有些学校已经这样做了。在我学习的地方(哥本哈根大学),他们在第一学期教授SML,作为编程的介绍。然后,他们之后教Java,作为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++.

实际上,有一种趋势是,那些刚接触编程的人比那些已经学习过Java或C ++的人更快地选择SML。

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.

从命令到功能似乎有一个很大的概念上的跳跃,但反过来似乎更容易。学习SML后,学生在接触Java时通常不会发现Java困难。一旦你了解了编程的“纯粹”概念,粘贴副作用就相当简单了。但如果您对编程的全部理解都是基于副作用,那么很难想象没有它们就可能发生任何事情。

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)

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

#2


Many schools teach functional programming. Some of them even teach it first. I think MIT, for a long time, used to teach scheme in its introduction to computer programing classes.

许多学校教授函数式编程。他们中的一些人甚至先教它。我认为麻省理工学院长期以来习惯于在计算机编程课程的介绍中教授计划。

At my school we covered ML as part of a "comparative programing languages class" that everyone was required to take.

在我的学校,我们将ML作为“比较编程语言课”的一部分,每个人都需要参加。

In any case, I don't think functional programming is that difficult to learn for people coming from imperative languages. At least it wasn't for me.

无论如何,我不认为函数式编程对于来自命令式语言的人来说难以学习。至少它不适合我。

A lot of people think the reason languages like Haskell and Scheme haven't gotten wider adoption is because people are "ruined" from them by imperative programming. That's nonsense.

很多人认为像Haskell和Scheme这样的语言没有得到更广泛采用的原因是因为人们被命令式编程“毁掉”了。那是胡说八道。

The real reason those languages haven't seen wide adoption is because they don't use curly braces. Seriously.

这些语言未被广泛采用的真正原因是因为它们不使用花括号。认真。

The C/Algol syntax style is prevalent because people like the way it looks.

C / Algol语法风格很流行,因为人们喜欢它的外观。

The key to increasing adoption of functional programing is not to talk about how great Haskell is and how evil side effects are, or to say the word "monad" repeatedly. Instead, just create a functional language that uses curly braces and semi-colons. People will use it.

增加功能性编程的关键不是谈论Haskell是多么伟大,副作用有多恶心,或者反复说“monad”这个词。相反,只需创建一个使用花括号和分号的函数式语言。人们会用它。

#3


Many (most ?) schools teach functionnal programming. Very few teach it first tough, for many reasons.

许多(大多数?)学校教授功能编程。由于很多原因,很少有人会先教它。

  • Most development environments for functionnal languages suck, and require extensive programming knowledge to use adequately. This is becoming less and less true, but we're still far away from Visual Studio for Haskell.

    功能语言的大多数开发环境都很糟糕,需要大量的编程知识才能充分利用。这变得越来越不真实,但我们仍然远离Visual Studio for Haskell。

  • It's harder to jump in the 'flashy stuff'. GUI toolkits and libs suck for most functionnal languages. Showing stuff on-screen and rewarding the student is important.

    跳进'华而不实的东西'更难。 GUI工具包和库很适合大多数功能语言。在屏幕上显示内容并奖励学生非常重要。

  • Self-taught programmers tend to gravitate to imperative/OO languages for historical reasons. Availability of BASIC in their youth, knowing that their favorite game was written in C or C++, you name it.

    由于历史原因,自学成才的程序员倾向于使用命令式/ OO语言。 BASIC年轻时的可用性,知道他们最喜欢的游戏是用C或C ++编写的,你可以说出来。

  • Simple resources and tutorials for functional programming languages are harder to come by. Compare the number of C# samples to Lisp samples on Code Project. Keep in mind that Lisp is over 5 times as old.

    简单的资源和函数式编程语言教程很难得到。在Code Project上将C#样本的数量与Lisp样本进行比较。请记住,Lisp已经超过5倍了。

#4


It could possibly be a mindshare issue, as most teachers/professors probably learned imperative styles first as well.

这可能是一个思想共享的问题,因为大多数教师/教授也可能首先学习命令式的风格。

Also, I would guess that there is far larger body of work available for teaching imperitive styles.

此外,我猜想有更多的工作可用于教授不完美的风格。

#5


I can only assume its the fact that OOP seemed to be a favorite buzzword / style, So Schools stuck to that,

我只能假设OOP似乎是一个最喜欢的流行语/风格,所以学校坚持这一点,

I was taught OOP design from the get go, its only recently ive been teaching myself the Functional style of programming and i can see it has its advantages.

我从一开始就被教授OOP设计,它最近才一直在教自己编程的功能风格,我可以看到它有它的优点。

#6


Edit: What follows reflects the original title, "Why is functional programming not taught in schools," Schools have teachers, not professors. Schoolteachers do not write their own textbooks.

编辑:以下内容反映了原始标题,“为什么函数式编程没有在学校教授”,学校有教师,而不是教授。教师不写自己的教科书。

The textbook companies from which the teachers are allowed to purchase their materials are the largest problem. The textbook companies are quick to jump on "the next big thing", which was OOP a few years ago. Functional programming has fallen by the wayside. Many teachers cannot or are not allowed to teach a course without a textbook, so the course selection generally follows the availability of textbooks from the big vendors.

允许教师购买材料的教科书公司是最大的问题。教科书公司很快就会跳上“下一件大事”,这是几年前的OOP。功能性编程已经被淘汰。许多教师不能或不允许在没有教科书的情况下教授课程,因此课程选择通常遵循大型供应商提供的教科书。

#7


First, I find the basis of your question faulty because I was taught functional programming at school. (It wasn't what I started with, but we did do some functional programming.)

首先,我发现你的问题的基础是错误的,因为我在学校教过函数式编程。 (这不是我开始的,但我们确实做了一些函数式编程。)

Second, I question the ease of transferring from functional coding to imperative coding. I don't think it'd be as easy as you make it out to be.

其次,我质疑从功能编码转移到命令式编码的难易程度。我认为它不像你想象的那么容易。

Third, programming is (for most people) a job skill. The vast majority of shops use imperative programming. Therefore, it's most useful to future coders to learn imperative programming.

第三,编程(对大多数人来说)是一种工作技能。绝大多数商店使用命令式编程。因此,对未来的编码人员来说,学习命令式编程是最有用的。

#8


The clear control flow of imperative programming lends itself well to implementation and analysis of algorithms in a teaching environment. Object-oriented programming is a convenient extension of that, so it is naturally what gets used most often. Functional programming (declarative programming of any kind really), on the other hand, is a completely separate paradigm that requires a whole new set of considerations (performance and otherwise) many of which are much easier to visualize if you understand imperative programming first. After all, it all boils down to an imperative language in the end.

命令式编程的清晰控制流程非常适合在教学环境中实现和分析算法。面向对象编程是一种方便的扩展,因此它最常被使用。另一方面,函数式编程(实际上是任何类型的声明式编程)是一个完全独立的范例,需要一整套新的考虑因素(性能和其他方面),如果您首先理解命令式编程,其中许多考虑因素都更容易可视化。毕竟,这最终归结为一种必要的语言。

#9


There has to be an historical angle to this (showing my age) for the curriculums in school. Functional was all I had to learn when I started.

对于学校的课程,必须有一个历史角度(显示我的年龄)。当我开始时,功能是我必须学习的。

But putting that aside, you have to start somewhere so one of them has to be first. If you start with imperative then there will be things you reach for that wont be there when you learn functional and you'll have to get used to doing things differently. If you start with functional and move onto imperative then you'll have to get used to learning new concepts/constructs and remembering that they are there it use.

但是把它放在一边,你必须从某个地方开始,所以其中一个必须是第一个。如果你从命令开始,那么当你学习功能时,你将会遇到的事情不会存在,你将不得不习惯以不同的方式做事。如果你从功能开始并转向命令式,那么你将不得不习惯于学习新概念/结构并记住它们在那里使用。

Whenever you are programming you are trying to solve a problem. It is good to have both in your toolbox to reach for to solve the problem at hand. That's why I think it would be best to start with imerative and then learn functional: if you find yourself reaching for something not there that's indicative of having chosen the wrong tool to solve your problem.

无论何时编程,您都在尝试解决问题。最好在工具箱中同时使用以解决手头的问题。这就是为什么我认为最好从imerative开始,然后学习功能:如果你发现自己找不到那些表明选择了错误工具来解决问题的东西。

Other than that methinks it's a toss up.

除此之外,它是一个折腾。

#10


I was actually just at a talk given by the person who's developing Bootstrap (a programming curriculum currently run by Citizen Schools). He seemed to think the functional programming style provided a better background for algebra, since it hits on the concept of functions as both processes and objects (with properties of their own). (Of course, declarative programming languages can have first-class functions, too, but the focus is not on that nearly as much.)

我实际上只是在开发Bootstrap(一个目前由公民学校运营的编程课程)的人发表的演讲中。他似乎认为函数式编程风格为代数提供了更好的背景,因为它将函数的概念作为进程和对象(具有自己的属性)。 (当然,声明性编程语言也可以拥有一流的功能,但重点并不是那么多。)

Personally, I think that teaching functional programming first is worthwhile. The declarative approach is taught very early on in math class, so functional programming provides some new concepts that declarative programming does not. I agree with many of the above posters that the bit about it being "too hard" is a myth, it's been done.

就个人而言,我认为首先教授函数式编程是值得的。声明式方法很早就在数学类中讲授,因此函数式编程提供了一些声明式编程所没有的新概念。我同意上面的许多海报,认为它“太难”是一个神话,它已经完成了。

#11


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?

所以,我的问题是,如果在命令式之前在学校教授函数式编程,那么,为什么从它开始并不常见?

Though I was not fortunate enough to start off with a functional language, I do have colleagues who did. I also had a friend who studied Math, and the only language he learned while in school was Haskell!

虽然我没有幸运能够开始使用功能性语言,但我确实有同事做过。我还有一个学习数学的朋友,他在学校学到的唯一语言是Haskell!

There really are two things: Computer Science and Computer Engineering. Though the line is very thin, IMO, it depends a lot on the course (as mentioned above) and the concerned department's focus area which language to cut your teeth with. Most engineering schools start with one of C, C++ or Java -- which have a potentially large job market. Others, may start with Lisp, Haskell etc.

真的有两件事:计算机科学和计算机工程。虽然线条非常薄,IMO,但它在很大程度上取决于课程(如上所述)和相关部门的重点领域,哪种语言可以用来切割。大多数工程学院都是从C,C ++或Java开始的 - 它们有着巨大的就业市场。其他人,可以从Lisp,Haskell等开始。

#12


Functional programming is taught in most universities. Part of the reason it's not taught in high school is probably due to the "Functional programming is to hard" myth.

大多数大学都教授功能编程。高中没有教过它的部分原因可能是由于“功能编程难以”的神话。

#13


Dunno about your school by in my undergrad studies ML was an essential part of the basic programming languages course and there was an extra curriculum course dedicated to Haskel.

关于你的学校的Dunno在我的本科学习ML中是基础编程语言课程的重要组成部分,还有一个专门用于Haskel的课程。

#14


Honestly, I think this is the wrong question to ask.

老实说,我认为这是一个错误的问题。

If the goal of an introductory class is to teach basic computer science, algorithms, programmatically solving problems, then your course is fundamental and you can choose one based on clarity, simplicity, and getting your ideas across. Some functional languages will be great for this. Particularly if the students have little or no previous experience.

如果入门课程的目标是教授基本的计算机科学,算法,以编程方式解决问题,那么您的课程是基础,您可以选择基于清晰度,简单性和提出想法的课程。一些函数式语言对此非常有用。特别是如果学生很少或没有以前的经验。

Usually this isn't really the goal of many introductory classes, though. They may require certain techniques or certain languages for a later course. They may want to leverage particular libraries, etc. They may just have to match someone elses checkbox list of "features".

但是,这通常不是许多入门课程的目标。他们可能需要某些技术或某些语言用于以后的课程。他们可能想要利用特定的库等。他们可能只需要匹配某些人的“功能”复选框列表。

So I think you want to turn your question on its head. Figure out what it is the course is actually trying to achieve, and pick the best language you can for that purpose. In some cases, this may be a functional language.

所以我想你想把问题放在首位。弄清楚课程实际上要实现的目标,并为此目的选择最佳语言。在某些情况下,这可能是一种功能语言。

If what you are really asking is how best to teach introductory level programming and computer science, that's a different can of worms.

如果你真正问的是如何最好地教授入门级编程和计算机科学,那就是一种不同的蠕虫病毒。

#15


I think, it should, yes.

我想,它应该,是的。

Also - no console applications and no "color palette mixers", but unit tests first.

此外 - 没有控制台应用程序和没有“调色板混音器”,但首先进行单元测试。

Only if the students behave well and write test cases with extremely high coverage, they MAY be allowed to have a quick look at how to read characters from keyboard.

只有学生表现良好并编写具有极高覆盖率的测试用例,才可以让他们快速了解如何从键盘读取字符。

In my opinion, most bad coding practices (code smells, antipatterns) come from a total ignorance towards the theory and best practices.

在我看来,大多数糟糕的编码实践(代码味道,反模式)来自对理论和最佳实践的完全无知。

So - teach them F# first, forbid the use of console i / o and GUIs and only use unit tests.

所以 - 首先教他们F#,禁止使用控制台i / o和GUI,只使用单元测试。

Second, teach them imperative / functional mixed style in an OOP context with full use and explanation of design patterns.

其次,在OOP环境中教授命令性/功能性混合风格,充分利用和解释设计模式。

Then - and ONLY then they can try to put clickybuttons somewhere, maybe as a reward. But theory and good coding practices first. Otherwise we create the next generation of "RAD" - victims that can't even use indentation correctly and mistaken ctrl+c / ctrl+v for software development.

然后 - 然后他们可以尝试将clickybuttons放在某处,也许作为奖励。但首先是理论和良好的编码实践。否则我们会创建下一代“RAD” - 受害者甚至无法正确使用缩进,并将ctrl + c / ctrl + v误认为是软件开发。