Go from Google, alternative to C++
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 is intended to replace C++ for system programming, that neither Java nor C# can do.

A 40 years old syntax!
To do this it employed several veteran of programming, and that explains the legacy syntax of the language.
- Ken Thompson. Co-author of UNIX, creator of the B language which was followed by C (by Dennis Ritchie).
- Rob Pike, created the Plan 9 system for Bell.
- Robert Griesemer has contributed to the V8 JavaScript compiler and GCC Chrome.
Its goal is to stay as close as possible to the C language while significantly improving productivity.
Go 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!
It is used in production since May 2010.
Why use Go?
Designed for parallel programs, it can on modern computers provide faster processing.
Its syntax and the way it treats objects intend it primarily for system programmers as a replacement for C or C + +. It then allows more rapid development.
Has builtin concurrency and garbage collector, that must be added to theses languages.
But it lacks libraries for now.
It may be used to make server software and for example to build a CMS and generates HTML pages. The golang.org site is made with Go.
Features
- No semi-colons required but to separated statements.
- map is a hash table and is part of the language.
- Multiple threads that communicate with each other.
- Variables are declared as in Pascal:
var name type
Ex: var x int; - Functions can return multiple values at once.
- There are no parentheses around the conditions in if or for as in Scriptol.
- break and continue may specify a label.
- The switch case structure may include different types or comparators as in Scriptol.
- A case statement can contain several alternatives:
case 0, 1, 2: - A slice is a structure that includes a part of a list and point to it.
- The go command calls a function by starting a different thread.
- chan is a channel for communication between goroutines (which are functions of concurrent threads).
CSP (Communicating Sequential Processes) manages communication between program with support for multi-core processors.
Difference with C++
Even if it uses a syntax of the 70s, Go simplifies a lot programming compared to C++.
Many common causes of errors coming from the syntax are removed.
Multi-threaded operation becomes quite easy thanks to a single command.
The garbage collector avoids memory management by the programmer.
- There is no class and inheritance. The interfaces are close to objects of JavaScript.
- Memory is managed automatically by a garbage-collector.
- Pointers have a type set.
- Arrays are passed by values and not pointers.
- Imports of packages as in Java rather than headers.
- No type conversion without using a function.
- nil replaces null.
- The pointer symbol -> is replaced by dot.
- No do while.
- No break in the switch case (as in Scriptol).
- Increments - and + + can not be used in expressions.
- Constants can be declared without a type.
- new is a function and not an operator.
Go vs. Java
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 might adopt a different approach, using Webkit to the interface, Native Client or be integrated into the browser as JavaScript to run Web applications on the desktop.
Go vs. C Sharp
C# was created by Microsoft as an answer to Java and is designed to run on the .NET platform. The platform suffers from a lack of compatibility. It runs on Linux, but with reduced features compared to the version of Windows.
C# also works in Silverlight for Web applications.
Controversy over the name
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!
Note that 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!
Sites and tools
- The official website.
- Online Go. Web service to execute a Go program through the browser. The program is compiled on the server, executed and the result displayed.
- List of resources.
- Video of the language.
- App Engine for Go. On the Google's cloud, you can build web applications using Go server-side.
- Go review. A comparison with other C-like languages.
Sample code
Hello World! program:
package main
import fmt "fmt"
func main()
{
fmt.Printf("Hello, world\n");
}
Displaying chars of a string:
package main
import ("os";"flag";)
func main()
{
var s string = "Demonstration";
for i := 0; i < s; i++
{
os.Stdout.WriteString(s[i]);
}
}
The lack of parentheses after the for is voluntary.
| Tweet |
|