Recently, Python has been included in the national Computer Grade examination subjects, into the primary school textbooks, won 2018 years of top programming language honor, it can be said that Python more fire will be more fire. This article is not to add oil on this fire, but in a timely manner for Python poured a basin of cold water, steady development is a programming language on the right track. The author used the go language to complete a variety of tasks that had been done with Python, and found that the go language approach seemed to be better.
Among them, the completed tasks such as saying:
Processing the Cloudfront logs stored on the S3;
Move terabytes of data from one bucket to another in S3, or other areas;
Compare the data in the database and the files in the S3 to ensure data synchronization.
Many are a one-time task, so the scripting language is appropriate. The program can be written out very quickly, and it will not be used until it is almost exhausted. Typically, each task is new and unique, so there is little likelihood of code reuse.
Here's where Go is stronger than Python:
The compiler is good.
I've been making stupid mistakes in Python. such as the wrong variable name or function name, or pass the wrong argument to the function. Devtools can find some errors, but usually these tools require special settings. I've never been able to set the pylint perfectly, and I don't like the cumbersome Ides that need to be configured separately.
The worst case scenario is the name of the wrong variable hidden behind the conditional logic. The code runs for several hours until the error is triggered. Then you have to start all over again.
Unit tests can usually catch these errors, but it's hard to get 100% code coverage, and I don't want to waste time writing tests for one-off scripts.
Compiling the language completely avoids these problems. The compiler can find all the stupid errors. So, for any task that exceeds 100 lines of code, I prefer to use Go.
Development speed
The downside of the compiler is that it usually slows down development. This is especially noticeable in C/C + + and Java.
But Go is very simple and I find it has a very small impact on development speed. Don't get me wrong, I'm still faster with Python, but using Go usually achieves Python's 85% efficiency.
Considering that using compilers can make fewer mistakes, 85% is well worth it.
Better concurrency
You must know that the purpose of Go development is to execute concurrently.
In my team we generally need concurrent programming because we are dealing with S3 or large amounts of data in the database.
If there is a lot of IO in the task (so many tasks), then we can use the Python thread. But if you need a lot of CPU, Python is hard to do because it has a global interpreter lock (interpreter lock).
It's great to use Go Multi-threading without any special processing to work properly. You must have seen the ctrl-c trying to end a multithreaded task in Python without reacting?
More easily deployed
I like a single binary file. Usually I run the code on the EC2 machine so that it is closer to the S3 and the database on the network. With Python, I need to install all the packages on the remote machine and make sure that no one else is installing any conflicting stuff.
Although virtualenv can solve this problem, I still think Go is easier.
I usually cross-compile the code into a Linux binary on my Mac and then copy it to the remote machine, and then I can do it. All dependencies are placed in a binary file.
A consistent style
Initially, the GOFMT tools were really annoying, especially when they used tab instead of spaces. I think they're crazy.
But after a lot of use, I started to rely on it. It can provide a perfect code format directly. Regardless of the project, all code has the same style, because style is part of the standard Go tool chain.
It takes more effort to achieve the same effect in Python. The pylint must be configured correctly and the configuration of each project is guaranteed to be the same.
A better tool chain
GOFMT is just an example of a common tool chain. All my favorite editors, whether Vscode, Vim or sublimetext, have very good go language extensions, using the standard go toolchain.
As a result, I can get only hints that approximate Java, but without the use of a real IDE. And using Python has never been able to enjoy such a function.
Disadvantages
Many of the articles I read criticizing the Go language are saying that it lacks some obvious functionality, such as generics. But without generics I've never had any trouble. In fact, map and slice can do a lot of work. But I have some other problems.
Go is a language of opinion
First of all, Go is probably the most opinioned language I've ever used. From forcing tabs instead of spaces (assuming you're using gofmt), to forcing the use of a fixed directory format, or even forcing the code to be written in the GOPATH environment variable, many Go things can't be changed.
One reason to have a point of view is that it is easy to learn, because none of these features will change. But if you don't want to export a name that starts with a capital letter, there's no way. Fortunately, none of these issues will be a reason for me not to use Go, but I can understand that some people cannot accept it.
Python is more flexible.
Lack of library support
It's not fair to compare Python and Go in this area. Go is very young, but I am puzzled when I find out that the go itself does not support a feature. To my disappointment, some people put some code on the STACKOVERFOLW that should be built-in functions, and then everyone would just paste the code into the project as if it were nothing.
Give me two examples I have found in recent years:
Sort the slice (fortunately it gets much easier in Go 1.8)
Math.Round can only be used for integers, not rounded up into floating-point numbers (such as rounding to the nearest. 5). There was no math.round even before Go 1.10.
Of course, there are some reasons why go doesn't have generics, because Go's design idea is to add absolutely essential things to the standard library.
I understand these two reasons, but I still find it annoying to have to write my own code when I have a very simple function.
Hopefully the Go language will get better and less painful.
Original: Thinkfaster.co/2018/07/goo ... CSDN Information Author: Jake Wilson Translator: Crescent, Zebian: Min
CSDN College Go Language course recommended:
1.go language Combat-Detailed Golang tutorials
2.Go Language-Basic article
3.Go Language-Advanced article