Go language from Google, a Ford T with a Ferrari engine

Google has created the Go language to operate with multi-core processors of today, that is difficult with current languages. As always, this new language was created in response to the dissatisfaction caused by the shortcomings and disadvantages of current languages. In this case, it was intended to replace C++ for low level programming, that neither Java nor C# can do. But that does not mean it is actually used for that. It is amusing that the creators have wanted to keep a syntax that programmers are accustomed to, that of C, but the majority use Go to replace Python!

Go programming language, Ford T with Ferrari engine
Modern features and 40 years old syntax!

To design it, several veteran of programming were hired, and that explains the legacy syntax of the language...

These developers have nothing to do with C++, which was created by Bjarne Stroutstrup on the basis of their language, C, which explains different choices of design, such as composition instead of inheritance.

The goal of Go is to stay as close as possible to the C language while significantly improving productivity and replace it. 
It borrows features from C, Java, Pascal, Python and even incorporates features from Scriptol!
Google says in the presentation:

"We claim that Go is a modern language."

And it's true for its features, not for the syntax which dates exactly from 1969 and the B language with some borrowing from Pascal (1970)!
It is used in production at Google since May 2010, but beside the fact that it replaces C++ very effectively, it also tends to be used in place of Python or Ruby because its compilation speed is suitable for scripting, while it produces fast binary executables. It so can replace all languages ​​for command line programs.

Why use Go? The user experience...

Designed for parallel programs, it can on modern computers provide faster processing. 
Its syntax and the way it treats objects intend it primarily for programs on servers  as a replacement to Perl, Python or PHP. It then allows both a fast development and quicker scripts.
Has builtin concurrency and garbage collector. But the choice of a garbage collector and the runtime required are not suitable for the making of an OS, drivers ...

It may be used to make server software and for example to build a CMS and generates HTML pages a field where it is superior to Python or Java. The golang.org site is made with Go.

Whatever their previous language (but a priori a scripting language), programmers have a positive experience with Go. It is simpler than C++, more adaptable than Java, has an extensive well designed library and provides the services required to Web applications, such as WebSocket, closures.
And programs are compiled instantly which facilitates the development, as does the clear description of errors it displays too. C programmers know what it is about.

About the question of the speed of execution, opinion diverge. Go is significantly faster than Python, it is a fact, but for large quantity of data, one find that Java is significantly faster, especially because he knows immediately when use multiple cores that Go does not know (yet). Genericity also facilitates programming without slowing performance. (Ref).

A higher level C language

The syntax improves productivity.

CSP (Communicating Sequential Processes) manages communication between program with support for multi-core processors.

Go vs. Java, C#

Java was designed as a language for the Web and became popular thanks to that. It can run on the server or the client with applets.
Its main advantage is its huge library to build graphical user interfaces.
Go as Java allows you to test a program or script development immediately, but it produces binary code, so is faster and more compact.
This applies with respect to C# too.

Go vs. C++

Even if it uses a syntax of the 70s, Go simplifies a programming compared to C++ classic, but not so much over the version 11.
Some common causes of errors coming from the syntax are removed.
Multi-threaded operation becomes quite easy thanks to a single command.
The garbage collector eases memory management.

Comparing syntax...

Displaying a message.

Go

import "fmt"

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

C++

#include <stdio.h>

void main() {      
  puts("Hello, World!");  
}
Declaring a string.

Go

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

C++

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

Go

const a = 1

C++

const int a = 1;
Declaration. May be grouped. There is permutation with respect to C++, but no obvious advantage. Just want to be different!

Go

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;
The type can be determined by inference. It is always declared in C++.

Go

x := 2

C++

int x = 2;
If structure. We may include a declaration before the condition. This brings nothing more and makes the code less readable. We are in the weightlifters contest here.

Go

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");
}  
The switch structure. The difference with C++ is the disappearance of closing break, omission of which makes it possible to combine several cases to the same processing. But you can have the same result with the reserved word fallthrough that has the opposite role of break..

Go

