javascript node.js 是 Perl 和 Python 等传统脚本语言的可行替代方案吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13899623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is node.js a viable alternative to traditional scripting languages like Perl and Python?
提问by hippietrail
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?
我没有发现太多关于它以这种方式使用的讨论,但它似乎确实有一个广泛的社区,而且我没有注意到任何说它不适合这种用途的内容。这种方式被广泛使用了吗?或者它是否缺少此类事物的关键功能或模块?
回答by AndyD
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 中的每个异步函数都有一个同步版本,采用情况就会不同,人们最终会使用不可扩展的 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 缺乏同步功能,因此没有采用 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.
请记住,这是基于我自己的经验和意见,而不是我在互联网上找到的文章或数字,因此请自己尝试并得出自己的意见。