now we will learn the Go or Golang programming language. What is Golang?
Go or Go Language, commonly abbreviated as Golang, is a programming language created and developed by the Google team. This language was created by the google development team in 2007 and released to the public in 2009. Making golang is based on the C and C ++ languages. This is what causes Golang and C to have a fairly similar syntax. Unlike most new programming languages, Golang does not adopt Object Oriented or Generic programming.
This language was originally created only for Google’s internal company, but in 2009 Golang was finally released to the public in an open-source manner which means that the code is open, can be written, modified, and redistributed.
One of the famous Golang developer members is (Ken Thompson), a computer scientist who is also known as the developer of the Unix operating system. The other members of the team are Robert Griesemer and Rob Pike.
Golang is one of top 12 the most popular programming language in the world.
What can be made with Golang?
Golang can be used as a beck end language for any program, be it website, mobile, and others. This language is usually used to create RestAPI, due to its friendlier syntax and efficiency that is not inferior to the C language. As we all know efficiency is one of the most important things in choosing a programming language. In the world of programming efficiency is a process in which few resources are used to achieve the expected results.
Here are some applications made using golang:
- Monzo – An online banking application based in the United Kingdom.
- Allegro – Online Shop Application in Poland
- SoundCloud – Online sound distribution application that enables collaboration, promotion and distribution of sound recordings.
- Bado – Multi-language bureau based social networking service.
- Uber – Transportation Service Application from San Francisco (Once operated in Indonesia before finally Uber which operates in Southeast Asia in the acquisition of Grab).
Advantages of Golang
Just like other programming languages, Golang certainly has advantages over other programming languages. Here are some of the advantages possessed by Golang:
- Easy to learn – Golang’s syntax is smaller which makes it easier to learn.
- Have concurrency – Concurency is the ability to split into smaller parts that can function independently.
- Have a garbage collector – The garbage collector is a tool for managing memory allocation.
- Faster – Golang is a fast language because it is compiled into machine code, in contrast to most other programming languages that work with virtual runtime.
- Complementing the deficiencies of the previous language – Every new programming language comes with the aim of correcting the deficiencies of the previous language Some of the shortcomings that can be overcome by groups such as lack of multicore support, lack of parallel computing support, complex type systems, and complicated memory management.
Golang Writing Rules
Each programming language has a different structure and writing rules. Here are some writing rules and the use of certain functions in golang.
Method main
package main
import "fmt"
func main(){
// kode disini
}
Import package in Golang
Packages are used to use certain functions. For example, the code below shows import “fmt” is used so that the program can use the fmt package .
package main
import "fmt" // kode import
func main(){
// content main
}
Display writing
package main
import "fmt"
func main(){
fmt.Println("Halo dunia!")
}
To display the text in the golang program, the code fmt.Println (“Posts here”) is used , where previously we had to import the fmt package in order to use Pintln (“”) .
Data Types and Variables
Broadly speaking, in Golang there are three types of data types, namely number, string, and boolean. Number data types are data types that contain numbers which are divided into two, namely integers (whole numbers) and floating point (decimal). The integer itself is further divided into:
- uint – a number data type whose content cannot be negative
- int – can be positive or negative numbers
Apart from the two types of Integers above there are still bytes but this type of integer is rarely used. To understand more about data types, the following is an example of a program that combines variables with data types.
package main
import "fmt"
func main() {
a := "Codingrakitan.blogspot.com"
b := 7
c := true
fmt.Println("a = ", a)
fmt.Println("b = ", b)
fmt.Println("c = ", c)
}
The code above will display the program as shown:
Kondisi if else
package main
import "fmt"
func main(){
a := 10
if a > 10 {
fmt.Println("Nilai a lebih besar dari 10")
}else{
fmt.Println("Nilai a tidak lebih besar dari 10")
}
}
The code above shows a condition where if a> 10 then displays the words Value a is greater than 10, if not or otherwise, then display the words Value a not greater than 10 .
The For loop
Here is an example program using the for loop system:
package main
import "fmt"
func main(){
for i := 0; i < 5; i++ {
fmt.Println("Nilai = ", i)
}
The code above will display the value of writing five times with the value of i changing from 0 to 4. Why it starts from 0 because the variable i is initially formulated as i: = 0 , then why only goes to 4 because i <5 means i is less than 5.
Write a comment
Comments are very useful for marking as well as providing information on a certain section. The use of comments on the program is very useful if the application that has been created includes a lot of code, and helps programmers in doing teamwork. There are two types of comments on golang, namely inline comments (one line) and multi line comments (many lines). Inline comments use the // sign while multi-line comments use a line opening / * and a line closing * / . To better understand, see the example below:
package main
import "fmt"
func main(){
// ini adalah komentar inline
}
package main
import "fmt"
func main(){
/* ini adalah
jenis
komentar multi line */
}
On the official site golang.org you can see that golang can be installed on Windows, MacOS, or Linux platforms.