What I love about Golang as a Javascript developer

What I love about Golang as a Javascript developer

ยท

2 min read

I have been developing in Javascript(Typescript) and it's ecosystem for little more than a year now. After publishing my first simple go package, here are what I love about Golang!

It's Simple

I found Golang code more readable and simple. There are currently only about 25 keywords.

Plain Javascript is simple but developing in plain javascript is prone to runtime errors, bugs and hard to refactor. Using Typescript happens to solve most of the above mentioned issues for me but there is a catch. Typescript increases complexity of the code.

โญ Builtin Tooling

Golang comes with tools for testing, bench-marking and formatting. I can start writing test without installing an external dependency, awesome!

If you are writing test in javascript, you would have to install a testing framework and test runner like jest.

Testing

After writing your test in package_name_test.go, just run the following in the terminal

go test

Formatting

To format code, run the following

go fmt

Documentation - GoDoc

Godoc extracts and generates documentation for Go programs. It runs as a web server and presents the documentation as a web page.

Easy deployment - Server side

In javascript backend projects, we would require dependencies installed in the deployed platform. With golang, you can build a single binary for any platform you would like to deploy from your platform, cool!

๐Ÿš€ Delightful Concurrency

Being a javascript developer, I am more used to asynchronous programming.

You can't solve all problems using asynchronous programming. Asynchronous code is more simple to deal with, than a concurrent code but for CPU bound tasks, concurrent programming is way faster.

Concurrency is baked into golang making it easy to use.

go functionName() // spawned a new goroutine

This is how easy to spawn a goroutine. Goroutines are like very light weight threads (this is a over simplification though).

Channels make it easy to communicate between goroutines.


//Creating a new go channel
ch := make(chan int)

//Spawn a new goroutine
go func() {
    ch <- 101 // Send value (101) to the channel
}()

//Read data which is being sent to the channel
receivedData <- ch

fmt.Println("Received " ,  receivedData)// Output "Received 101"

With golang, I started enjoying concurrent programming!