Introduction to go and run hello world program.

Tram Ho

1. The origin of the Go language

The Go language was originally designed and developed by a team of Google engineers including Robert Griesemer, Ken Thompson and Rob Pike in 2007. The purpose of new language design stems from some feedback on properties. complexity of C ++ 11 and the need to redesign C language in network and multi-core environments.

In mid-2008, most of the features designed in the language were completed, they started implementing the compiler and the Go runtime with Russ Cox as lead developer. Before 2010, the Go language gradually improved. In September of the same year, the Go language was officially announced as Open source.

The Go language is often described as “C language” or “C language of the 21st century”. From many aspects, the Go language inherits the ideas from C, such as syntax, control structure, basic data type, calling procedure, return, pointer, etc., completely inherited and developed C language, the figure below describes the relation of the Go language to other languages.

The left side of the diagram shows the concurrency nature of the Go language developed from the CSP theory published by Tony Hoare in 1978. CSP theory is gradually refined and applied in practice in a number of languages. such as Squeak / NewSqueak and Alef, and then Go.

The center of the diagram shows the object-oriented and encapsulation properties of Go inherited from Pascal and other related languages ​​derived from them. The package, import keywords come from Modula-2 language. The object oriented syntax comes from the Oberon language, and the Go language was developed with additional features such as the implicit interface so that they support the duck typing model.

The right side of the diagram shows the Go language inherited and improved from C, Just like C, Go is a low level programming language, it also supports pointer (pointer) but less dangerous than C.

Some of the other features of the Go language come from several other languages:

  • The iota syntax is borrowed from the APL language.
  • Features such as lexical scope and nested functions come from Scheme.
  • Go supports slices for fast element access and can automatically be scaled up or down.
  • The defer clause in Go.

2. Hello World

The first thing is to install the Go lang program according to the instructions on the golang.org home page.

To begin with, the program first usually prints out the words “Hello World”, the code below is this program.


Save the file as hello.go and run it with the following command.
Share the news now

Source : Viblo