What are the pros and cons of node. js and Python as a back-end service programming language?

Source: Internet
Author: User
Tags windows support
Front end, but want to learn a back end of the language, is originally want to learn node JS, after all, if the node as the backend language to my front-end of the JS familiarity is also helpful, but found that node learning curve is a bit steep, and there is no good learning materials, and the domestic node is not very popular, Find Python is a good back-end language, learning materials are also many, now I am in a tangle between the two, seeking the guidance of the great God?

Reply content:

@SUN Ruoyu to say a little bit about node's not being good at crud.

The CRUD application and the platform itself do not have much to do with, more to look at the upper open Source library. Express + (MONGO + Mongoose) | | (Node-mysql + sequelize) The development of CRUD is also fast, and more crucially, node itself asynchronously has much higher database I/O performance than Python.

Some people say that node lacks a "mature" framework, in fact, it is related to the development of the node community, a number of leading developers are advocating "write a good thing to do a small program, and then string them together" of the Unix philosophy, plus NPM for the mutual dependence of the package is handled very well, So flexibility is actually one of node's selling points. In my personal view, node does not need a web framework such as "chatty" like Rails/django. Disclaimer: The following comparisons may have a strong personal color

Places in node. js > Python
    1. Quick: There are two aspects, the first is the V8 engine fast, behind the V8 engine is the Lars Bak God, he created a high-performance Smalltalk engine and Java hotspot engine (now Java's default VM), He led the V8 engine to make JavaScript speed reach a new stage. The second is asynchronous execution, and node. JS is functionally an asynchronous network and IO Library based on the V8 engine, much like Python's twisted, unlike the node. js event Loop, which is very deep in the language, You can imagine that the entire file is in a large event loop when it is executed.
    2. NPM:NPM can be said to be the most comfortable package management, NPM as node. JS's official package management, bringing together the entire community's most concentrated resources. Unlike Python, which has experienced Easy_install and Pip, there are 2TO3 problems.
    3. Windows Support: node. JS has Microsoft's add-on, Windows is basically considered a one-time citizen to support, LIBUV has been able to do a good job of unifying the cross-platform API, while Python also has official support for Windows, but the total feeling is second-class citizens, sometimes some problems.
where Python > node. js
    1. Language: Just from a language perspective, Python is much more comfortable to write than JavaScript. The JavaScript design itself has many flaws, after all, it was designed as a script to do a few simple tasks in the browser, so once the code was large, maintenance was difficult (though the node. JS module greatly improved the problem). However, using Coffeescript can greatly improve JavaScript, almost equivalent to Python.
    2. Maturity: Maturity includes the language itself is mature, and the framework and ecosystem are also very large. The vast majority of the framework of node. JS is new, some APIs are changing, some are not being maintained, and there is no framework like Django's Shimo feel. Python's mainstream Orm SQLAlchemy is also very mature.
where Python and node. js are hard to compete
    1. Asynchronous Style:Node.js's asynchronous style is the CPS, which is the layer callback, based on the event, much like the JavaScript in the browser. The CPS benefit is that people who are familiar with browser JavaScript can get started quickly and have little difficulty learning. The disadvantage is that logic is complicated, it becomes very difficult to maintain, basically need to pass async.js this kind of library, or use promise. Python's async, in addition to twisted like node. JS, has a coroutine-based gevent,coroutine that makes it easier to maintain asynchronous code, but the learning curve is steep.
    2. Application scenario: If it's a crud app, then you don't want to be a python directly, node. JS itself is not good at Crud app (most of node. js is directly naked outside, not have a nginx in front, otherwise websocket can not be used, but the new version of Nginx support WebSocket), code is not maintenance, and Python wsgi is very suitable for , and there are a lot of mature stacks. If you are more inclined to real-time, such as a chat, the node. JS implementation is easier. There are still differences between the two scenarios.
Personal contact with Django and a small amount of node. js
Also consider which of the following Web development will be used primarily?
In my opinion, Django is more comprehensive, developing a complete Web site or cms.
The features of node. JS are also very prominent, but it is not cost-effective to develop a complete website with node. js, and I prefer to develop a restful server with node. JS to address high-frequency requests while avoiding the depth of event nesting.
So, with this idea, Django does web development, in some parts of the need for restful or high-frequency requests with node. js
Each play its strengths ... The answer to Sun Rouyu in front has been very comprehensive. To add, NPM and Commomjs's require have gone beyond a simple package management tool that has evolved into a form of system architecture.
In addition, I write node. js with Coffeescript to enjoy the benefits of two worlds.
Although Python also has an asynchronous library, the implementation of different frameworks and libraries is inconsistent because async is not its DNA. For node. js, the asynchronous pattern has become the norm that the modules of 99% must first comply with, which is necessary for a robust daemon. Python's gevent brings a non-blocking IO and coroutine synchronous approach encapsulated asynchronously enough to explode twisted;
Nodejs features are non-blocking IO and faster language interpreters, but the event-based programming model is more appropriate to the user's response to the front-end, is not very suitable for most of the RPC or loop-style service-side logic;
Now distributed and SMP architectures gevent multi-process +coroutine+ simple language features + easy to C + + performance extension is definitely the ideal choice. The frame express difficulty of node. js should be similar to the Python framework Django,tornado,flask and so on. Already familiar with JS, it is better to start from node. js. Differences in Performance

I don't think a lot of people's systems are more complicated than PayPal.
PayPal is now full Nodejs (background bi may be Java)

However, prototype mode is difficult to build large code
Transform into OO programming difficulty and write Python no difference

Callback is not a problem I don't use those callback JS library pure JS Native mode
Get used to it is good to refer to this again:

What exactly is node. js?


Node is a server-side JavaScript interpreter that will change the concept of how the server should work. Its goal is to help programmers build highly scalable applications and write connection codes capable of handling tens of thousands of simultaneous connections to a single (one) physical machine.
To try to explain what node. js is, this article will briefly cover some of the background information: it's the problem to solve, how it works, how to run a simple application, and finally, Node in what case is a good solution. This article does not cover how to write a complex node application, nor is it a comprehensive node tutorial. Reading this article should help you decide whether you should continue to learn Node so that it can be used in your business. Using Python and Nodejs, it's true that Python's language design is more elegant than JavaScript, but the actual development of Nodejs is actually more useful than python.
Nodejs several major advantages:
1. Nodejs environment is very convenient to build, NPM package management is also good enough, a few commands to run it, and the Python environment installation is painful enough
2. Nodejs forced async, io async, MySQL asynchronous, HTTP request asynchronous, and asynchronous callback is a natural use of JavaScript, so the actual project does not have much optimization can be much faster than the Python synchronization MySQL
3. Nodejs and front-end unification, the actual development does not need to like Python the environment switch, the language switch
4. nodejs File system Watch function is very convenient for testing, compiling and so on, to a large extent, improve the development efficiency
5. Nodejs has become a huge ecosystem today: the Library on NPM is the most, the angularjs that is very close to the back-end programming style, the test framework that is combined with watch, webpack,livereload,pm2, all these things for web development, Are far superior to the development of other languages
6. The evolution of the JavaScript language has also made JavaScript more useful, such as a callback that has evolved into promise,async/await must be python, which says Python is not very reasonable.
If you want to align the bits, the Nodejs should be the Python Tornado framework.
Previously studied Baidu's Clouda, is a two have been contacted.
I focus on Tornado good, Nodejs in tornado before the advantage is not big.
First of all Performance
Node is superior in performance compared to Tornado, but the advantage is very small, can be said to be language bonus,c++ of the bonus. But their design ideas are basically similar, so the performance gap is not big, not to mention if the business processing speed is slow, the throughput is too large is virtual.
Secondly Ease of Use
This is based on the tornado of Python, you can write asynchronous code in the form of synchronization without the help of a lot of callbacks and closures, which is very important for heavy business scenarios, which is the steep cause of node learning costs, and once used poorly, The risk of memory explosion due to node's large block of closures presumably will be frustrating for everyone learning node.
Scalability
There is no doubt that, in addition to LUA, there is no other language to say that Python extensibility is convenient, and that it is easy to use C language to customize extensions for compute-intensive business or functionality (I even wrote an awk nested programming). Not to mention Python itself also exists in the geometric multiples of the NPM expansion pack (hehe, I should also know that, at least npm a lot of modules can not be looked directly at, you have seen a module only a function, inside a sentence? The number of high-quality libraries can not be compared with pypi, the development threshold is there, so I will not be bitten to admit that the number of NPM package is more python, because too much garbage. You can also modify the frame level directly and customize it (under license conditions, of course), redefining engine behavior, eventloop behavior, and high degrees of freedom.
maintainability
Needless to say, JS code is difficult to write the elegance of Python, and a variety of callback and closures for readability is simply a disaster. Plus the JS language itself has a lot of pits. This round of Python is outright.

In short, I personally is such a situation, if someone take Nodejs and tornado to say things, I will tell him I am not python. Even if I had to resign.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.