switch x {
 case "a":
     fmt.Println("a")
 case "b":
     fallthrough
 case "c":
     fmt.Println("b or c")
 default:
    fmt.Println("x")
}

C++ 11

switch(x) {
  case "a": 
    puts("a"); 
    break;
  case "b": 
  case "c": 
    puts("b or c"); 
    break;
  default:
    puts("x");  
}
The for loop is the only control structure for iterations. Note the disappearance of parentheses. This makes mandatory the braces.

Go

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

C

int i;
for(i = 0; i <= 10; i++) 
  puts(i);
For replaces while. Again, this does nothing except to complicate the parser and it does not make sense in English.

Go

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

C

int i = 0;
while(i < 10) {
  puts(i);
  i += 1;
}
An infinite loop is very simplified. While Rust chooses unnecessarily to invent a new structure, but none of the two languages ​​although they want to be safer, offers security, as does scriptol with mandatory increment at end of the loop.

Go

for {
  if condition {
  	break
  }
}

C++

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

For ... each. It is achieved with range. But it is simpler en C++ 11.

Go

var arr = []int { 5,10,20 }
for i, v := range arr {
  fmt.Println(v)
  ...
}

C++ version 11

int arr[] = { 5,10,20 };
for(x : arr) {
  puts(x);
  ...
}
Declaration of a function. Note that JavaScript uses the reserved word function, Python def, Rust fn and Go func. Each wants to distinguish itself, but why not call a function function?
Go syntax to declare a function is simple, while Rust being unnecessarily complicated and stupid.
If several arguments have the same type, the type is declared once. But they remains static in the two languages and do not offer multiple dispatch as in Julia.

Go

func mult(x int, y int) int {
  return x * y
}

C++

int mult(int x, int y) {
  return (x * y);
}
However a function can return multiple values ​​as a tuple while C++ must use an array or a tuple object, but not a direct assignment.

Go

func tuple(x int, y int) (int, int) {
  return x * 2, y * 2
}
x, y = tuple(10, 15)

C++

int[] tuple(int x, int y) {
  return { x * 2, y * 2 };
}
int z[] = tuple(10, 15);
x = z[0]; y = z[1];
Data structures are declared in verlan mode. The authors of the language do not drive a car. They drive a vehicle of type car, it's much better.

Go

type Point struct {
    x int
    y int
}

C++

struct Point {
    int x;
    int y;
}
Example of script: displaying letters of a string with a for loop.

Go

package main  
import ("os";"flag";)

func main() {
  var s string = "Demonstration"
  for i := 0; i < s; i++  {
    fmt.Println(s[i])
  }
}

C++

#include <stdio>

void main() {
  string str = "Demonstration";
  for(i : str) {
     puts(i);
  }
}

 

In terms of libraries, Go goes directly against C++, not only there is no file header, but you can even include external modules directly from a remote site, because all the information for the integration is stored in the modules.
In general that facilitates the distribution of programs, but it has also disadvantages. Modules imported directly cease to be compatible and require rewriting the software.

Some fun facts about Go

  1. At the public launch of the language, a ticket has been created on the forum of the language on issue 9.
    The author of an totally unknown language claims that the name Go is already that of his own language. The fact is that a book has been written on it, under the title Let's Go!
    But this language is called Go! and not Go, and that the word Go is in the public domain: it is the name of a Chinese board game that has existed for thousands of years!
  2. When reproached the absence of genericity, the author gives this replica:
    When a starlet said "I do not imagine to be anything other than an actress," one replied: "Then you're not much of an actress."
    Rob Pike then resumes:
    When a programmer said "I do not imagine a language without generics", I answer him: "So you're not much of a programmer."
    To this a smart programmer replied:
    When an author language says "I can not imagine a language that needs generic", I answer him: "So you're not much of a language designer."

Sites and tools

Programming and data languages Asm.js - Basic - C - C++ - C# - Dart - Eiffel - Go - Java - JavaScript - Julia - Pascal - PHP - Python - Ruby - Rust - Scala - Scriptol - TypeScript - HTML - XML - XAML - SQL