Significance of Go — Part 1 (Where does the Go stand among other programming languages?)

Wasura Wattearachchi
7 min readApr 6, 2020

Do you know about Go? If yes, then you have to read this. If no, then you have to read this too. This article series is not a place to learn to code in Go. These will highlight the significance and some cool stuff of Go. If you want to learn Go from scratch the place is the “Tour of Go”.

Let’s get started.

In this article you will get to know Go as a person, and where it stands among the other programming languages that you are familiar with.

Why Go was developed?

Of course, you can browse the internet and find out that Go was developed by Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. But do you know why they wanted to develop Go?

To find answers to the above question, let us compare Go with three other popular programming languages: C++, Java, and Python. Consider the table below, which consists of the characteristics of these three languages.

The Go was developed by Google, to combine advantages such as High Performance, Type Safety, Rapid Compilation, Ease of Use of the above three languages. It also aimed to be modern, with support for networked and multicore computing. Refer to the article named “Go at Google” to learn more about the motivation and background of Go.

Advantages of Go

As a whole, Go incorporates the below advantages.

  • Quick Compilation (Compiled directly to machine code. No Virtual Machine.)
  • Fully Compiled
  • Strongly Typed
  • Default Concurrency (In the previous programming languages to support concurrency they have used third-party libraries. That is because when those languages were invented multi-core processors were not popular. But when the Go was developed, we know that there is a need for concurrency, so it was developed in a manner by default it supports concurrency.)
  • Garbage Collected (Also aggressive steps has been taken to stop lagging the speed of application development which may arise when supporting garbage collection)
  • Flexible — Simplicity as core advantage, easy to read and concise.
  • Library- It provides a rich standard library
  • Built-in testing tool incorporated

But there are a few disadvantages of Go as well.

  • No support for generics until now
  • Lacks of manual memory management
  • Not object-oriented in the conventional sense

When to use Go?

Several applications can be developed using Go. Below two are the most popular among them.

  • Web Services
  • Web Applications

The difference between Web Services and Web Applications is, Web Services deliver data to the users while Web Applications deliver web pages to the user using a web browser. Google has developed Go to support these since all the communication in Google happens through a network so that the concurrency of Go will help to perform multiple transactions at once when using Web Services and Web Applications.

Apart from that Go can be used in the below situations as well.

  • Task Automation — Scripting can be done because Go’s syntax is almost similar to other scripting languages such as JavaScript, Python or Bash.
  • Machine Learning — Syntax is similar to Python
  • GUI support — Refer https://golangr.com/gui/ for more information

Do you know that there are several popular applications that have been developed using Go?

Examples are Docker, Openshift, Kubernetes, Dropbox, Netflix, InfluxDB, and Golang (The language itself was written in Go).

Aren’ t you wandering whether Google uses Go for their internal work?

Yes, they are using Go widely in production inside Google. But remember, Go is not the only language used by Google. There are more.

Introduction to your first Go code

Did you installed and setup Go in your machine? No, right. Do not worry. Here I am just going to show you a demo using https://play.golang.org/. Go here, and you can test your Go code online. Cool right?

When you navigate to that URL, the below program will be there. Don’t worry, keep it as it is.

When you navigate to Go playground

Just hit the“Run” button on the page, and the output will be displayed at the bottom of the page as shown below.

After you hit the “Run” button

Let us identify the structure of the above code a bit.

  • Every Go code starts with the statement package xxx where xxx specifies the name of the package.
  • import (…) blocks can be used to import libraries so that you can use the functionalities in those libraries. The above example has imported “fmt” package from the standard library which consists of the Println(…) function, that was used to print a string.
  • main() function is the entry point of any executable program in Go. Generally, we have the main package and within that, we define the main function where the execution is going to start. This main program prints the string passed to the Println(…) function as shown above

Some basic significant features in Go

  • Go supports both single line and multiple line comments. The syntax is similar to what we have used in C++ and Java.
Single line and multiple line comments

The comments above the import statement are two single-line comments and the comment above the main function is a multiple line comment.

  • Suggests removing unused library packages or unused variable declarations. Just remove the 14th line of the program and run the program. You will get an output as shown below.
Running the program after removing the 14th line in the code

It says that the imported “fmt” package is not used. Here the Go insists the programmers write clean code, where the imported packages should be used in the code on that page. This increases the maintainability of code by removing unnecessary packages that have not been used.

Similar type of thing may happen if you initialize a variable but not use it. Check below example where in line 8 the variable was initialized but not used anywhere in the code. You will get an error message as shown in red when you run this.

A variable has been initialized but not used
  • Whitespace is not critical in Go applications. As shown in the below screenshot remove the space in the 14th line and run the program. It will not affect the execution of the program.
Proving the whitespace is not critical

By clicking the “Format” button, you can automatically format the code. It is encouraged to use whitespace in order to write code in a clear manner but it is not critical.

  • Applies semicolons automatically by the compiler by the end of each line of the code. Just hit enter before the opening curly brace (“{”) in line 13 and move it to the next line by hitting enter. Run the program and you will get an output as below.
Moving semicolon to line 14 and run the program

The compiler applies semicolons to the end of each line of code. The reason for the above error message is the compiler has assumed that since the opening brace of the main function is not found in the same line, it should add a semicolon after main() as below.

func main();
{
fmt.Println("Hello, playground")
}

Because of that semicolon placement, the compiler decided that the main function does not have a body. That is why you get an error message as stated above. In the above case, if you try to format the code by hitting the “Format” button, it will not be able to do that for you. But it will pinpoint the place and how it should be corrected as shown below.

Formatter pinpoints the error

Plus point is, if you want to write your code with semicolons, you can do that. But it is not encouraged. Just insert semicolons to each line and run the program as shown below and see what happens.

Conclusion

In this tutorial, we learned the nature of the Go language. I hope this will help you to compare Go with other programming languages that you have been using during the past years. As an exercise try to find answers to the below questions. Just for fun!

You can put the answers to the questions in the responses section if you wish to share them. Cool right?

  1. Is Go an object-oriented language?
  2. What characteristics of Go increase the “ease of use”?
  3. Which is correct Go or Golang?
  4. How should we spell Go? Is it like “Go” or “GO”?
  5. What IDEs does Go support?

Hope you have enjoyed the first tutorial. Goodbye until next time.

References

📝 Save this story in Journal.

👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. Read the Noteworthy in Tech newsletter.

--

--