News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Go Programming language - Overview

Started by NiveRoshni, Aug 08, 2020, 03:09 PM

Previous topic - Next topic

NiveRoshni

Go is a general-purpose language designed with systems programming in mind. It was initially developed at Google in the year 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is strongly and statically typed, provides inbuilt support for garbage collection, and supports concurrent programming.

Programs are constructed using packages, for efficient management of dependencies. Go programming implementations use a traditional compile and link model to generate executable binaries. The Go programming language was announced in November 2009 and is used in some of the Google's production systems.

Features of Go Programming

*The most important features of Go programming are listed below −

*Support for environment adopting patterns similar to dynamic languages. For example, type inference (x := 0 is valid declaration of a variable x of type int)

*Compilation time is fast.

*Inbuilt concurrency support: lightweight processes (via go routines), channels, select statement.

*Go programs are simple, concise, and safe.

*Support for Interfaces and Type embedding.

*Production of statically linked native binaries without external dependencies.

Features Excluded Intentionally

To keep the language simple and concise, the following features commonly available in other similar languages are omitted in Go −

Support for type inheritance

Support for method or operator overloading

Support for circular dependencies among packages

Support for pointer arithmetic

Support for assertions

Support for generic programming

Go Programs

A Go program can vary in length from 3 lines to millions of lines and it should be written into one or more text files with the extension ".go". For example, hello.go.

You can use "vi", "vim" or any other text editor to write your Go program into a file.

Local Environment Setup

If you are still willing to set up your environment for Go programming language, you need the following two software available on your computer −

A text editor

Go compiler

Text Editor

You will require a text editor to type your programs. Examples of text editors include Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.

The name and version of text editors can vary on different operating systems. For example, Notepad is used on Windows, and vim or vi is used on Windows as well as Linux or UNIX.

The files you create with the text editor are called source files. They contain program source code. The source files for Go programs are typically named with the extension ".go".

Before starting your programming, make sure you have a text editor in place and you have enough experience to write a computer program, save it in a file, compile it, and finally execute it.

The Go Compiler

The source code written in source file is the human readable source for your program. It needs to be compiled and turned into machine language so that your CPU can actually execute the program as per the instructions given. The Go programming language compiler compiles the source code into its final executable program.

Go distribution comes as a binary installable for FreeBSD (release 8 and above), Linux, Mac OS X (Snow Leopard and above), and Windows operating systems with 32-bit (386) and 64-bit (amd64) x86 processor architectures.

The following section explains how to install Go binary distribution on various OS.

Download Go Archive

Download the latest version of Go installable archive file from Go Downloads. The following version is used in this tutorial: go1.4.windows-amd64.msi.

Installation on Windows

Use the MSI file and follow the prompts to install the Go tools. By default, the installer uses the Go distribution in c:\Go. The installer should set the c:\Go\bin directory in Window's PATH environment variable. Restart any open command prompts for the change to take effect.

Verifying the Installation

Create a go file named test.go in C:\>Go_WorkSpace.

Hello World Example

A Go program basically consists of the following parts −

Package Declaration
Import Packages
Functions
Variables
Statements and Expressions
Comments
Let us look at a simple code that would print the words "Hello World" −

Executing a Go Program

Let us discuss how to save the source code in a file, compile it, and finally execute the program. Please follow the steps given below −

Open a text editor and add the above-mentioned code.

Save the file as hello.go

Open the command prompt.

Go to the directory where you saved the file.

Type go run hello.go and press enter to run your code.

If there are no errors in your code, then you will see "Hello World!" printed on the screen.