Home etc Blogs Go: Perhaps the Best Language for Building Scalable Code

Go: Perhaps the Best Language for Building Scalable Code

0
4934

This article on Go covers the reasons for learning it and some of its concepts. It also presents a sample program.

Go (also known as Golang) is a procedural programming language. It was developed in 2007 by Robert Griesemer, Rob Pike and Ken Thompson at Google, but it was only in 2009 that it was launched as an open source language. Since then it has became one of the most popular languages in the developer community. It provides a rich standard library, garbage collection and dynamic typing capability. Programs are assembled by using packages for the efficient management of dependencies, so that the code is easy to read, and the specifications are short.

Why learn Go?
So why exactly should someone learn Go? Golang was built by Google to help solve problems faced by developers at the company, where lots of big programs are built for server software that run on massive clusters. Before Go, Google was using languages like C++ and Java to solve problems, but these languages didn’t really have the fluidity and ease of construction that was needed for problems at such scale. So Ken Thompson and Robert Greaser thought about building a new language that would be good for these kinds of problems and hence Golang was born. Basically, if you’re trying to solve a problem of enormous scale or just need efficient and scalable code, go for Go.
To run the Go language in your own PC or laptop, you need a text editor and a compiler.

Figure 1: Data types

Text editor: This editor gives you a platform on which to write your source code. The following is a list of text editors:

  • Windows Notepad
  • OS Edit command
  • Brief
  • Epsilon
  • vm or vi
  • Emacs

Compiler: You can install the Go compiler from https://golang.org/doc/install. The extension of the source code file of Go language must be .go.

Figure 2: Operators

Writing your first program in Go
This must be typed in a text editor and saved as a file with a .go extension:

package main
import “fmt”
func main() {
// used for comments
fmt.Println(“Hello, World!”)
}

OUTPUT: Hello,World!

Let’s examine the above Go program line by line.

Line 1: This contains the package main of the program, which has the overall content of the program. It is the opening point to run the program; so it is compulsory to write this.
Line 2: This contains import fmt, which is a preprocessor command that tells the compiler to incorporate the files lying in the package.
Line 3: This is the main function — the beginning of the execution of the program.
Line 5: fmt.Println() is a standard library function to print something as an output on the screen. In this case, the fmt package has transmitted the Println method, which is used to show the output.

Note: Comments are used for explaining code and are used in Java, C or C++. Compilers ignore the comment entries and do not execute them. Comments can be of a single line or multiple lines.

Go, Java and C++: A comparison
Here is a comparison of Go with Java and C++.

  • Go is a procedural and concurrent programming language, while Java and C++ are object-oriented programming languages.
  • Go does not contain classes with constructors and deconstructors, while both Java and C++ contain classes with constructors and deconstructors.
  • Go contains pointers, but does not contain an arithmetic pointer. Java doesn’t support pointers, while C++ contains both pointers as well as arithmetic pointers.
  • In Go, maps are passed by reference, while in Java and in C++ maps are passed as a value.
  • Go does not support exception handling; instead it has errors. Both Java and C++ support the concept of exception handling.

Data types and operators
Data types: The data types supported by Go are shown in Figure 1.
Operators: Go has three general types of operators that are prevalent in every major programming language, as shown in Figure 2.

New features in the latest stable version
The latest stable version of Go is 1.13.1, which was released on September 3, 2019. Its new features are mentioned below.
1. Go now supports a more uniform and modernised set of number literal prefixes.
2. Support for TLS 1.3 in the crypto/tls package is available by default (opt-out will be removed in Go 1.14).
3. It now has support for error wrapping.

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here