Read the "Why I'm moving from Python to go" experience

Source: Internet
Author: User

At first I thought it was a 2013-year old post, did not expect to be 2015 years. Do not know python do not spray ah. You say, " I don't know python, and I don't want to maintain the bad code that my predecessor wrote, I go cow b, so I'm going to refactor it again!" "I think you have a normal IQ point.

I think go is good, but if it's not a specific area of development, not enough mature and stable libraries are still a hassle .

http://www.jianshu.com/p/afa14e631930

Http://www.lupaworld.com/article-254456-1.html

Although Python is very powerful, but we also encountered some problems when using, mainly by the following aspects:

  • Dynamic language

    python is a dynamic, strongly typed language. However, a run-time error such as INT + string can still occur, because for a variable, when writing code, we sometimes easily forget what kind of variable it is (reviews: Really rarely encountered, each function parameter type has a convention, So it won't be remembered at all).

    reviews: encountered, but this is not to follow the convention caused by the name of the reason, the different modules with the same name is possible, another problem in the static language also has Ah, you link to a wrong library. At run time with )

  • As mentioned above, the static language can be compiled to help us detect, and do not have to wait until the runtime problems to know. While we have well-developed test cases, there are always cases where case is missing. So every time there was a run-time error, I thought about how good it would be if I could compile it.  ( reviews: Do you have a compile-time check to run without error?) Is the code finished? Almost every time you add a function or debugging, read the feeling write bad or write unclear, should do some cleanup, after all, people to use the library or language understanding is gradually in-depth. )


    • performance

      > This has always been a place where many people spit out python, but Python has something to do with it, and it's hard to use Python to develop some high-performance modules.

      python Gil leads to the inability to really multi-threading, People may say that I use a lot of process is not finished. However, if some computations involve multi-process interaction, the communication overhead between processes has to be considered.

      But even if we use multiple Django processes to handle HTTP requests , Python still can't handle some super-large requests. So we use Openresty to implement high-frequency HTTP requests using LUA. This in turn leads to the use of two development languages, and some logic has to write two different codes. ( point Comment: No Django, no say, but high-frequency requests can be optimized with Cython, now the Cython is more convenient than the 2013 time ... )


    • Synchronous Network Model

      The Django Network is a synchronous block, that is, if we need to access a service outside, Django cannot handle any other logic while waiting for the result to return (except, of course, multithreading). If it takes a long time to access an external service, it means that our entire service is completely unavailable for almost a long time.

      In order to solve this problem, we can only continue to open the Django process, but also to ensure that all services can quickly handle the response, but think this is really a very unreliable thing.


  • Asynchronous Network Model

    The Tornado network model is asynchronous, which means that it does not appear as Django does because the service cannot respond because the external service is unavailable. In other words, compared to Django, I am very fond of tornado, small and simple, before also wrote a few in-depth analysis of tornado article. Although Tornado is asynchronous, Python's MySQL library does not support asynchrony, which means that if we access the database in tornado, we may still face the fact that the entire service is not available due to database problems. ( for historical reasons, almost all of Python's standard libraries are synchronized.)

  • In fact, the biggest problem of the asynchronous model is the fragmentation of the code logic, because it is triggered by the event, so we are all through callback related processing, so the code inside often appear to do one thing, pass a callback, and then callback inside and pass callback situation, The result is that the entire code logic is very confusing. Python does not have native coprocessor support, although it is possible to support the process by gevent,greenlet this patch, but after all, the Python source code is changed. In addition, the yield of Python can also be a simple co-simulation, but after all, can not cross the stack, the limitations are very large, do not know whether the 3.x version has been improved. ( reviews: Python3.4 introduced Asyncio,Python3.5 introduced async and await, even if the use of twisted, not a bunch of callback ah. You got a mistake? Not clear across Stacks )


    • Develop operations deployment

      When I first used the Python development project, I did not successfully install the package required for the project, the installation of the successful MySQL library has been a long time. Later, it was a colleague who packaged the entire Python directory for me so I could run the project normally. In other words, now that there is Docker, it is one thing that makes people happy. ( reviews: No virtual python environment used?) Virtualenv,python call MySQL connector directly, how can you install a heap of libraries? Unknown so )

      While deploying the Python service, we need to install a bunch of packages on the server, which is very troublesome, although it is possible to solve the deployment problem by puppet,salt these automation tools, but compared to the static compilation language only throw a binary file, it is much more convenient. (Review: Test environment is the development environment, you are sure that static compilation does not solve the dependency on the other machine can run? )


    • code out of control

      python is very flexible and simple, write C dozens of lines of code to get the function, Python line of code can not be solved. But it is too simple, but many students can not be in-depth thinking of the code, the entire architecture for careful consideration. Come a demand, PA PA, the keyboard knocked out the speed of implementation, the result is more and more chaotic code, resulting in the entire project code out of control.

      reviews: It seems to have not heard the use of that language code is not out of control, this is simply rejected small step refactoring, code modularity is poor, module coupling high and so on a series of problems caused, Python implementation code, but can have the energy to continue rapid improvement. )

The above mentioned are the problems we encountered in the actual project using Python, although eventually resolved, but it makes me increasingly feel that with the increase in project complexity, the increase in traffic performance pressure, Python is not a good choice.


(Reviews: Is there a problem with Python?) Of course there are many, like

* The supporting asynchronous library is too small and lacks maintenance.

* Cannot limit the type of the variable (although there is Python3.5 type hints, but it is not the same as the comment)

* The computational performance itself is much worse than the V8 engine's JavaScript (c)



Read the "Why I'm moving from Python to go" experience

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.