
From the Translator: have been transitioned . The article will be helpful not only for beginner programmers but also for anyone interested in Go in any capacity.
I like Python. This language has been my favorite for the past five years. It's user-friendly, efficient, and easy to learn. It's used for almost everything: from creating simple scripts and web development to data visualization and machine learning.
The gradual 'maturation' of Go, a large community, and the fact that more and more companies are adopting this language after successful tests made me pay attention to it and delve into the literature. But this post is not about which is better — Python or Go: there are countless comparisons online. In my opinion, it all depends on the application area. I am going to explain why I chose Go, providing some tips and links to useful resources for anyone interested in the topic.
Skillbox recommends: Practical Course .
Reminder: for all readers of 'Habr' - a discount of 10,000 rubles when enrolling in any Skillbox course with the promo code 'Habr'.

Observations
The first thing I did at the beginning of my journey was study the excellent official tutorial “”. It provides an understanding of the language's syntax.
To further improve my knowledge, I also read the book “”, which allowed me to move on to the next stage — trial and error.
I took familiar functions that I used in Python (JSON serialization or working with HTTP calls) and tried to write them in Go. This hands-on comparison helped me identify the key differences between the languages.
Project Layout
First of all, Python does not require a specific directory hierarchy, whereas Go does.
Go uses a 'standard' layout, which is a bit more complex and requires more work. On the other hand, as a result, we get a well-structured codebase, where a modular structure is used, and when scaling the project, the code remains strictly organized.
The official tutorial “” explains how to organize your work.
Static Strict Typing
Go is statically typed, and this will make those accustomed to dynamically typed languages like Python and Ruby feel out of place.
There's no doubt that dynamic languages are more prone to errors, requiring developers to put in more effort when validating input. For example, a function that calculates the sum of two integers. If a string is passed to the function (which happens quite often), it will result in a TypeError.
In Go, this cannot happen because you must declare a type for each variable and function, as well as what type the function will return.
At first, this is annoying: I thought that this feature of Go slows things down — but then I realized that declaring everything actually saves time, and the likelihood of errors decreases.
Native Parallelism
Go has native support for parallelism using goroutines and channels — this is convenient.
The concept of channels seems somewhat convoluted at first. However, over time it becomes clearer, and you begin to enjoy new possibilities as you work with them actively.
Here’s a visualization of everything mentioned by .
package main
func main() {
// create new channel of type int
ch := make(chan int)
// start new anonymous goroutine
go func() {
// send 42 to channel
ch <- 42
}()
// read from channel
<-ch
} 
More examples and .
Working with JSON
Well, json.loads() is no longer an issue. In Python, it's straightforward: we use json.loads, and there are no problems.
But in Go, a statically typed language, this operation becomes more complex.
Here, when using JSON, everything is predefined. Any field that doesn’t fit the specified structure will be ignored, and this is good. You can think of it as a pre-agreed protocol between two parties. The data you receive in JSON should be expected, and the fields and types of JSON are 'agreed upon' by both parties.
{
"first": "Elad",
"last": "Leev",
"location":"IL",
"id": "93"
}type AccountData struct {
First string `json:"first"`
Last string `json:"last"`
Location string `json:"location"`
ID string `json:"id"`
}Of course, you can deserialize JSON without structures, but it should be avoided whenever possible, considering the static nature of the language.
Decoding JSON in Go is best or .
Are you lazy to convert your JSON into Go struct? No problem, .
Clean Code
The Go compiler will always try to keep your code 'clean'. It treats unused variables as compilation errors. Go employs a unique approach that allows the system to solve most formatting issues. Thus, Go will run the gofmt program upon saving or compiling and will automatically fix the formatting.
Don't care about variables? No problem! Just use _ (underscore) and assign it to an empty identifier.
The master tutorial for this part of working with the language is the information from “”.
Finding the right libraries and frameworks
I used frameworks and libraries like Flask, Jinja2, Requests, and even Kazoo with Python, so I feared I wouldn't find anything suitable for Go.
But the community has already solved these problems: the language has its own unique libraries that allow you to completely forget about what you used before.
Here are my favorites.
Python Requests => net/http
provides a convenient and easy-to-use implementation of an HTTP client and server.
Flask + Jinja2 => Gin
— an HTTP web framework with a very simple API: path parameters, file uploads, group routing (/api/v1, /api/v2), custom logging formats, serving static files, HTML rendering, and truly powerful custom middleware.
Check out the benchmark.
CLI Creation => Cobra
— a library for creating powerful CLI applications, as well as a tool for generating applications and command files.
Cobra is used in many large Go projects, including Kubernetes, etcd, and OpenShift.
Here are some more libraries I highly recommend: , and this amazing list — .
Other Useful Resources
[1] — you definitely need to check out his and .
[2] .
[3] .
[4] , , — Twitter accounts.
Summing up
Having been a regular Python user for five years, I was worried that switching to Go would be painful.
But no: there are community-driven initiatives that expand and enhance the capabilities of the language, as well as various useful resources that will aid your transition.
Go is rapidly evolving, and I hope that Google will make it the primary language for writing cloud applications and infrastructure.
Join us!

Skillbox recommends:
- Two-Year Practical Course .
- Online educational course .
- Practical Year Course .
Source: habr.com
