Go Language And Its Environment Set Up
Go is a programming language, which is designed by Google(2007).
Why it is introduced?
1. Limitations in the hardware.
The performance of the system has to be increased. Using a large number of hardware parts like the transistor and the processor, which is not possible. When one of them increases the cost will increase or the performance will reduce.
2. The code is easy to maintain
The code written with Go language has a simple and understandable syntax. These features help to maintain the code easily.
Features of Go language
- Open-source.
- Used at the backend.
- Made of packages
- Performance is greater.
- Has garbage collection.
- Easy to read the code.
- Throughput is better.
- Has garbage collection.
How to set up the environment to start coding in Go language.
Initially go to The Go Programming Language (golang.org) and download Go language by clicking the relevant link(select the correct Operating System).
Download Go |
Click on the below icon in the location where it is installed to start the downloading process.
Downloaded setup file. |
Then follow the following images to continue the installation process.
After finishing the installation you can check the version of the go language by typing "go --version" in the command line.
After the installation, you can start coding. The file extension is .go.
Let us learn how to code hello world using the syntax in go. I am using VS Code as the IDEA. So I will explain the code implementation using the VS Code.
Tip: VS Code has an extension to give suggestions when you code using the Go language.
Go extension used in VS Code |
Now it is time to execute the code.
How to run a .go file?
Hello World! in Go language |
Go to the terminal in the VS Code and run the following command.
go run file_name
Let us assume that I am having a main folder as coding. Inside the coding folder, there is a file name called hello.go where the hello world code snippet is written.
folder set up with .go file |
I will run the .go file as shown below
go run hello.go
How to run .go file in terminal |
The terminal of the VS Code shows the output as Hello World!.
Explanation about the code
- The package which is used to run a program written in Go language is main.
- Packages are imported to the program with the import keyword.
- fmt is a package and it is known as the format. fmt is used to provide input and output functions.
- The function main is defined as func main().
- It is possible to access functions from packages where the first letter of the exported name has to be capitalized. Example: fmt.Println()
Conclusion
This blog was written to give an understanding of the Go language for beginners and to know the reason to have it as the programming language. In the future post let us learn more about the Go language.
Comments
Post a Comment