为什么功能语言被认为是多线程环境的福音? [英] Why are functional languages considered a boon for multi threaded environments?

查看:72
本文介绍了为什么功能语言被认为是多线程环境的福音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听到了很多有关功能语言的知识,以及它们如何很好地扩展,因为功能周围没有状态.因此该功能可以大规模并行化.

I hear a lot about functional languages, and how they scale well because there is no state around a function; and therefore that function can be massively parallelized.

但是,这对我来说意义不大,因为几乎所有现实世界中的实用程序都需要/需要状态来照顾.我还发现有趣的是,大多数主要的缩放库(即MapReduce)通常都是用命令式语言(如C或C ++)编写的.

However, this makes little sense to me because almost all real-world practical programs need/have state to take care of. I also find it interesting that most major scaling libraries, i.e. MapReduce, are typically written in imperative languages like C or C++.

我想听听我听到的这种炒作来自的功能营地.

I'd like to hear from the functional camp where this hype I'm hearing is coming from..

推荐答案

添加一个词很重要:没有 shared 状态".

It's important to add one word: "there's no shared state".

任何有意义的程序(使用任何语言)都会改变世界的状况.但是(某些)功能语言使无法同时从多个线程访问同一资源.缺少 shared 状态使多线程安全.

Any meaningful program (in any language) changes the state of the world. But (some) functional languages make it impossible to access the same resource from multiple threads simultaneously. The absence of shared state makes multithreading safe.

这篇关于为什么功能语言被认为是多线程环境的福音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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