Go language from the point of view of the PHP developer

    Go is a language invented by Robert Griesemer, Rob Pike and Ken Thompson , which was announced in November 2009 with Linux and Mac OS X versions. Now developers work at Google, but they were very famous and respected long before that. people (for example, the UTF-8 encoding was invented by Thompson and Pike for use as the primary encoding in Plan 9).

    Personally, I decided to see what kind of language it was after I published this video of Rob Pike’s speech here . I haven’t studied Go for a very long time, but even in the two weeks I spent studying it, I managed to do several projects on it, for example, the backend for the JsHttpRequest library ( JsHttpRequest ; my backend on Go) I still use JsHttpRequest because of its convenience (both from JS and from PHP). In the article I want to talk exclusively about my feelings after programming in PHP and JavaScript, with almost no code examples.

    In a nutshell about the language


    The official website of the project is http://golang.org . There is a short tutorial, a description of the language and built-in packages (packages), as well as links to Wiki, benchmarks and a list of third-party packages .

    Go is a statically typed language with a garbage collector that feels like both C and Javascript (many constructs also resemble other languages ​​like Python, Pascal, and Java). Go is a compiled language, and compiled into native executable code (unlike Java and .NET), and its performance is quite close to C.

    The language has a slightly strange syntax (for example, the definition of the string str looks like , notstr stringstring stras in almost all other languages), built-in support for UTF-8, immutable strings (immutable strings) and support for dynamic typing using interfaces (not to be confused with interfaces in other OOP languages)

    I will give at least code examples - if you want to look at the code on Go, I recommend that you read the tutorial .

    Why the language is considered from the point of view of the PHP developer, and not ?


    I involuntarily compare it with PHP because I started programming in PHP, I have been programming on it for about 7 years with some interruptions and I wanted to see some language that would be fundamentally different from PHP, but at the same time suitable for web. Of course, Google’s language cannot but satisfy the second criterion, so I decided to pay attention to it :).

    It’s not entirely correct to compare PHP and Go, since these are languages ​​for various purposes - they are rather complementary, but I decided to compare Go and PHP in the area for which PHP is geared for creating websites

    Advantages over PHP


    - Compiled language with static typing, which allows to achieve excellent performance (10-100 times faster than PHP)
    - Perfectly suited for writing system utilities and daemons
    - Elimination of a huge number of runtime errors due to strict typing
    - Exceptional support for Unicode and UTF -8: source codes and lines are mandatory in UTF-8, rich built-in mechanisms for working with UTF-8
    - Excellent multi-threaded and parallel programming capabilities (concurrent and parallel)
    - Close integration with API * nix-systems, well-organized in morning data structures for working with the system and files
    - Good support for the latest web standards, such as the WebSocket API

    Disadvantages Compared to PHP


    - Lack of integration with Apache (only working as a standalone web server or FastCGI from third-party developers)
    - Language with incomplete syntax and capabilities - some Go projects that are less than a year old are no longer compiled
    - Lack of dynamic code connection (unable to load and unloading, for example, * .so-files on the fly)
    - much less convenient to use dynamic capabilities
    - Few third-party libraries - except for MySQL, PostgreSQL and NoSQL-databases are not connected
    - Lack of official support for the Windows the Microsoft ®
    - Desired tionary have experience in C programming to better understand the semantics of the language

    Overall feeling


    Go is the first static typing language I have seen where it doesn’t really interfere with programming and doesn’t force you to write 2-3 times more code than in PHP or JavaScript. Also, Go is compiled into native code, and is positioned as a language for writing system utilities and daemons. The language and the compiler do not cause the sensation of something monster-like and clumsy, like Java or .NET (which, in fact, is the main reason why I do not write in Java).

    On the other hand, it feels like the language is still booming (for example, in front of my eyes in one day a package called html was drawn that appeared almost immediately after I downloaded and installed my Go environment, so I had to reassemble it :)). Also, as a replacement for PHP, it doesn’t work very well, because for each host you have to write a whole web server and make sure that it doesn’t accidentally fall :), and you also need to bother separately with launching these daemons when the server is rebooted, for example . I am silent that on shared hosting the maximum that you can do on Go is to connect your CGI-handlers on Go, which will not work much faster than PHP, if it works faster at all.

    In general, the language itself and the built-in libraries are stable enough so that Go can be used on production (for example, golang.org itself runs a server on Go, namely, it’s just godoc running with the -http = "key .. .: 80 "). But, since I do not have as much experience in network and system programming as I would like, I often come across errors in using libraries that could have been avoided if I had experience in network programming and writing demons. But, in general, it seems to me that if you wanted to learn Java or ASP.NET, try better Go - this language is unlikely to leave you indifferent.

    Also popular now: