- Network
- A
The Holy War of Programming Languages or the Experience of an Unsuccessful Move from Python to Golang
What prompted me to switch to Golang? At that time, I was using Python version 2.7.9 — this was around 2017. Then Python 3 was released. It turned out that despite many promises that everything would now work out of the box, wild conflicts began when switching from 2.7 to the new third version. I was a bit disappointed and started looking for something else interesting to work with networks.
Hello, tekkix! Valery Linkov is a Skillbox expert, a certified Cisco specialist, and an author of articles on machine vision and image processing. He has been teaching students around the world for more than seven years. He runs the Telegram channel "Curly Microphone". During a broadcast in the closed Skillbox Code Experts community, Valery talked about the "holy war" of programming languages and his experience of an unsuccessful move. So, let's go!
Turtle Battle or Why Golang is Needed
Back in school, I studied C++, although calling it studying is a stretch, but it was definitely an acquaintance. Years later, I got a job at Samsung, where they tried to teach me Java. I didn't like it at all. Java, I suppose, didn't like it either — and we parted ways.
In the process, I became a Cisco network engineer. And Cisco was then advocating for two languages: Python and C#. Python, because it is easy to interact with, it is a scripting language, easy to learn. And C# because Cisco was cooperating with Microsoft at the time, and C# is their proprietary development.
So what prompted me to switch to Golang? At that time, I was using Python version 2.7.9 — this was around 2017. Then Python 3 was released. It turned out that despite many promises that everything would work out of the box, wild conflicts began when transitioning from 2.7 to the new third version. I was a bit disappointed then and started looking for something else interesting to work with networks.
Spoiler: we still ended up switching to Python 3. At first, we worked through Power Shell because Microsoft and Cisco collaborated and worked well together. Then Python fixed version 3 and released updates in versions 3.4, 3.5. They themselves acknowledged the problems during the transition and the conflict with version 2.7. As a result, version 2.7 was killed at some point and stopped being supported.
But let's rewind: before all this happened, I started looking for alternatives. Python always suited my tasks. And in working with Python, I felt something like this: it's a huge, very kind, very good, almost fluffy turtle, but at the same time terribly clumsy. It's very hard to travel with it, very hard sometimes to make it do what I need. At the same time, the PyPy extension accelerated it very much — conditionally, from 9 to 0.2 seconds. And around the same time, Natasha Samoylenko's book "Python for Network Engineers" appeared, which describes how to configure various network devices, how to interact with Active Directory, and so on.
In general, I had no direct reasons to switch to Golang, except for the sad experience with the third version of Python. I believe that a programming language should be chosen for a specific need. And I wondered, what is Golang for?
At that time, I had a clear division into categories in my head, one of which was languages for writing applications or drivers for Windows. And if you have a personal life, then the language of choice is C#, and if you don't, then C++. :). If you want to create a huge service for creating anything, use Java, with which there will be no problems. If you want a solution to a problem that can be quickly made and shown, then Python.
But why is Golang needed, I sincerely did not understand. I thought it was some kind of totem animal of Google. Then I turned to statistics, and it showed active growth of Golang and that it accounts for 13.5% of backend development. Then I started looking at repositories to understand what is being developed on it, but I didn't find much interesting. The marketing campaign of Golang was built like this: it is as simple a language as Python, but as performant as C#. This deserves respect and I decided to try it.
Advantages and disadvantages of Golang
I spent many attempts to do a simple thing - just upload a ready-made configuration file to the router next to it. It turned out to be not such a simple task. I'll tell you why, I'll start from afar
Golang is a compiled language. Python is an interpreted language, respectively, it is slower, there are problems with the interpreter, periodically the interpreter may not be quite correctly configured and due to this the interpretation of the language may not go according to plan.
Golang is low-level programming, which is cool. This means you can pull up a microservice architecture, do parallel computing. Go immediately offers built-in support for parallel computing. And it also collects garbage and this property is promoted in marketing.
But Go had two disadvantages that everyone who was not lazy wrote about.
Golang is a new programming language. The history of C begins in the 1970s, C++ in the 1980s, C# in the 2000s, and Java has also been around for a long time and has 3 million users. But Golang only appeared in 2009. However, it is being developed by guys from Google. At the same time, there are an incredible number of games on the relatively young Unity, and even more applications on C#. Therefore, I personally did not see any problems with the youth of Golang.
Limitations. Go is more geared towards working with network applications. But in my case, when I work with networks, this is more of a plus than a minus.
There is a cool article from 2023, the essence of which is that Python is an easy programming language, but not a simple programming language. You can easily implement OOP in Python, and it will work great. But Go is a simple programming language, but not easy at all. And "easy" and "simple" are different things. Let me explain this idea.
Here is the code written in Python, a completely simple dictionary, nothing complicated, nothing scary.
And here is a dictionary in Golang. Super easy? — It didn't seem that way to me.
I began to notice that, on the one hand, Python has 33 keywords that need to be learned, while Golang has 25. And it seems to be really simpler, everything works great. But even from the two code examples above, you can infer two simple things.
In Python, all the code is two lines: a temperature string and a filtering string. The point of Python is that you can write an over-large command, fit many values into it, and send it to the server. It will be executed beautifully because you can set all the necessary parameters, work with Active Directory, Linux, or any interpreter—there will be no problems.
There is a club of enthusiasts who put a semicolon after the temperature array and write everything in one line. Then the readability of the code will drop somewhere into the stratosphere, but nevertheless, it is possible, and you can use it.
Golang does not imply that everything will be written in one line. And for myself, I have identified only two options where it makes sense to switch to Golang. It is faster. According to research, C# is slower than Golang. But C# is not an apostle of fast languages. Java is much faster.
If you have, for example, a large application with a bunch of classes that are interconnected, or even several applications that are not connected to each other and do not interact with each other in any way, they can be accelerated thanks to Golang. Simply because you can go down one level.
But I remind you that Python has PyPy, which essentially does the same thing. It is a more narrowly focused thing that translates the interpreter into a very conditional compiler. PyPy lowers the code, which speeds up the code.
The following code that I will show, as it seems to me, is the pinnacle of learning Golang. This code is not mine, but a blogger on Russian YouTube. He first created the Hidden Lake project, and then GoPeer — an analogue of CTM. All his processes look something like this. And all this is written in Go.
So what I showed can really be done in Golang. And, most likely, it will really be more convenient to manage if your project is aimed exclusively at networks, their low-level part.
But in other cases, I was completely disappointed in Golang. I fell for the marketing story that it would be much faster than all programming languages, and even more so than Python. But PyPy negates this advantage.
And we don't always need fast solutions. Fast solutions are most often needed either on low-level drivers, which Python cannot do, or in networks, which it can.
But on my big and friendly Python turtle, I already ride pretty well. This turtle is still slow, but my path is not so far that it creates real difficulties. It is enough to take the book "Python for Network Engineers", open all the scripts and see how they interact. For any CISCO device, for iOS — for anything, we can call the terminal or command line. Bash and PowerShell are suitable for such solutions. But what's the point of learning each one separately? It is clear that in some form we master them in the process of working as a sysadmin. But there is no need to switch from Python to any of these languages. And, in general, Python won again.
Conclusions
If you compare Golang and Python, personally I don't see any point in switching. For myself and my tasks, it may be different for you. The exception is if I want to create my own internal network or speed up the existing one. But, again, PyPy can help with this. And if you need to create some kind of service, you can use Java, C, C++, C#. So what is Golang for?
Creating services. If you only know Python and nothing else, then it makes sense to learn Golang to create services. But if you know anything else — Java, C#, C++ — Golang just falls off, because personally I didn't see anything good enough in the examples of working with it.
DevOps. DevOps engineers are now looking at Java and Golang and they are really interested in it. After all, to write something in Java, you essentially need to create it. Almost entirely, without moms, dads, and credits, almost from the core of the system. And also due to problems with VC-Code, it has become more difficult to work with Java, and switching to Eclipse is hell for many. For Golang, there are many DEs, plugins that make it easy and comfortable to work with. But on the other hand, even "SberTech" created their own DE and still haven't added Golang there, but they added Python and Java. It is clear that they made it primarily for their own needs and Golang, apparently, was not included in their number.
High loads. If we are talking about a high-load system, a web server with a large number of clients, then the choice will be 100% in favor of Go. Nevertheless, "Sber", "Alfa", "T-bank" have all their architecture built on Java, and I think this is not accidental. But there is a nuance — they pay a lot of attention to mobile development, and it is more convenient on Java. A high-load network service is more convenient to build on Go.
Working with legacy. Another advantage of Go is static typing. In Python, without it, it can be insanely difficult to understand code that was developed several years ago. And Go's static typing allows you to tidy up the code and read it even after many years. But in scripting stories, Python will give 100 points ahead just because of the convenience and speed of implementation of the solution. In Python, you can write complex things even if the code base is growing. But there is a bottleneck - it is the approach of people to writing.
Bonus. And there is also Go tour in Go - if you have previously studied any language, then just go to the website and take a course on learning Go syntax without any books.
Write comment