Why you should choose Go lang and abandon Python 2020?
By: Shiv Bajpai
Tags: Programming, Golang, Python, Machine Learning, Cloud Computing

Why choose Go programming?

1. Compile to a single binary

Golang is a compiled language and the developers of Googe put a lot of effort into it. It uses static linking to actually combine all dependent library files and modules into a single binary based on the operating system type and environment, which also means that if you want to compile your back-end applications to your Linux operating system and In an X86-based CPU, you only need to download the compiled binary application to the server, and then the back-end application can work, which does not require any dependent files.

2. Static type system

Type systems are very important for large-scale applications. Python is a great and interesting language but sometimes you will see some unusual exceptions because when you try to use a variable as an integer variable, it turns out that it is a string type.

Django will crash process because of this def some_view (request): user_id = request.POST.get (‘id’, 0)

Go compiles and tells you that this is a compiler error, and this is where it wins time on stupid issues.

3. optimization

Surprisingly, Go is faster than Python (version 2 or 3) in most application scenarios. The results of the comparison can be seen in the Benchmarking Game, which of course is unfair, it depends on the type of application and user use case.

For our case, Go got better performance due to its own multi-threaded module and CPU scalability. Whenever we need to execute some internal requests, we can use Goroutine to execute them separately, which is more than ten times less resource-intensive than Threads in Python. Thanks to these built-in language features, we can save a lot of resources (memory and CPU).

4. Go no longer requires a web framework

This is a very cool thing for programming languages. The creators and community of the Go language have many built-in native tools supported by the core language, and in most cases, you no longer need any third-party libraries. For example, it has a built-in Http, JSON, and HTML templates. You can even build very complex API services without having to worry about finding third-party libraries on Github.

Of course, Go also has many libraries and frameworks for building web projects, but I would recommend that you do not use third-party libraries to build your web projects or API services because in most cases using native packages will make your life easier.

5. better IDE support and debugging

IDE support is one of the most important considerations when you try to change your programming language. A friendly IDE can save you 80% of your programming time on average. Go Plugin For JetBrains IDEA, also provides other support, such as (Webstorm, PHPStorm, etc …). This plugin provides any services you need in project development. The powerful JetBrains IDEA can make your development even more powerful.

Choose Go, or just go home?

Mozilla is internally switching its massive underlying logging architecture to Go, partly because of the powerful [goroutines]. The Go language was designed by people at Google, and support for concurrency was a top priority at the beginning of the design, rather than adding it after the fact as with various Python solutions. So we set out to switch from Python to Go.

Although Go code is not yet an officially launched product, the results are very encouraging. We can now process a thousand documents per second, use less memory, and don’t need to debug the problems you encounter in Python: ugly multi-process / event / “why Control-C can’t kill processes”.

Why we like GO ?

Anyone who has a little understanding of how programming languages ​​work (interpreted vs compiled, dynamic vs. static) will say, “Cut, of course, Go is faster”. Yes, we can also rewrite everything in java, and we can see similar and faster improvements, but that’s not why Go language wins. The code you write in Go seems to be correct. I don’t know what’s going on, but once the code is compiled (fast compilation speed), you will feel that the code will work (not only will it run without error, but even logically correct). I know this doesn’t sound very reliable, but it does. This is very similar to Python in terms of redundancy (or non-redundancy). It takes functions as the first goal, so functional programming will be easy to understand. And of course, go threads and channels make your life easier, you can get a big performance boost from static typing, and you can control the memory allocation more finely, but you don’t have to pay too much for language expressiveness. cost.

Based on our code statistics, we wrote 64% less code after rewriting the project in Go.

You don’t need to debug code that doesn’t exist. The less code, the fewer errors!

in conclusion

Go provides us with great flexibility. One language can be used in all user scenarios, and it works well in all user scenarios. In our Backend and API services, we got 30% performance optimization. And now I can process logs in real-time, convert to a database, and process one or more services through Websocket! This is a very powerful feature provided by Go language features.