Introduction To Golang
Introduction To Golang
- Berin Aniesh.
In this article, we will learn why golang exists and also learn the basic
syntax of the Go programming language.
When golang was created, the most popular languages at Google were
C/C++, Java and Python and each language had its own problems.
● C/C++ is difficult to program in, has long compile times, has a complex
type system, and is not modern because it has to maintain compatibility
with old code bases.
● Java again has a complex type system, uses large amounts of memory
and is slow.
● Python is an interpreted language, which is obviously too slow for any
performance intensive tasks.
● Simple by Design
● Speed - Go is a compiled language which implies it is fast
● Parallel Computing - Go is built with multithreading in mind
● Garbage collected - No need to worry about memory management
● Extremely fast compile times
● Strong community
● Large number of libraries available for many use cases.
● Compiles to a single standalone binary - no dependency hell or external
libraries needed.
● Docker
● Kubernetes
● Terraform
● SoundCloud.com
● Uber
● Hugo
The second statement imports the fmt library which is needed to print
text to the console.
https://www.pepcoding.com/resources/online-java-foundation/function-and-
arrays/bar-chart-official/ojquestion
The interesting point to notice here is line number four. This is the same
as the “for each” loop in most other languages but the index is not given a
variable name but an underscore because Go doesn’t allow unused variables.
If we were to use a variable name in place of the underscore, we have no use
for that variable and Go doesn’t allow us to compile the program.
Also note that the function linear_search has a return type of boolean,
which is specified at the end of the function declaration.
Program 5: Structures in go
Note that there are no object constructors or method overloading. They are
left out on purpose in Go to maintain simplicity.
Fun fact:
The code for the above programs can be found in the following github gist.
https://gist.github.com/berinaniesh/79dfb1378aa18c2e4264bd97fa256895