Go is an open-sourced programming language that made its first appearance about 11 years ago. The language is very young compared to 30-year-old Python and 35-year-old C++.
Go was designed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. The purpose of Go was to make software development faster and easier for developers.
According to this HackerEarth survey, Go is the most sought-after programming language among students and professional developers.
In fact, Go is one of the easiest languages to learn. In this article, I will try to introduce some of the basic concepts of Go. I hope this article motivates you to learn the language further. Let’s get started!
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Here is the Go code to print ‘Hello World’.
package main
import "fmt"
func main () {
fmt.Println("Hello World")
}
The first line is called a package declaration and every Go program starts with a package declaration.
The next line, import “fmt”
is an import statement. The import
keyword allows us to import and use code from other packages.
fmt
is short for format, but commonly pronounced as ‘fumpt’. You can call it whatever you want.
The main()
function is a special function. A file with a package main
declaration will automatically run the main()
function.
Inside the main function block, we have fmt.Println(“Hello World”)
.
Println
is a function used to print text, which in our case is Hello World.
In Go, we can declare a variable either with the variable’s type
or with an initializer using the var
keyword. Multiple variables of different types can also be declared at once.
var a, b int = 0, 1
func main() {
var c, d, e = true, "GO", 2.33
f := -5
fmt.Println(a, b, c, d, e, f)
}
If the type
of the variable is not mentioned then the variable will take the type of the initializer.
Inside a function, the :=
short assignment statement can be used instead of a var declaration. However, this is not possible outside a function.
Constants are declared like variables, but with the const
keyword. Constants can be character, string, boolean, or numeric values.
#go #golang #programming #web-development #developer