DEV Community

Adrian B.G.
Adrian B.G.

Posted on

Golang, it was love at first sight.

The article was originally posted on my personal website https://coder.today/go-go-go-flash-bang-d66f4c42eb7c. Meanwhile I have developed a few libraries and small apps in Go, even contributed to Go Tour and I changed some of my opinions, but I will keep this article as it was, I like immutability.

“Go Go Go … flash bang”

When I hear “Go” I always have this flash…back.

Intro

Usually, when people have free time they do some R&R, but me, being weird and all I like to learn, experiment and play with new things. I have enough new hobbies (earlier this year I learned to pick locks & started to do mobile photography), so I decided to step up my lost programming mojo.

If {you are like me (web or mobile developer, avoided low-level languages and concurrency for any reason) keep reading,
else you already know the truth, skip to the end and share the article 😁.}

I was away from the Web development for a couple of years, doing Unity3D (C#) & mobile, so naturally I began to catch up with the latest web trends. I made some small projects using MeteorJS (node +hot code +~mongodb + other steroids), React and D3JS. By switching to nodeJS I ditched PHP, working in only 1 language, with shared code, I greatly improved my productivity.

If {you are a JavaScript developer check this hard-core 2017 playlist}

Go — the programming language

Reading about new architectural styles, scalability & cloud I found a pattern, most of the big companies (www backbone) switched in a way or another to Go.

When reading about it I found that we had a lot in common (me & Go), it’s a good start for any relationship.

  • We are both very opinionated

  • We like to work with JavaScript (building an API is easy or they can be complementary)

  • We deeply care about developer productivity

  • We like KISS. Simple is better (vs cpp)

  • 1 way to do it (idioms, code formatting). Having more ways complicates the project, the developer’s brain, team work and compiler’s life.

  • We suck at RegEx (but the contributors are working on it)

  • We hate bugs (so we enforce coding rules)

  • We like to multi taskand work with big data.

If {you are a Gopher please help me learn faster and review my code:}
bgadrian/data-structures
*data-structures - Abstract data structures Go packages, built with performance and concurrency in mind to learn Go.

For me Golang has a few more advantages:

  • It is the perfect mix between low & high-level languages. I want to deliver fast, get things done, so taking out the garbage is not for me. The steep learning curve keeps me away from low-level.

  • It has integrated Unit Tests — I was looking for a reason to start practicing TDD.

  • Community — after more than 60 hours of conferences panels and reading forums I can say it is a nice community.

  • I want to be more involved in the open source community, this is my Go sign.

  • It has identity & a cool mascot

  • It creates a pleasant environment (good tools, compiler warnings, idioms etc).

  • WebAssembly Learning a compiled language will help to gain an advantage & have fun writing JavaScript and WebAssembly modules in the same time.

Most of the “anti” Go reasons I consider them to be “pro” reasons, here are a few examples :

  • missing features like Exceptions- results in better code, who wants this chaos on this hands? .

  • “When 2 sides argue more than 15 min they are both wrong.” In this case wars took more than a decade, so Go being opinionated is a good thing. No more spaces vs tabs, functions vs objects, for vs while … Developers write the same code, compiler can optimize it better.

  • overloading — usually creates too much similar code, and there is no polymorphism, so no much use for it when you code in Go style. Overloading makes “cool looking code”, but is harder to debug, maintain and interpret. I think interfaces are enough (1 function does 1 thing, that can be relate to 1 interface) with explicit conversions.

Actual c++ codeActual c++ code

  • code is art/ has no soul — I think the beauty is not in the source formatting, rather at the system/architecture level, solving difficult problems with simple solutions.

  • most of the reasons can be easily ignored: they are too subjective, don’t understand the Go paradigms, their minds are stuck in OOP never land or they compare it with other languages like C/C++ (which is not an alternative for) or apply to problems outside of the scope of Go.

If {you want to be a better programmer by practicing katas check CodeWars}

Go learned from 30 yrs of development mistakes

There, I said it! It went back to the roots and returned like a Pheonix, better and with a fresh look.

I spent too many hours of my life debugging and fixing bugs. I remember a lot of fixes, mistakes and anti-patterns that I fixed along the years, and a lot of them are addressed in the compiler rules and coding style of Go.

Most programmers are humans, we have feelings and bad days, different experiences and backgrounds, different level of professionalism, technology/env evolves around the code. Bad code will always exists, but if the Language we speak (Go) can fix a lot of issues (even before they exists), shall it be!

If {you want to learn Go check out my first steps:}
First steps in learning Golang
*How am I learning Go as my new main language, what resources & techniques am I using?*coder.today

Done, rant over, thanks for reading!

Thanks to ashleymcnamara, her gopher panel inspired me to start contributing.

Top comments (20)

Collapse
 
bgadrian profile image
Adrian B.G.

Ah yes, sorry about that. I think I used the wrong words, is not that I changed my mind, but I can add more details or debunk some of the ideas. At a first glance:

It has identity & a cool mascot

Gophers are cooler than I expected, I even made one

We like to work with JavaScript (building an API is easy or they can be complementary)

I didn't found any support for this, it supports the same features/frameworks like most popular web languages: a template system (builtin), Go-JS compiler, Go-WebAssemly compiler (builtin), but nothing special.

We like to multi taskand work with big data.

I didn't realized the scales of the projects where Go is used, and at what stack level is used. I have found important, latency and HA sensitive projects, I don't have time to put the links now but the resources are out there, a few examples are: Dropbox new storage system, Kubernets and Docker, Consul, DGraph, CockroachDB, terraform, Cloudflare analytics and othe systems ...

Community — after more than 60 hours of conferences panels and reading forums I can say it is a nice community.

Is an understatement, I found the community to be great, especially the Slack server.

I have found some limits, or downsizes:

  • intensive realtime, time sensitive apps is kinda cumberstone because of the lack of memory management, but I saw some talks, so they can be done but is harder
  • the builtin web server tools are too simple and don't have the proper default settings to be used in production, if you don't use a framework or some modules you will end up writing your own (like GorillaMux for routing)
  • Package management, Generics and error handling are the top 3 problems in Go and they are taking care of, in the next Go versions
  • Concurrency paradigms are not so easy to understand (is not related to Go, is just a new way of thinking), but are very easy to implement in Go.

Overall I still love it, I even have a personal goal to be an expert in Go in a few years, is a language that doesn't lie, WYSIWYG, simple, pragmatic and efficient.

Collapse
 
biros profile image
Boris Jamot ✊ /

Go 1.11 brought the concept of modules that allows to resolve the package management issue, like npm or composer.

I think that Go is production ready for many purposes as it's getting more and more used in software industry (elk beats, docker, openshift...).

Thread Thread
 
bgadrian profile image
Adrian B.G.

Go modules are not ready yet, after the need of /vendor dissapear then it will be ready.

I know about them, I even read the original longgg VGo articles and I love the idea. Coming from a NPM nightmare projects where errors and random builds occurs is going to be a bless to work with go modules.

Thread Thread
 
biros profile image
Boris Jamot ✊ /

I don't know much about Go and modules but I know we use it in my company for a big project. And yes, I noticed that /vendor was committed and my eyes started to bleed ☺️

Collapse
 
ahmadawais profile image
Ahmad Awais ⚡️

Can you share with me what is the immediate benefit of Go for a frontend dev? Where can I use it immediately? I loved it at first sight but couldn't find a thing to do with it. That has to do with small businesses.

Collapse
 
bgadrian profile image
Adrian B.G.

Immediately usage is none for a front-end dev, maybe:

  • WebAssembly if you have to write performance based front end library.
  • make your own back-end stubs/small services

But ...

I (and others) suggest to learn a new programming language each year, at least at the beginner level. 30 hours per year is a small price to pay for the advantages. It will change how you think about programming, learning new paradigms, constructs that will enlarge your horizons and make you a better developer.

Collapse
 
ahmadawais profile image
Ahmad Awais ⚡️

I do do that. I am failing to find a project to work on with Go. I don't believe in learning for the sake of learning. I learn to produce production quality software. So, that's why I asked :) I enjoyed Go a lot.

