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...

Langage de programmation Go, Ford T avec moteur Ferrari
Modern features and 40-year syntax!

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.

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.

Syntax comparison...

Show Message.

Guo

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

C++

#include <stdio.h>

void main() {      
  puts("Hello, World!");  
}
Declare Variable. The type can be determined by output to Go.

Go: two equivalent statements.

var i : int = 10
var i = 10

C++

int i = 10;
Declare String. The type can be assigned by output.

Guo

var str = "Hello in Go"
fmt.Println(str)

C++

string str = "Hello in C++";
puts(str);
Constant...

Guo

const a = 1

C++

const int a = 1;
Statement. We can combine the two. There are permutations regarding C++, but there is no clear advantage.

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;
In a function, a variable can be declared implicitly. It is always directly stated in C++.

Guo

x := 2

C++

int x = 2;
If structure. You can include a statement before the condition. This brings nothing and makes the code less readable.

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");
}  
La structure switch. La différence avec C++ est la disparition du break terminal, dont l'omission permettait d'associer plusieurs cas à un même traitement. Mais on peut avoir le même résultat avec le mot réservé fallthrough qui joue le rôle opposé à break.

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");  
}
La boucle for est la seule structure de contrôle pour les itérations. On notera la disparition des parenthèses. Cela rend obligatoires les accolades.

Go

for i:= 0; i < 10; i++ {
  fmt.Println(i)
}

C

int i;
for(i = 0; i <= 10; i++) 
  puts(i);
For dispense de while et cela ne paraît pas un choix judicieux. "while i < 10" signifie: "tant que i est inférieur à 10" et est compréhensible, mais "for i < 10" signifie "pour i inférieur à 10" et cela n'a pas de sens.

Go

var i  = 0
for i < 10 {
  fmt.Println(i)
  i += 1
}

C

int i = 0;
while(i < 10) {
  puts(i);
  i += 1;
}
Une boucle infinie est très simplifiée. Rust quand à lui a choisi d'inventer inutilement une nouvelle structure, mais aucun n'offre de sécurité, que l'on obtient avec l'incrément obligatoire en fin de boucle comme le fait le langage .

Go

for {
  if condition {
  	break
  }
}

C++

while(true) {
  if(condition) 
    break;
}

For ... each. Cela se fait avec le mot range. Mais c'est plus simple en C++ 11.

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);
  ...  
}
Déclaration d'une fonction. Notons que JavaScript utilise le mot réservé function, Python def, Rust fn, Go func. Chacun cherche à se distinguer, pourquoi ne pas appeler une fonction function?
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);
}
Par contre, une fonction peut retourner plusieurs valeurs sous forme de tuple alors que C++ doit recourir à un tableau, ou un objet tuple, mais sans assignement direct.

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];
Les structures de données sont déclarées à la mode verlan. Les auteurs du langage ne roulent pas en voiture. Ils roulent en véhicule de type voiture, c'est bien mieux.

Go

type Point struct {
    x int
    y int
}

C++

struct Point {
    int x;
    int y;
}
Exemple de script: afficher les lettres d'une chaîne avec une boucle for.

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

Programming and data languages Asm.js - BASIC - C - C++ - C # - Darth - Eiffel - Guo - Java - JavaScript - Julia - Pascal - PHP - Python - Prolog - Ruby - La Scala - Scriptol - Swift - TypeScript - HTML - Vasm - XML - XAML - SQL