In my latest role, I had the chance to learn a bit of Go (or Golang).
My whole programming career I've been using JavaScript and TypeScript. I dabbled a bit with PHP. So let's just say that Go is officially the second programming language I'm learning.
So, here are my takeaways:
It's easier to pick up a second language
When I started with JavaScript, it was daunting. I had no idea about programming. All these concepts of memory, loops, data types, algorithms... Everything was new. You start to connect the dots after a while, and once you get the logic right, it's easy to spend hours on MDN and deepen your knowledge.
Now, with Go, the thought process is more like:
"So this is how you do a for loop, it's different from JavaScript in this and that way"
I have the basics of a programming language in my mind, so with Go, it's just figuring out how those basics work. It's a great exercise to constantly compare both.
JavaScript is a mess
Everything in Go is more organized. go.mod
and go.sum
are so much simpler and clean than package.json
and the dreaded package-lock.json
.
The Go CLI is a joy to use. The thing is that everything is built into the language. When we use JavaScript, we have to use NodeJS to interact with the OS. And NodeJS is great, but it is a library/framework hacked on top of JS. I'm sure tho that if we had to rebuild NodeJS today, it would be much better (hello Deno).
The documentation in Go is excellent. Every package has its documentation page. For example, let's have a look at the HTTP package.
Everything is faster in Go
Or at least it feels that way. I don't know enough about the innards of Go to tell you why it is faster. But literally every action I do feels a bit faster than in JavaScript.
Go is making me a better programmer?
Pointers
There are some basic programming concepts that you never even touch in JavaScript. The biggest one I've had to spend some time with are pointers. I'm still wrapping my head around when to use *
and &
, but at least the concept of memory addresses is clear in my head.
Error handling
I like the style of defensive programming that Go enforces. There's a pattern you see all the time:
f, err := os.Open("filename.ext")
if err != nil {
log.Fatal(err)
}
// Do something if there's no error
So whenever we do anything, we first check if there's an error. If not, we proceed.
This is great, because how many times you've had an unhandled error in JavaScript? In JS you always need to actively make sure that you catch an error, usually with a try/catch
block.
In Go, by putting the error first, we make sure we always handle it.
You can easily compile
Whatever code you write, you can build it as an executable file for multiple systems.
I'm not sure if you can do this in NodeJS - but for sure it's not built in. To run NodeJS programs you usually need to have NodeJS installed, and then run node your-program.js
.
JavaScript is simple & it works
In JS, it's pretty easy to write some messy code in a few minutes and see its effect. Hell, you can even right now open the dev tools in your browser, go to the console and just do alert('hello')
and it will work. JS is still the language of the web; so I don't think it's going anywhere.
Around the web, there are thousands of libraries written in JS. There's more documentation, and more people using JavaScript than Go. I've already had quite a hard time finding some answers for Go questions - and I always find the answer for JS.
I can see Go succeeding at replacing NodeJS, but for websites, JS and its frameworks will still prevail.
That's why, if you are a Full-Stack developer, I recommend you to take a look at Go, mostly for the backend: https://go.dev/tour/welcome/1
Top comments (1)
See also:
reddit.com/r/golang
gophers.slack.com