Thread Thread
 
bgadrian profile image
Adrian B.G.

What are the top 3 problems you face when building websites, what will make you to be more productive, efficient or your projects performant?

Choose a problem and build a solution, or contribute to an already made one. I'm sure that your problems are similar with other front-end devs aswell.

Collapse
 
itsdarrylnorris profile image
Darryl Norris

One project that can be considered "front-end" is Gohugo. Gohugo is a static website generator is pretty cool. However, GoHugo uses their Golang templating language, which is pretty weird(or different from other templating languages out there).

Golang can be used to create API's to build your front-end or even server-side rendering.

I am not sure if that answer your question or not.

Collapse
 
ahmadawais profile image
Ahmad Awais ⚡️

That's exactly what I tried to do. Haha. I built my last talk's slide with Go Hugo. wordsesh2018.ahmadawais.com/

Honestly, it felt a bit hard to do as compared to using Gatsby which is written in JavaScript/React.

Thread Thread
 
itsdarrylnorris profile image
Darryl Norris

I can see why making a slide using GoHugo will be painful. GoHugo seems to be targeting more plug and play website tool with possibly a lot of content creation. Compare Gatsby, which more like a framework build static website generators.

Collapse
 
lobocode profile image
Vitor Lobo • Edited

A simpler way to create a generic golang project that makes more sense than using the go mod init name command, is here:

