node.js是传统脚本语言(如Perl和Python)的可行替代方案吗?

时间:2021-09-03 12:08:12

Recently I've fallen out of love with Perl as a cross-platform general purpose scripting language, and niether Python nor Ruby ever really appealed to me either.

最近我已经不再喜欢Perl作为跨平台的通用脚本语言了,而且Python和Ruby也没有真正吸引过我。

But I've been getting more and more comfortable with JavaScript in the browser, it's getting pretty good performance in contemporary engines such as V8, and node.js has been really taking off for a couple of years now.

但是我在浏览器中越来越习惯使用JavaScript,它在V8等现代引擎中的性能相当不错,而node.js现在已经真正起飞了几年。

But node.js is intended for server side networking programming primarily. As it declares itself on its homepage:

但node.js主要用于服务器端网络编程。正如它在其主页上声明的那样:

Event-driven I/O server-side JavaScript environment based on V8.

基于V8的事件驱动的I / O服务器端JavaScript环境。

I would like to know if node.js is also currently suitable as a general scripting language on *nix and Windows as an alternative to Perl, Python, and Ruby.

我想知道node.js目前是否也适合作为* nix和Windows上的通用脚本语言,作为Perl,Python和Ruby的替代品。

I don't find much talk of it being used in this way yet it does seem to have a broad community and I haven't noticed anything saying it's not suitable for this use. Is it widely used this way? Or does it lack key features or modules for this type of thing?

我没有太多关于以这种方式使用它的说法,但它确实似乎有一个广泛的社区,我没有注意到任何说它不适合这种用途。这种方式被广泛使用吗?或者它缺少这种类型的关键功能或模块?

1 个解决方案

#1


22  

In terms of Node.js, I can't see it becoming a mainstream way of using javascript as a general purpose scripting language. The main reason for that would be the async nature of 99% of the libraries and functions available in Node.js. Because of the async nature, you have to completely change your thinking. Not having synchronous methods available is the stumbling block. It makes things less script like as your code is not linear anymore.

就Node.js而言,我无法看到它成为使用javascript作为通用脚本语言的主流方式。主要原因是Node.js中99%的库和函数的异步性质。由于异步性质,你必须完全改变你的想法。没有可用的同步方法是绊脚石。它会减少脚本,因为代码不再是线性的。

So the adoption is not happening for the simple reason that most of the time you're thinking: I could write this a lot quicker/simpler in Ruby/Python/... (just try downloading 5 different files, zipping them and copying them to another folder using Node.js)

因此,大多数时候你都在考虑采用这种简单的原因:我可以在Ruby / Python /中更快/更简单地写这个...(只需尝试下载5个不同的文件,压缩它们并复制它们使用Node.js到另一个文件夹)

As people get more used to thinking and programming in an async way adoption of node.js as a general purpose scripting tool might change.

随着人们越来越习惯于以异步方式思考和编程,将node.js作为通用脚本工具的采用可能会发生变化。

If every async function in node had a synchronous version, adoption would have been different and people would have ended up with non scalable node.js servers because they choose to use sync methods in places. Arguably, node would not have become popular as the performance numbers wouldn't have made it stand out.

如果节点中的每个异步函数都有同步版本,那么采用会有所不同,人们最终会得到不可扩展的node.js服务器,因为他们选择在某些地方使用同步方法。可以说,节点不会变得流行,因为性能数字不会让它脱颖而出。

In short:

简而言之:

adoption of node.js is happening because of it's async nature. adoption of node.js as a client side general purpose scripting tool is not happening due it's lack of synchronous functions.

node.js的采用正在发生,因为它具有异步性质。由于缺少同步功能,因此没有采用node.js作为客户端通用脚本工具。

Please keep in mind that this is based on my own experience and opinion and not on articles or numbers I found on the internet so try it out for yourself and make up your own opinion.

请记住,这是基于我自己的经验和意见,而不是我在互联网上找到的文章或数字,所以请亲自尝试并制定自己的意见。

#1


22  

In terms of Node.js, I can't see it becoming a mainstream way of using javascript as a general purpose scripting language. The main reason for that would be the async nature of 99% of the libraries and functions available in Node.js. Because of the async nature, you have to completely change your thinking. Not having synchronous methods available is the stumbling block. It makes things less script like as your code is not linear anymore.

就Node.js而言,我无法看到它成为使用javascript作为通用脚本语言的主流方式。主要原因是Node.js中99%的库和函数的异步性质。由于异步性质,你必须完全改变你的想法。没有可用的同步方法是绊脚石。它会减少脚本,因为代码不再是线性的。

So the adoption is not happening for the simple reason that most of the time you're thinking: I could write this a lot quicker/simpler in Ruby/Python/... (just try downloading 5 different files, zipping them and copying them to another folder using Node.js)

因此,大多数时候你都在考虑采用这种简单的原因:我可以在Ruby / Python /中更快/更简单地写这个...(只需尝试下载5个不同的文件,压缩它们并复制它们使用Node.js到另一个文件夹)

As people get more used to thinking and programming in an async way adoption of node.js as a general purpose scripting tool might change.

随着人们越来越习惯于以异步方式思考和编程,将node.js作为通用脚本工具的采用可能会发生变化。

If every async function in node had a synchronous version, adoption would have been different and people would have ended up with non scalable node.js servers because they choose to use sync methods in places. Arguably, node would not have become popular as the performance numbers wouldn't have made it stand out.

如果节点中的每个异步函数都有同步版本,那么采用会有所不同,人们最终会得到不可扩展的node.js服务器,因为他们选择在某些地方使用同步方法。可以说,节点不会变得流行,因为性能数字不会让它脱颖而出。

In short:

简而言之:

adoption of node.js is happening because of it's async nature. adoption of node.js as a client side general purpose scripting tool is not happening due it's lack of synchronous functions.

node.js的采用正在发生,因为它具有异步性质。由于缺少同步功能,因此没有采用node.js作为客户端通用脚本工具。

Please keep in mind that this is based on my own experience and opinion and not on articles or numbers I found on the internet so try it out for yourself and make up your own opinion.

请记住,这是基于我自己的经验和意见,而不是我在互联网上找到的文章或数字,所以请亲自尝试并制定自己的意见。