Why web development on Go is nicer than on PHP

Who am I writing for? For those who write in php (perhaps also python, ruby) and have heard about Go, but have not yet decided to study it in more detail. I will give reasons why it is worth learning this programming language and why the future lies in it in web development.

I have been writing php for about 12 years and it is an excellent programming language, 90% of the sites of the entire Internet are written on it. Almost every popular CMS is written in PHP.
Why did I switch (or rather switch) to Go?

Multithreading


In principle, everything is clear here. Multithreading provides tremendous benefits to a programming language. In Go, multithreading is implemented very simply and expressively. In the next paragraph I will reveal the benefits affecting the development of the site.

Environment


What do I need to raise a regular site in php?

Server on Linux, install Nginx, sometimes Apache, install PHP, extensions, database, Memcache, configure Cron. In order not to be painfully painful to maintain the server, I put everything in Docker. This is what my regular Docker PHP project looks like.



Is that familiar?

What do you need to raise a regular website on Go?

Server on Linux and install Go. All. Cool? This is because Go is multi-threaded and any functionality can be moved to a separate stream, for example, a web server, micro-services, queues, crowns, etc. Many things are already implemented in basic packages.

How does my Docker project for Go look like? In fact, it does not exist at all. I put Docker files directly in the folder with the site or service code. If the site has additional micro-services (for example, for working with queues), then its Dockerfile is placed in the folder with this service.



Entry threshold


Learning the Go language is easy. You can scroll through all the documentation in a couple of hours and understand the principle of the language without deepening. I think Go has the shortest documentation of popular compiled languages.

On the official website, you can take a study tour that will reveal all aspects of the language.

To deepen your theoretical knowledge to the pros in a very short time. I recommend courses from Mail.ru on YouTube .

Code readability


Did you have such that you open someone else's code, module, plugin, etc. and you understand that you don’t understand anything. And in order to understand the intricacies, you need to at least go through the main code with debug.

In Go, in most cases, opening some fierce code for 200 files and each towel code file, you are surprised that you can understand it.

IDE


Writing in the JetBrains IDE under PHP and under Go are completely different things. Auto-completion works always and everywhere (99% of cases). You can fail in any method, in any!

There are no brakes at all. With words in general, it is difficult to describe, you need to try. When you start to write fully in Goland, you understand that you no longer want to go back to PhpStorm.

The year before last for hylood, I asked Dmitry Stogov about plans to introduce "native" multithreading in PHP and it looks like we won’t see it, but it's a pity.

Debugging and testing


Many PHP developers do not use debugging at all because it needs to be installed separately as an extension, it also needs to be configured correctly and many simply don’t bother and use the output to the page. In Go, the debug is built-in, in fact, you don’t have to figure out how it works inside, if you use the IDE just put a breakpoint and start the program.

With testing things are approximately the same, you do not need to connect the whole framework to the project, it is already built into the base packages and IDE.

Performance


Go is much faster than PHP in terms of execution speed and memory consumption. Of course, comparing them is not correct, since Go is a compiled language. There is a good article in comparison of productivity on Habré . For example, I have a Mirkoservice in a full Docker environment, which used to occupy 100-200 mb of RAM, switching to Go takes 1-2 mb. The increase in speed is 2-5 times.

Total


I love PHP and will continue to write on it as needed, but Go was a continuation of development for me and if I rewrote PHP from scratch, it would become the Go language.

Also popular now: