Google's Go language, Ferrari-powered Ford T
Google has created a Go language to be able to work with modern multi-core processors, which is difficult with current languages. As always, the new language responds to dissatisfaction with current languages. In this case, it was intended to replace C++ for low-level programming, which neither Java nor C # can do. But that doesn't mean it's actually being used for that. It's funny that the creators wanted to keep the syntax that programmers are used to - C, but most use Go to replace Python!
To design it, he turned to several programming veterans, which explains the venerable syntax of the language...

Modern features and 40-year syntax!
- Ken Thompson. Co-author of Unix, creator of the B language, who was replaced by C (Dennis Ritchie).
- Rob Pike, created the Plan 9 system for Bell .
- Robert Griesemer contributed to Chrome's JavaScript V8 compiler and GCC.
These developers have nothing to do with C++, which was created by Bjarne Strutstrup based on C, which explains various design options, such as composition instead of inheritance.
The goal of Go is to stay as close to the C language as possible and at the same time significantly increase performance, and replace it.
It takes inspiration from C, Java, Pascal, Python and even repeats the features of Script!
Google tells us in the presentation:
"We argue that Go is a modern language."
And this is true when to its functions, and not to the syntax dated exactly 1969 and the language B, and with borrowings from Pascal (1970 )!
It has been used in production at Google since May 2010, but in addition to being a very effective substitute for C++, it also tends to be used in place of Python and Ruby because its compilation speed is suitable for scripting, while producing fast executable binaries. Therefore, it can replace all languages for command line programs.
Another quote from the author, Rob Pike:
The main thing here is that our programmers are Goglers, they are not researchers. They are usually quite young, freshly baked from school, have probably learned Java, possibly C or C++, and possibly Python. They are not capable of understanding brilliant language, but we want them to make good programmes. So the language we give them should be easily understood and easily accepted .
Why use Go? User Experience...
The experience is quite negative for individual programmers who have used other modern languages. Go is mainly intended for a command where repeated addition/replacement of a programmer. It allows even beginners to work quickly.
Its syntax and how it relates to objects intended mainly for programming on servers as a replacement for Perl, Python or PHP. It allows both rapid development and the performance of cycle scripts.
It has competitive features and a collectible garbag from the start. The collection garage is usually not suitable for running OS, drivers, but is specially optimized to achieve breaks of less than 100 micro-waves!
It can be used to create server software and, for example, to build a CMS and generate HTML pages - a domain where it outperforms Python and Java.
It is simpler than C++, more adaptable than Java, faster and more secure than Python, has a complete and well-thought-out library (on the server side) and provides the necessary services for web applications such as WebSocket, closets.
And programs compile instantly, which makes development easier, as well as an accurate description of possible errors, unlike other languages like C++.
C language syntax
Syntax improves performance.
- Semicolons are not required except to separate statements.
- map is a rush table and is part of the language.
- Multiple threads that communicate with each other.
- Variables are declared as in Pascal as:
var name type.
Ex: var x int ; - break and continue can specify a label. In
- the structure of the switch can be different tests, as in Script .
- The check box can have several alternative options:
field 0, 1, 2 : - A slider is a structure that takes part of a list and points to it.
- The go command calls the function by starting another thread .
- chan (channel) - a communication channel between gorutins (which are functions of competing processes).
- UTF-8 string format.
- Primitives are: bool, string, int, int8-64 similarly for uint, byte, float32 and 64, complex64 and 128 .
CSP (Communicating Sequential Processes) technology manages communication between programs and helps manage multi-core processors.
Forward vs. Java
Java was conceived as a language for the Web and thanks to this it became popular. It can run on the server or client computer using applets (they are outdated).
His main interest is the very extensive GUI library.
Go as Java allows you to immediately test an evolving program or script, but it produces binary code, so it's faster and more compact.
Go vs C++
Even if it repeats the same 70s syntax, Go makes programming easier compared to C++. Some common syntax errors are removed.
Multithreading becomes simple, with one command.
The collection garage makes memory management easier.
- There is no class and no inheritance. Classes are replaced by structures and interfaces close to JavaScript objects. Objects expand in composition, not inheritance .
- The memory is controlled automatically by the garbag collector. In October 2016, it was announced that the new GC marked breaks of less than 100 micro-seconds, so the user was invisible .
- Pointers are of a fixed type.
- Tables are passed by value, not as pointers.
- Import packages as in Java, not header files as in C.
- No type conversion without using the function.
- nil replaces null.
- The pointer symbol -> is replaced by a period .
- Increments of - and++ cannot be used in expressions.
- Constants can be declared without a type .
- new is a function, not an operator.
- Go hates genius, because of all its flaws, the authors say. (Ref: Esmeralda imagination).
Syntax comparison...
Guo
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
C++
#include <stdio.h>
void main() {
puts("Hello, World!");
}
Go: two equivalent statements.
var i : int = 10
var i = 10
C++
int i = 10;
Guo
var str = "Hello in Go"
fmt.Println(str)
C++
string str = "Hello in C++";
puts(str);
Guo
const a = 1
C++
const int a = 1;
Guo
var b int = 2
var x, y, z int
var i, j, k int = 5, 10 , 20
b += x
C++
int b = 2;
int x, y, z;
int i = 5, j = 10, k = 20
b += x;
Guo
x := 2
C++
int x = 2;
Guo
if x < 1 {
fmt.Println("ok")
}
if x = mult(y, 100); x < 1000 {
fmt.Prinfln("ok")
}
C++
if(x < 10) {
puts("ok");
}
x = mult(y, 100);
if(x < 1000) {
puts("ok");
}
Go
switch x {
case "a":
fmt.Println("a")
case "b":
fallthrough
case "c":
fmt.Println("b ou c")
default:
fmt.Println("x")
}
C++ 11
switch(x) {
case "a":
puts("a");
break;
case "b":
case "c":
puts("b ou c");
break;
default:
puts("x");
}
Go
for i:= 0; i < 10; i++ {
fmt.Println(i)
}
C
int i;
for(i = 0; i <= 10; i++)
puts(i);
Go
var i = 0
for i < 10 {
fmt.Println(i)
i += 1
}
C
int i = 0;
while(i < 10) {
puts(i);
i += 1;
}
Go
for {
if condition {
break
}
}
C++
while(true) {
if(condition)
break;
}
Go
var arr = []int { 10,20,30 }
for i, v := range arr {
fmt.Println(v)
...
}
C++ version 11
int arr[] = { 10,20,30 };
for(x : arr) {
puts(x);
...
}
La syntaxe de Go pour déclarer une fonction reste simple, celle de Rust étant inutilement compliquée et abscon.
Si plusieurs arguments sont de même type, on déclare le type une seule fois. Mais cela reste des types statiques dans les deux langages et n'offre pas le multiple dispatch de Julia.
Go
func mult(x int, y int) int {
return x * y
}
C++
int mult(int x, int y) {
return (x * y);
}
Go
func ftuple(x int, y int) (int, int) {
return x * 2, y * 2
}
x, y = ftuple(10, 15)
C++
int[] ftuple(int x, int y) {
return { x * 2, y * 2 };
}
int z[] = ftuple(10, 15);
x = z[0]; y = z[0];
Go
type Point struct {
x int
y int
}
C++
struct Point {
int x;
int y;
}
Go
package main
import ("os";"flag";)
func main() {
var s = "Démonstration"
for i := 0; i < s; i++ {
fmt.Println(s[i])
}
}
C++
#include <stdio>
#include <string>
void main() {
string s = "Démonstration";
for(i : s) {
puts(i);
}
}
Sur le plan des bibliothèques, Go va directement à l'encontre de C++, non seulement il n'y a pas de fichiers d'en-têtes, mais on peut même inclure des modules externes directement depuis un site distant, car toute l'information pour l'intégration est stockée dans les modules.
En général cela facilite la distribution des programmes, mais cela à des inconvénients. Les modules importés directement cessent d'être compatibles et obligent à réécrire les logiciels...
Polémique au sujet du nom
Lors du lancement public du langage, un ticket a été créé sur le forum du langage avec pour code d'identification issue 9.
L'auteur d'un langage totalement inconnu clame que le nom Go est déjà celui de son propre langage. Le fait est qu'un livre a été écrit sur celui-ci, sous le titre Let's Go!
Mais ce langage s'appelle Go! et non pas go, et le mot Go appartient au domaine public: il s'agit d'un jeu de tableau chinois qui existe depuis plusieurs milliers d'années! (Et aussi le verbe "aller" en anglais).
Sites et outils pour Go