Go (also called Golang or Go language) is an open source programming language used for general purpose. Go was developed by Google engineers to create dependable and efficient software. Most similarly modeled after C, Go is statically typed and explicit.
- Go Programming Language Introduction
- Writing first program in Go
- Why this “Go language”?
- What excluding Go which is present in other languages?
- Hardware Limitations
- Advantages and Disadvantages of Go Language
- Features of go language
- Single Line Comment
- Why you Should Learn Go
- Conclusion
- Windows Notepad
- os edit command
- brief
- epsilon
- vm or vi
- Emacs
- VS code
Go Programming Language Introduction:
Go is a procedural programming language. It was developed at Google in 2007 by Robert Griesemer, Rob Pike and Ken Thompson, but launched as an open-source programming language in 2009. Programs are assembled using packages for efficient management of dependencies. The language also supports an environment adopting patterns similar to dynamic languages. For example, type inference (y := 0 is a valid declaration of a variable y of type float). There are many online IDEs such as The Go Playground, Riplat, etc., that can be used to run Go programs without having to install them.
To install Go on our PC or Laptop, we need the following two software: Text Editor and Compiler.
Text Editor: Text editor gives you a platform where you write your source code. The following is a list of text editors:
Finding a Go Compiler: Binary Installer for Windows Operating Systems with Go Distributions FreeBSD (release 8 and above), Linux, Mac OS X (Snow Leopard and above), and 32-bit (386) and 64-bit (amd64) Comes as doable. ) x86 processor architecture
- package main
- import “fmt”
- func main() {
- // print geeksforgeeks
- fmt.Println(“Hello, geeksforgeeks”)
- ,
- Output:
- hello geeksforgeeks
Writing first program in Go:
Explanation of Go program syntax:
Line 1: Contains the package main of the program, which contains the overall contents of the program. This is the starting point for running the program, so writing is essential.
Line 2: include import “fmt”, a preprocessor command that tells the compiler to include the files in the package.
Line 3: Main function, this is the start of the execution of the program.
Line 4: fmt.Println() is a standard library function to print something as output to the screen. In this, the fmt package has propagated the println method which is used to display the output.
comment: Comments are used to explain the code and are used just like in Java or C or C++. Compilers ignore comment entries and do not execute them. Comments can be single line or multiple lines.
Why this “Go language”?
Because the Go language is an attempt to combine the ease of programming of an interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled language. It also aims to be modern with support for network and multicore computing.
What excluding Go which is present in other languages?
Try to minimise the amount of typing in both senses of the word. Throughout its design, the developers tried to minimise clutter and complexity. There is no forward declaration and no header files; Everything is declared exactly once. Stuttering is reduced by a simple derivation of the type: the = declare-and-initialise construction. There is no hierarchy of types: types are just there, they don’t need to declare their relationships.
Hardware Limitations:
We have seen that over a decade, the hardware and processing configuration is changing very slowly. In 2004, the P4 had a clock speed of 3.0 GHz and now in 2018, the MacBook Pro’s clock speed is approx (2.3Ghz v 2.66Ghz). We use more processors to speed up the work, but using more processors also increases the cost. And because of this we use limited processors and using limited processors we have a heavy programming language whose threading takes more memory and slows down the performance of our system. So, to overcome this problem, Golang is designed in such a way that it uses Goroutines instead of threading, which is similar to threading but consumes much less memory.
Like threading consumes 1MB while Goroutine consumes 2KB memory, so at the same time, we can trigger millions of goroutines. So the thing discussed above makes Golang a robust language that handles concurrency like C++ and Java.
Advantages and Disadvantages of Go Language:
Flexible – It is concise, simple and easy to read.
Concurrency- It allows multiple processes to run simultaneously and effectively.
Quick Result- Its compile time is very fast.
Libraries- It provides a rich standard library.
Garbage collection – This is a major feature of Go. Excels at giving you a lot of control over memory allocation and the latest versions of the garbage collector have dramatically reduced latency.
Disadvantages: It has no support for generics, even though there are many discussions about it. The packages distributed with this programming language are quite useful but Go is not so object-oriented in the traditional sense. Lacks some libraries, especially a UI tool kit.
Some popular Applications developed in Go Language:
Docker: a set of tools for deploying Linux containers
OpenShift: Cloud computing platform as a service by Red Hat.
Kubernetes: the future of seamless automated deployment processes
Dropbox: Moved some of its key components from Python to Go.
Netflix: For part two of their server architecture.
InfluxDB: is an open-source time series database developed by InfluxData.
Golang: The language itself was written in Go.
Features of go language:
Language Design: The designers of the language made a conscious purpose to keep the language simple and easy to understand. Full details are in a few pages and some interesting design decisions were made through object-oriented support in the language. For this, language is considered and an idiomatic way of achieving things is recommended. It gives priority to composition over inheritance. In Go language, “do more with less” is the mantra.
Package Management: Go merges the modern developer workflow of working with open source projects and incorporates the way external packages are managed. Support is provided directly in the tooling for getting external packages and publishing your own packages in a set of easy commands.
Powerful standard library: Go has a powerful standard library, which is distributed as a package.
Static Typing: Go is a statically typed language. So, this compiler not only works on compiling the code successfully but also ensures on type conversion and compatibility. Because of this feature, Go avoids all the problems that we face in dynamically typed languages.
Testing Support: Go provides us with unit testing features in itself, that is, a simple mechanism to write your unit tests in parallel with your code. Because of this you can understand the code coverage by your own tests. And it can easily be used to generate your code documentation as an example.
Platform Independent: Go language is similar to Java language as it supports platform independence. Due to its modular design and modularity, the code is compiled and converted into binary form which is as small as possible and, therefore, does not require any dependencies. Its code can be compiled into any platform or any server and application you work on.
- // single line comment
- Multi-line comment:
- Syntax:
- /* Multiline Comment */
- The following is another example:
- package main
- import “fmt”
- func main() {
- fmt.Println(“1 + 1 =”, 1 + 1)
- Output:
- 1 + 1 = 2
Single Line Comment:
syntax:
Explanation of the above program:
In this above program, the same package line, same import line, same function declaration and uses the same println function as we have used in the 1 Go program. This time instead of printing the string “Hello, geeksforgeeks” we print the result of the expression 1 + 1 followed by the string 1 + 1 = . This expression is made up of three parts: the numeric literal 1 (which is of type int ), the + operator (which represents addition) and another numeric literal 1.
How to Install and Run Go on Windows 10 To install Go on your Windows machine, you first need to download Go from the official website. It is available for all popular operating systems. Click on the one that is related to your OS and install it.
Step 1: Before installing Go, open your command prompt, type “go” and press Enter. You can open Command Prompt by entering “cmd” in the Windows search bar and then selecting the first app that appears.
When you enter “go” and hit enter, you should get a message that says “‘go’ is not recognized as an internal or external command, operable program, or batch file”.
Don’t worry, this is because you have to install Go by double-clicking on the installer you downloaded from the Go website.
Step 2: Double-click on the downloaded installer to install Go. Follow the prompts accordingly and Go will be installed.
Step 3: After installing Go through the installer, go back to the command line and enter “go” again. This time, you should see several commands available in Go.
Step 4: But You Can’t Start Programming in Go Like This. You have to set up your Go workspace by configuring environment variables.So, go to your desktop and create a “go-workspace” folder. You can name it whatever you want. This is the folder where your Go projects will be stored. Only if you set the value of the GOPATH variable in it. We do this in the next steps.
Step 5: Search “env” on the windows search bar and click on “Edit System Environment Variables”.
Step 6: Click on “Environment Variables”.
Step 7: Make sure “GOPATH” is selected, then click “Edit…”.
Step 8: Click on “Browser Directory”
Step 9: Select the folder you created in Step 4. That is, “go-workspace”, or whatever you named it.
Step 10: Click OK”.
Step 11: Click “OK” again.
Step 12: And “Okay” again.
- Go has solid and easy-to-read documentation. You can read the documentation on the official website.
- In addition to the documentation, Go also has a helpful and active community behind it, so you can always get help when you get stuck.
- The hashtag #golang is commonly used on Twitter, so if you get stuck, you can tweet your question and attach the hashtag.
- Go is a multi-purpose programming language, which means you can use it for many things such as web development, data science, cloud computing, and more.
- If you want to pursue a career in cloud-based programming, you should consider learning Go, as platforms such as Amazon Web Services, Kubernetes, and Google Cloud Platform (GCP) all support Go.
- According to the 2020 Stack Overflow Developer Survey, Go developers are the third highest paid after Perl and Scala with a median salary of $74K.
- This figure will probably continue to climb, as Go is gaining more popularity and demand every year. So, if you want to make more money, you should consider learning Go.
Why you Should Learn Go:
Go is one of the simplest programming languages. It’s easy to pick up, especially if you already have knowledge of another programming language. In my case, I learned the fundamentals of Go in one sitting.
A lot of developers who use Go and are confident in its learning capabilities say that they can get a complete start on building apps with Go in just a few hours. The simplicity of Go is one of the main reasons why it jumped 5 places from 10th to 5th most preferred programming language according to the 2020 Stack Overflow Developer Survey.
Active community and good documentation:
You can do a lot with Go:
Attractive wages:
- In this article, you learned about the Go programming language and why it is good to know. You also learned how to install Go on a Windows machine and write your first Hello World program in it.
- Go is a powerful programming language that is here to stay. It is clear from now Stack Overflow Developer Survey that developers love Go, and its popularity is increasing year by year.
- Go is definitely worth your time. Now, go learn something.
Conclusion: