xxleyi / learning_list

聚集自己的学习笔记
10 stars 3 forks source link

Why isn't Functional Programming the Norm? #183

Open xxleyi opened 4 years ago

xxleyi commented 4 years ago

Why Isn't Functional Programming the Norm? – Richard Feldman - YouTube](https://www.youtube.com/watch?v=QyJZzq0v7Z4)

很棒的演讲,系统性的梳理了语言流行的原因,以及 OO 为什么得以横行于世。

语言流行的可能原因:

OO(面向对象)是语言流行的根本原因码? 答案:并不是。OO 流行的原因是,为了更好的实现「模块化」,恰好采用了 object 这一抽象,以及 class 这一形式。

image

image

当下的世界不再是 OOP 独霸,而函数式编程风格也开始逐渐流行开来。不讲高深的函数式编程概念,只是在某些局部贯彻两个基本点:

image image

xxleyi commented 4 years ago

Well, I don't know if C is the best language theoretically, but I can get things done.

In short, OOP is most popular because it is a reflection of how our brain functions.

Arguably most successful FP is Scala - a multi paradigm language by their own definition.

00:00:27 Richard Feldman: Why are things the way they are? It's complicated. 00:00:53 Richard Feldman: Outline 00:00:59 Richard Feldman: Part 1. Language 00:01:01 Richard Feldman: What languages are norm today. Top 10. No functional programming language. 00:01:42 Richard Feldman: How did they get popular. 00:02:05 Richard Feldman: 1. Killer apps. VisiCal to Apple II/Rails to Ruby/Wordpress & Drupal to PHP ... 00:06:21 Richard Feldman: 2. Platform Exclusivity. ObjC/Swift to iPhone sales / JS to web&internet user / C# to Windows&VS 00:10:21 Richard Feldman: 3. Quickly Upgrade. CoffieScript&TypeScript to JS / Kotlin to Java 00:13:27 Richard Feldman: 4. Epic Marketing. $500M Java marketing compaign in 2003 00:16:15 Richard Feldman: 5. Slow and Steady. Python story 00:17:53 Richard Feldman: Other Popularity Factors. Syntax/JobMarket/Community 00:18:46 Richard Feldman: Why are the most popular languages OO except C. 00:19:15 Richard Feldman: Part 2. Paradigm 00:19:39 Richard Feldman: Uniuquely OO features. Encapsulation = Modularity 00:35:35 Richard Feldman: They are OO because modularity is a good idea and they originally got if from OO by chance. 00:35:47 Richard Feldman: Part 3. Style 00:35:50 Richard Feldman: FP Style : avoid mutation and side effects 00:36:31 Richard Feldman: Why isn't FP style the norm? No sufficiently large 'killer apps' / No exclusivity on large platforms / Can't be a quick upgrade if substantially diffeerent / No epic marketing budgets / Slow & steady growth takes decades 00:41:02 Richard Feldman: OO languages are the norm not because of uniquely OO features. 00:41:32 Richard Feldman: FP style just need time to become the norm. 00:41:50 Richard Feldman: Questions. 00:42:03 Question1: How do you see Lisp fiting in is it a FP language or not? 00:42:21 Answer: Classifying a language is functional or not is kind of arbitrary, definitely very fuzzy and ultimately not as important as talking about the style and their support for the style like being able to avoid mutation and side-effects and still have a good experience. 00:44:03 Question2: How does performance factor into this. 00:44:26 Answer: Perfromance is not the key factor to the popularity of a language.

语言演化是个复杂的话题,由于惯性的存在,未来函数式编程将长期寄居于主流语言之中,并逐渐流行开来。但纯粹如 Haskel 的函数式编程语言,在我有生之年几乎不大可能成为主流。

如果 Scala 能成为主流,那也算是奇迹了。

结论:抓紧学习 Scala 和 Java。

xxleyi commented 4 years ago

函数式在逻辑上最简单,最容易推理,能更有效的避免错误,但使用起来却需要费一些功夫。根本原因是是它并不符合大多数弱数理背景程序员的「mental model」。

面向对象式是逻辑上最复杂,极难推理,很容易滋生各种错误,但却能让人更「自然」的使用。根本原因是它最为符合大多数弱数理背景程序员的「mental model」。

但这只是过去短短二三十年的历史而已。从最为长远的视角来看,计算机程序的发展是越来越声明式,越来越面向软件设计和维护而非机器运行效率。

至于大多数程序员的「mental model」,也许也是在向前演化。最起码,越来越多的人,尤其是新晋编程语言的设计者们,开始在语言设计上有意引导程序员优先使用 immutate 变量,并努力平衡对多种编程范式的支持。

未来十年的软件编码趋势是:小范围和骨肉层面上优先使用不可变加函数式,大的思维和架构层面上利用面向对象下成熟的设计模式,有效管理和隔离大系统整理复杂度,方便分工协作。