Hello World Program in Go

By TechCogs | Programming and Coding | 25 Feb 2020


Go is an open source programming language created by Google.  It was originally created not only to be easier than C++, but also to compile much faster.  In addition a normal Go program bundles everything it needs into one executable file when compiled, meaning you only have to distribute that one file instead of a whole archive full of files.

Those interested in cryptocurrency might find it interesting to know that the software behind the Ethereum blockchain is written in Go.

While Go is inspired in part by languages like C++ its syntax is a bit different.  The classic Hello World program in Go looks like this.

package main

import "fmt"

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

The very first line tells Go that this code file is part of the main package.  The main package and the main function are where the program begins.

The import statement is just like the important statement in any other language.  It imports the basic "fmt" library, which contains many of Go's printing and formatting functions.

Next you'll notice that functions are preceded by the keyword "func" which will be familiar to those that use JavaScript but not as familiar to those that use primarily C++ or Java.  That denotes that the section of code is a function.

The next line calls the Println function of the "fmt" package, which prints a line to the terminal or console.

This is a very brief overview of the classic Hello World program in Go.  For more information on the Go programming language see golang.org.

How do you rate this article?

3


TechCogs
TechCogs

I work with Linux, technology, computers, and science.


Programming and Coding
Programming and Coding

The wonderful world of software engineering and software creation, centered around languages like D, Java, Python, Dart, and C++.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.