nodejs与python
In this article, we'll be bold and claim that one of these technologies is winning. The question is: which one is it? Let's jump on in and find out.
在本文中,我们将大胆地说出其中一项技术正在获胜。 问题是:是哪一个? 让我们跳进去找出。
Node.js and Python are among the most popular technologies for back-end development. Common knowledge holds that there are no better or worse programming languages, and that everything depends on each developer's preferences.
Node.js和Python是用于后端开发的最受欢迎的技术。 常识认为,没有更好或更坏的编程语言,而且一切都取决于每个开发人员的偏好。
Yet, in this article, I am going to be brave and claim that one of these technologies – NodeJS or Python 3 – is winning. Which one will it be? Let’s see.
但是,在本文中,我将勇敢地说,其中一项技术( NodeJS或Python 3)正在获胜。 会是哪一个? 让我们来看看。
The criteria that I am going to consider are:
我要考虑的标准是:
Before I jump into a detailed side-by-side comparison, you can have a look at this infographic to get a general understanding.
在我进行详细的并排比较之前,您可以查看一下此信息图以获得一般理解。
NodeJS is not a programming language but rather an open-sourced runtime environment for JavaScript. It was initially released in 2009 by Ryan Dahl. The latest version – NodeJS 12.6.0 – was released in July 2019.
NodeJS不是一种编程语言,而是JavaScript的开源运行时环境。 它最初由Ryan Dahl于2009年发布。 最新版本– NodeJS 12.6.0 –已于2019年7月发布。
The most outstanding thing about Node.js is that it is based on Google’s V8 engine. It is a virtual machine with built-in interpreter, compilers, and optimizers. Written in C++, this engine was designed by Google to be used in Google Chrome. The purpose of this engine is to compile JavaScript functions into a machine code. V8 is well-known for its high speed and constantly advancing performance.
Node.js的最杰出之处在于它基于Google的V8引擎。 它是一个具有内置解释器,编译器和优化器的虚拟机。 该引擎由C ++编写,由Google设计,可在Google Chrome中使用。 该引擎的目的是将JavaScript函数编译为机器代码。 V8以其高速和不断提高的性能而闻名。
Python is an open-sourced high-level programming language. It was first released in 1991 by Guido van Rossum. The latest version is Python 3.8, and it was released in October 2019. But Python 3.7 is still more popular.
Python是一种开放源代码的高级编程语言。 它由Guido van Rossum于1991年首次发行。 最新版本是Python 3.8,它于2019年10月发布。但是Python 3.7仍然更受欢迎。
Python mainly runs on Google’s App Engine. Also developed by Google, the App Engine lets you develop web apps with Python and allows you to benefit from numerous libraries and tools that the best Python developers use.
Python主要在Google的App Engine上运行。 App Engine也是由Google开发的,它使您可以使用Python开发网络应用,并使您受益于最佳Python开发人员使用的众多库和工具。
NodeJS vs Python: 0 – 0
NodeJS与Python:0 – 0
Node.js is designed as an event-driven environment, which enables asynchronous input/output. A certain process is called as soon as the respective event occurs, which means that no process blocks the thread. The event-driven architecture of Node.js is perfectly suitable for the development of chat applications and web games.
Node.js被设计为事件驱动的环境,该环境启用异步输入/输出。 一旦相应的事件发生,就会调用某个进程,这意味着没有进程会阻塞线程。 Node.js的事件驱动架构非常适合聊天应用程序和Web游戏的开发。
By contrast, Python is not designed that way. You can use it to build an asynchronous and event-driven app with the help of special tools. Modules like asyncio make it possible to write asynchronous code in Python as it would be done in Node.js. But this library is not built in most Python frameworks, and it requires some additional hustle.
相比之下,Python不是那样设计的。 您可以在特殊工具的帮助下使用它来构建异步和事件驱动的应用程序。 像asyncio这样的模块使得可以像在Node.js中一样用Python编写异步代码。 但是该库不是在大多数Python框架中构建的,它需要一些额外的帮助。
This event-driven architecture brings Node.js its first point.
这种事件驱动的体系结构使Node.js成为第一要点。
NodeJS vs Python: 1 – 0
NodeJS与Python:1 – 0
First of all, since JavaScript code in Node.js is interpreted with the V8 engine (in which Google invests heavily), Node.js's performance is remarkable.
首先,由于Node.js中JavaScript代码是使用V8引擎(Google大力投资)来解释的,因此Node.js的性能非常出色。
Second, Node.js executes the code outside the web browser, so the app is more resource-efficient and performs better. This also allows you to use features that cannot be used in a browser, such as TCP sockets.
其次,Node.js在Web浏览器之外执行代码,因此该应用程序具有更高的资源效率和更好的性能。 这也使您可以使用浏览器无法使用的功能,例如TCP套接字。
Third, the event-driven non-blocking architecture enables several requests to be processed at the same time, which accelerates code execution.
第三,事件驱动的非阻塞体系结构允许同时处理多个请求,从而加快了代码执行速度。
And finally, single module caching is enabled in Node.js, which reduces app loading time and makes it more responsive.
最后,在Node.js中启用了单模块缓存,这减少了应用程序加载时间,并使响应速度更快。
Both Python and JavaScript are interpreted languages, and they are generally slower than compiled languages, such as Java. Python is beat out by Node.js in this case.
Python和JavaScript都是解释语言,它们通常比Java之类的编译语言要慢。 在这种情况下,Python被Node.js击败。
Unlike Node.js, Python is single-flow, and requests are processed much more slowly. So, Python is not the best choice for apps that prioritize speed and performance or involve a lot of complex calculations. Therefore, Python web applications are slower than Node.js web applications.
与Node.js不同,Python是单流的,并且处理请求的速度要慢得多。 因此,对于那些优先考虑速度和性能或涉及许多复杂计算的应用程序,Python并不是最佳选择。 因此,Python Web应用程序比Node.js Web应用程序慢。
Since Node.js is faster, it wins a point in terms of performance and speed.
由于Node.js更快,因此在性能和速度方面赢得了一点。
NodeJS vs Python: 2 – 0
NodeJS与Python:2 – 0
Syntax, for the most part, is a matter of personal preference. If I start saying that one is better and the other is worse, I know I'll face a lot of criticism and skepticism from our readers.
语法在大多数情况下是个人喜好问题。 如果我开始说一个更好,另一个更坏,我知道我将受到读者的很多批评和怀疑。
In fact, Node.js syntax is quite similar to the browser's JavaScript. Therefore, if you are familiar with JavaScript, you are not going to have any difficulties with Node.js.
实际上,Node.js语法与浏览器JavaScript非常相似。 因此,如果您熟悉JavaScript,那么Node.js不会遇到任何困难。
Python’s syntax is often deemed its greatest advantage. While coding in Python, software developers need to write fewer lines of code than if they were coding in Node.js. Python's syntax is very simple, and it is free of curly brackets.
Python的语法通常被认为是其最大的优势。 使用Python进行编码时,与使用Node.js进行编码相比,软件开发人员需要编写更少的代码行。 Python的语法非常简单,并且没有大括号。
Because of this, the code is much easier to read and debug. In fact, Python code is so readable that it can be understood by clients with some technical background. But again, it depends on personal preference.
因此,代码更易于阅读和调试。 实际上,Python代码可读性强,因此具有一定技术背景的客户都可以理解。 但同样,这取决于个人喜好。
But in the end, because Python's syntax is easier to understand and learn for beginners, Python wins a point here.
但是最后,由于Python的语法对于初学者来说更容易理解和学习,因此Python在这里赢得了一点。
NodeJS vs Python: 2 – 1
NodeJS与Python:2-1
Node.js spares you the need to create a large monolithic core. You create a set of microservices and modules instead, and each of them will communicate with a lightweight mechanism and run its own process. You can easily add an extra microservice and module, which makes the development process flexible.
Node.js使您无需创建大型的单核。 相反,您创建了一组微服务和模块,每个微服务和模块将与轻量级机制通信并运行自己的进程。 您可以轻松添加额外的微服务和模块,从而使开发过程变得灵活。
Also, you can easily scale a Node.js web app both horizontally and vertically. To scale it horizontally, you add new nodes to the system you have. To scale it vertically, you add extra resources to the nodes you have.
另外,您可以轻松地水平和垂直扩展Node.js Web应用程序。 要水平缩放它,请向您的系统中添加新节点。 要垂直缩放它,请向具有的节点添加额外的资源。
And finally in terms of typing, you have more options in Node.js than in Python. You can use weakly-typed JavaScript or strongly-typed TypeScript.
最后,在键入方面,Node.js中的选项比Python中的更多。 您可以使用弱类型JavaScript或强类型的TypeScript。
In order to scale an app, multithreading needs to be enabled. But Python does not support multithreading because it uses Global Interpreter Lock (GIL).
为了扩展应用程序,需要启用多线程。 但是Python不支持多线程,因为它使用了全局解释器锁(GIL)。
Although Python has libs for multithreading, it is not "true" multithreading. Even if you have multiple threads, GIL does not let the Python interpreter perform tasks simultaneously but rather makes it run only one thread at a time. Python has to use GIL even though it negatively affects performance because Python's memory management is not thread-safe.
尽管Python具有用于多线程的库,但它不是“真正的”多线程。 即使您有多个线程,GIL也不会让Python解释器同时执行任务,而是使其一次只运行一个线程。 Python必须使用GIL,即使它会对性能产生负面影响,因为Python的内存管理不是线程安全的。
Furthermore, Python is dynamically-typed. Yet, dynamically-typed languages are not suitable for large projects with growing development teams. As it grows, the system gradually becomes excessively complex and difficult to maintain.
此外,Python是动态类型的。 但是,动态类型的语言不适合具有不断增长的开发团队的大型项目。 随着系统的发展,该系统逐渐变得过于复杂且难以维护。
Evidently, Python loses out a bit to Node.js in terms of scalability.
显然,Python在可伸缩性方面对Node.js有所损失。
NodeJS vs Python: 3 – 1
NodeJS与Python:3-1
Node.js can be easily customized, extended, and integrated with various tools. It can be extended with the help of built-in APIs for developing HTTP or DNS servers.
Node.js可以轻松自定义,扩展并与各种工具集成。 可以借助内置的API对其进行扩展,以开发HTTP或DNS服务器。
It can be integrated with Babel (a JS compiler) which facilitates front-end development with old versions of Node or the browser.
它可以与Babel (一个JS编译器)集成在一起,后者可以促进使用旧版本的Node或浏览器进行前端开发。
Jasmine is helpful for unit-testing, and Log.io is helpful for project monitoring and troubleshooting. For data migration, process management, and module bundling, you can use Migrat, PM2, and Webpack.
Jasmine帮助进行单元测试,而Log.io帮助进行项目监视和故障排除。 对于数据迁移,流程管理和模块捆绑,可以使用Migrat , PM2和Webpack 。
And Node.js can be extended with such frameworks as Express, Hapi, Meteor, Koa, Fastify, Nest, Restify, and others.
Node.js可以使用Express ,Hapi, Meteor ,Koa,Fastify,Nest,Restify等框架进行扩展。
Python was introduced in 1991, and throughout its history a lot of development tools and frameworks have been created.
Python于1991年引入,在其整个历史中,已经创建了许多开发工具和框架。
For example, Python can be integrated with popular code editor Sublime Text, which offers some additional editing features and syntax extensions.
例如,Python可以与流行的代码编辑器Sublime Text集成在一起,后者提供了一些附加的编辑功能和语法扩展。
For test automation, there is the Robot Framework. There are also a few powerful web development frameworks, such as Django, Flask, Pyramid, Web2Py, or CherryPy.
对于测试自动化,有机器人框架 。 还有一些强大的Web开发框架,例如Django,Flask,Pyramid,Web2Py或CherryPy。
So, both networks are easily extensible, and both win a point.
因此,这两个网络都可以轻松扩展,并且都有优势。
Node JS vs Python: 4 – 2
Node JS vs Python:4 – 2
In Node.js, libraries and packages are managed by NPM – the Node Package Manager. It is one of the biggest repositories of software libraries. NPM is fast, well-documented, and easy to learn to work with.
在Node.js中,库和程序包由NPM(节点程序包管理器)管理。 它是软件库的最大存储库之一。 NPM快速,文档完善且易于学习。
In Python, libraries and packages are managed by Pip, which stands for “Pip installs Python”. Pip is fast, reliable, and easy to use, so developers find it easy to learn to work with as well.
在Python中,库和程序包由Pip管理,Pip代表“ Pip安装Python”。 Pip快速,可靠且易于使用,因此开发人员也发现易于使用。
Again, both win a point.
同样,两者都赢了一点。
Node JS vs Python: 5 – 3
Node JS vs Python:5 – 3
Node.js is predominantly used for the back-end development of web applications. Yet, for front-end development, you use JavaScript so that both front-end and back-end share the same programming language.
Node.js主要用于Web应用程序的后端开发。 但是,对于前端开发,您使用JavaScript,以便前端和后端共享相同的编程语言。
With Node.js, you can develop not only web apps but also desktop and hybrid mobile apps, along with cloud and IoT solutions.
使用Node.js,您不仅可以开发Web应用程序 ,还可以开发桌面和混合移动应用程序以及云和物联网解决方案。
Node.js is also cross-platform, meaning that a developer can create a single desktop application that will work on Windows, Linux, and Mac. Such universality is a great way to reduce project costs since one team of developers can do it all.
Node.js也是跨平台的,这意味着开发人员可以创建一个可以在Windows,Linux和Mac上运行的桌面应用程序。 这种通用性是降低项目成本的好方法,因为一个开发人员团队可以完成所有工作。
Python is full-stack, so it can be used both for back-end and front-end development. Similar to Node.js, Python is cross-platform, so a Python program written on Mac will run on Linux.
Python是全栈式的,因此可以用于后端和前端开发。 与Node.js相似,Python是跨平台的,因此在Mac上编写的Python程序将在Linux上运行。
Both Mac and Linux have Python pre-installed, but on Windows you need to install the Python interpreter yourself.
Mac和Linux均已预安装Python,但是在Windows上,您需要自己安装Python解释器。
While Python is great for web and desktop development, it is rather weak for mobile computing. Therefore, mobile applications are generally not written in Python. As for IoT and AI solutions, the popularity of Python is growing quickly.
虽然Python非常适合用于Web和桌面开发,但对于移动计算却相当薄弱。 因此,移动应用程序通常不是用Python编写的。 至于物联网和人工智能解决方案,Python的普及正在Swift增长。
In terms of universality, Node.js and Python go nose to nose. It would be fair to grant each a point here.
在通用性方面,Node.js和Python相互影响。 在这里给每个观点都公平。
Node JS vs Python: 6 – 4
Node JS vs Python:6 – 4
Node.js is JavaScript-based and can be easily learned by beginning developers. As soon as you have some knowledge of JavaScript, mastering Node.js should not be a problem.
Node.js是基于JavaScript的,初学者可以轻松学习。 一旦掌握了JavaScript知识,精通Node.js就不会有问题。
Installing Node.js is quite simple, but it introduces some advanced topics. For example, it may be difficult to understand its event-driven architecture at first. Event-driven architecture has an outstanding impact on app performance, but developers often need some time to master it.
安装Node.js非常简单,但是它引入了一些高级主题。 例如,一开始可能很难理解其事件驱动的体系结构。 事件驱动的体系结构对应用程序性能有显着影响,但是开发人员通常需要一些时间来掌握它。
Even so, the entry threshold for Node.js is still quite low. But this can mean that there are a lot of unskilled Node.js developers. This might make it harder for you to find a job in such a busy market. But if you are confident and have a great portfolio, you can easily solve this problem.
即使这样,Node.js的进入门槛仍然很低。 但这可能意味着有很多不熟练的Node.js开发人员。 这可能会使您很难在如此繁忙的市场中找到工作。 但是,如果您有信心并且拥有出色的产品组合,则可以轻松解决此问题。
On the other hand, if you're a business owner, you might face a problem of hiring low-quality specialists. But you also can solve this problem by hiring a trusted software development agency.
另一方面,如果您是企业主,则可能会遇到雇用低素质专家的问题。 但是您也可以通过雇用值得信赖的软件开发机构来解决此问题。
If you do not know JavaScript and you have to choose what to learn – Python or Node.js – you should probably start with the former. Python may be easier to learn because its syntax is simple and compact.
如果您不懂JavaScript,而必须选择要学习的知识– Python或Node.js –您可能应该从前者开始。 Python的语法简单而紧凑,因此可能更易于学习。
Usually, writing a certain function in Python will take fewer lines of code than writing the same function in Node.js. But this is not always the case because the length of your code greatly depends on your programming style and paradigm. Another plus is that there are no curly brackets as in JavaScript.
通常,与在Node.js中编写相同功能相比,在Python中编写特定功能所需的代码行更少。 但这并非总是如此,因为代码的长度在很大程度上取决于您的编程风格和范例。 另一个优点是没有JavaScript中的大括号。
Learning Python also teaches you how to indent your code properly since the language is indentation and whitespace sensitive. (The same is true for Node.js.) The problem with indentation and whitespace sensitive languages is that a single indentation mistake or a misplaced bracket can break your code for no obvious reason. And new developers may find it hard to troubleshoot such issues.
学习Python还可以教您如何正确缩进代码,因为该语言是缩进且对空格敏感。 (Node.js也是如此。)缩进和对空格敏感的语言存在的问题是,单个缩进错误或括号未正确放置都可能导致代码中断而没有明显的原因。 新开发人员可能很难解决此类问题。
Installing Python is more difficult than installing Node.js. If you have Linux or Windows, you should be able to install Python with no problem. If you use MacOS, you will see that you have Python 2.0 preinstalled – but you cannot use it as it will interfere with system libraries. Instead, you need to download and use another version. When you're configuring the development environment, do not forget to select the proper version.
安装Python比安装Node.js困难。 如果您使用的是Linux或Windows,则应该可以毫无问题地安装Python。 如果您使用MacOS,将会看到您已经预装了Python 2.0-但您无法使用它,因为它会干扰系统库。 相反,您需要下载并使用其他版本。 在配置开发环境时,请不要忘记选择适当的版本。
Both Python and Node.js are easy to learn, so it's hard to say objectively which one is simpler. It also is a matter of personal preference. So, once again both technologies receive a point.
Python和Node.js都很容易学习,因此很难客观地说出哪个更简单。 这也是个人喜好问题。 因此,两种技术再一次取得了成功。
Node JS vs Python: 7 – 5
Node JS vs Python:7 – 5
The Node.js community is large and active. It is a mature open-sourced language with a huge user community. It's ten years after its release and developers from all over the world have grown to love this technology. As a business owner, you can easily find Node.js developers. As a developer, you can always rely on peer support.
Node.js社区很大且活跃。 它是一种成熟的开源语言,拥有庞大的用户社区。 该技术发布已经十年了,来自世界各地的开发人员已经开始喜欢这项技术。 作为企业所有者,您可以轻松找到Node.js开发人员。 作为开发人员,您始终可以依靠同行的支持。
Python is somewhat older than Node.js, and it is also open-sourced. The user community has an immense number of contributors with different levels of experience. Once again, should you be a business owner or a developer, you benefit from the large community.
Python比Node.js稍旧,并且也是开源的。 用户社区拥有大量不同经验的贡献者。 再一次,如果您是企业主或开发人员,您将从大型社区中受益。
Both Python and Node.js have great communities, so both receive a point.
Python和Node.js都拥有强大的社区,因此两者都有共同点。
Node JS vs Python: 8 – 6
Node JS vs Python:8 – 6
Due to its event-based architecture, Node.js perfectly suits applications that have numerous concurrent requests, heavy client-side rendering, or frequent shuffling of data from a client to a server.
由于其基于事件的体系结构,Node.js非常适合具有大量并发请求,繁重的客户端渲染或频繁地将数据从客户端传输到服务器的应用程序。
Some examples include IoT solutions, real-time chatbots and messengers, and complex single-page apps.
一些示例包括IoT解决方案,实时聊天机器人和Messenger以及复杂的单页应用程序。
Node.js also works well for developing real-time collaboration services or streaming platforms. However, Node.js is not the best option for developing applications that require a lot of CPU resources.
Node.js还可以很好地用于开发实时协作服务或流平台。 但是,Node.js并不是开发需要大量CPU资源的应用程序的最佳选择。
Python is suitable for the development of both small and large projects. It can be used for data science apps, which involve data analysis and visualization, for voice and face recognition systems, image-processing software, neural networks, and machine learning systems. Python can also be used for the development of 3D modeling software and games.
Python适用于小型和大型项目。 它可用于涉及数据分析和可视化的数据科学应用,语音和面部识别系统,图像处理软件,神经网络和机器学习系统。 Python也可以用于3D建模软件和游戏的开发。
Both technologies let you develop a wide range of apps. Which one is more suitable depends exclusively on what you need. Therefore, choosing a better one does not make any sense. Here, neither technology gets a point because they do not compete directly in this way.
两种技术都可以让您开发各种应用程序。 哪种更合适取决于您的需求。 因此,选择一个更好的选择没有任何意义。 在这里,任何一种技术都没有意义,因为它们不能以这种方式直接竞争。
Node JS vs Python: 8 – 6
Node JS vs Python:8 – 6
Do you remember that I said I would prove that one technology is better than the other? Good!
您还记得我说过我会证明一种技术比另一种更好吗? 好!
But you also should remember that each software project has its own needs and requirements and you should choose your technology based on those needs.
但是,您还应该记住,每个软件项目都有其自己的需求和要求,并且应根据这些需求选择技术。
A language that works for one project may not work for another project at all.
适用于一个项目的语言可能根本不适用于另一个项目。
Now, I can draw conclusions. With the 8 – 6 score, Node.js is slightly ahead of Python. Keep these results in mind when choosing Python vs JavaScript for web development.
现在,我可以得出结论。 以8 – 6的得分,Node.js稍稍领先于Python。 在选择Python与JavaScript进行Web开发时,请牢记这些结果。
My company KeenEthics can't help you with Python but we are an experienced Node.js company willing to take up the challenge. If you are ready to change the game and start your project, feel free to get in touch.
我的公司KeenEthics无法为您提供Python方面的帮助,但我们是一家经验丰富的Node.js公司,乐于接受挑战。 如果您准备改变游戏规则并开始您的项目,请随时与我们联系 。
If you have enjoyed the article, you should definitely read another wonderful comparison: Angular vs React: What to Choose for Your App? or Progressive Web Apps vs Accelerated Mobile Pages: What's the Difference and Which is Best for You?
如果您喜欢这篇文章,则绝对应该阅读另一个精彩的比较: Angular vs React:为您的应用选择什么? 还是渐进式Web Apps与加速的移动页面:有什么区别,哪种最适合您?
I would also like to say thank you to Yaryna Korduba, one of the awesomest web developers at KeenEthics, for inspiring and contributing to the article.
我还要向KeenEthics的最出色的Web开发人员之一Yaryna Korduba表示感谢,感谢他对本文的启发和贡献。
The original article posted on KeenEthics blog can be found here: NodeJS vs Python: Choosing the Best Technology to Develop Back-End of Your Web App.
可以在以下网址找到发布在KeenEthics博客上的原始文章:NodeJS vs Python:选择开发Web App后端的最佳技术 。
nodejs与python