Golang: Introduction

Golang: Introduction

ยท

3 min read

A confession first I am a JavaScript lover, but whenever i write or read code of Golang my loyalty to JS starts fading away, sorry JS :(, enough of my romance now lets move to the subject why you came here for.

We'll discuss super-basic of Golang

Now what's Golang?

It is a statically typed compiled programming language, the design philosophy of Go is to write reusable pieces of code as packages and make your application using those packages. If you are familiar with ReactJS you can relate it with so easily, So what is statically types and compiled language?

Compiled Languages are converted directly to machine code that the processor can execute not line by line like interpreted languages, which infers more power to the compiler hence performing all types of checking and therefore can catch bugs at early stage.

Lets look through infamous "Hello, World" program in Golang and understand what each line interprets

package main 

import "fmt"

func main() {
  fmt.Println("Hello, JS ๐Ÿ˜") // Hello, JS ๐Ÿ˜
}

package main : when building an executable program we use package main, this tells the compiler that package should be executed as an executable program not as shared library [ shared library ? collection/set of packages ]

import "fmt" : here we are importing a package fmt that is responsible for formatting strings, values and printing them or collecting user's input from console, in simple terms this package is all about formatting input/output

func main() { // code } : the main function in package main is an entry point for our executable program, but while building packages there's no main package and main function.

fmt.Println("Hello, World") : here we are using a method/function Println defined in fmt package which is used to format the strings, values and prints on the console. Now you may wonder why Println() has a capital P this is because while creating a package if there is a function that is meant to be used outside of the program it has to be defined in capital letter.

For more of Golang, visit its super-awesome documentation ๐Ÿ˜Ž


So this is it, we may meet in other articles of Golang, before that a tip If you are facing difficulty writing a topic, that means your foundation for that topic is still need to be brushed more, that's what i have faced writing this :)

I hope this helps in your developer journey, bye for now ๐Ÿ‘‹

ย