Into ~/.bashrc or ~/.zshrc

#Create Go project
goproject () { mkdir -p $1/{src,bin,pkg,vendor} && touch $1/main.go }

And now, use the command

goproject example
Collapse
 
redeving profile image
Kelvin Thompson

Thanks, this is great for me since I'm a Go newbie. However, I kept getting a bash error:

syntax error: unexpected end of file

I had to add a semi-colon after after main.go so the parser didn't keep going insane. I'm running LMDE4.

Original: #Create Go project
goproject () { mkdir -p $1/{src,bin,pkg,vendor} && touch $1/main.go }

No Error:#Create Go project
goproject () { mkdir -p $1/{src,bin,pkg,vendor} && touch $1/main.go; }

Thanks again! Cheers!

Collapse
 
debugging profile image
Salman Ahmed

I love the simplicity of Go also, especially coming off a scala project.
I have to say I sure to miss the rich collection library of scala (and even c# for that matter).
In the end being able to write and read other developers code has given me allot of inner peace.

Collapse
 
bgadrian profile image
Adrian B.G.

You will see that rich frameworks and libraries will appear to Go too, but I hope not in the same way.

Being at a lower level of abstraction than C#/Java, to keep performance in the top priorities we need to see, know and understand what each function call does. It is hard to do that if you use a library with 20 levels of inheritance in 200 files, or worse, letting the ORM generating queries for you.

Collapse
 
debugging profile image
Salman Ahmed

Agreed. Being able to understand the code from your dependancies can be as important to understand as your own code when dealing with production issues. You own all the code when something is down.

Collapse
 
revskill10 profile image
Truong Hoang Dung

What Go can do that Javascript/NodeJS can't ?

Collapse
 
bgadrian profile image
Adrian B.G.

This post is about my subjective passion for Go, but I can be objective too to answer your question. I'm sure others provided better answers but I'll try to sum it up in a few examples.

Basically you can see Go good for building databases, proxies, servers and CLI tools, while NodeJS keeping the business logic and websites.

Sure there are things that NodeJS can do and Go cant! I even keep a list of how many things JS can do nowdays and is getting bigger every month!

I even see them complementary in mid/large size products and teams. If you already have a NodeJS large app you can extract the golden paths that needs to be fast responsive in small go services, keeping the benefits of both languages (like finding developers).

For me personally, after 8yrs+ of JS (not node) in production I can say Go brought me inner peace, stability, solved many engineering problems I faced in real products and simplify the entire building process while making faster and more resilient apps, with only a few keywords. Is not the holy grail! it is just better for me and it suites my next career needs.

Collapse
 
quii profile image
Chris James
  • It's simpler to read and write
  • Better tooling
  • Easier to ship
  • Generally will perform better, especially on CPU bound tasks