GNU/Linux Programmer's Solver - Go

Hello World program in Go. Basic structure, comments and string literals
PROGRAMMING GO HELLO WORLD
package main
import "fmt"
/* This is a multiline
 * comment
 */
func main() {
    fmt.Println("Hello World!") // This is a comment
    fmt.Println (`--------------
Thiaa is a multine string
------------------------`);
}

Go is a compiled programming language, relatively recent.

Go source files have the .go extension. Of course.

We see how the language takes several elements from C/C++. The comments and the grouping of instructions are identical. Instead of include it uses import like Python (although we haven’t seen this yet). We can ignore the package instruction for now.

As we can observe, Go uses the same solution as Java, adding the characters ln (of line, line in English) to the Print function when we want to include a carriage return at the end of our string.

DID YOU KNOW…

The Go language offers native support for concurrent programming. One of the most unique features in this aspect are the calls goroutines and channels. Goroutines can be seen as a kind of threads, while channels are a mechanism for exchanging messages between goroutines.

In addition to all that, we can define multi-line strings using backticks.

We can execute our program directly using the command:

$ go run hello.go

Or generate an executable

$ go build hello.go
$ ./hello

Go was designed at Google by Robert Griesemer, Rob Pike, and Jen Thompson (a few heavyweights on the list) in 2007. The language was conceived to improve programming productivity in the era of networked machines, multi-core processors, and large codebases.

The language was publicly announced in 2009 and released in 2012.

You can install the development tools for the Go language using the following command in Debian-based distributions:

    apt install golang

Summary

  • Compiled language
  • Extension: go
  • Line terminator: ;
  • Groups instructions with: Depends on the command
  • Multi-line comments: Using /* ... */
  • Single-line comments: //
  • String delimiter: "string" or `string`
  • You can print text with fmt.Println (Adds carriage return)
  • Supports multi-line strings: Depends on the operation
  • Does not Support HERE-DOCS
  • Entry Point: main function

Related Posts

GNU/Linux Programmer's Solver
Chapter 1 - Hello World

Hello World is the first program you write when learning a new language and there are good reasons for that

Read

PROGRAMMING HELLO WORLD

GNU/Linux Programmer's Solver - C#

Hello World program in C#. Basic structure, comments and string literals

Read

PROGRAMMING C# HELLO WORLD

GNU/Linux Programmer's Solver - Lua

Hello World program in Lua. Basic structure, comments and string literals

Read

PROGRAMMING LUA HELLO WORLD

Return to Home Page