My journey from JavaScript to Go

Steve Hook
18 min readMar 10, 2021

Having already 2+ years of production experience in Go, made me look back a little bit and realise where things actually began. It’s probably no surprise that most people that write dynamic programming languages tend to make their code as safe and stick to as many practices that statically typed languages already have there by default. In this article I will share my personal journey from JavaScript to Go aka Golang. If you want to find more about my activity make sure to check out my YouTube channel where I share many more things about Go including the video about My Journey from JavaScript to Go, and not only. Without any further ado, Enjoy your reading 😉

How it Started

Like many people in the business, for a long time was looking for a Nice, Statically Typed programming language, which does not sacrifice on Productivity or Performance and at that time I couldn’t really stick to something that was compelling enough. At the time, the only options I was looking at were the OOP giants like: Java and C# or the absolute performance beasts: C/C++. So back then I had to choose between performance or maintainability and nice language design. There was the desire of switching to a more mature, stable language for a long time, there were just too many tradeoffs, and like any other JavaScript dev, I felt comfortable and did not consider switching.

Want to read this story later? Save it in Journal.

It was all true, till I first got my hands on some side by side comparison articles between Go and Node.js. And my first question was, What is Go? and How serious this language really is? 🥴

Right after reading couple of articles, my curiosity level just raised, and I thought, why not try it, maybe I will like it. Maybe this is that language I was waiting for. I started having a look & tinkering with the language, realising I like it more and more. Running example after example, got me more and more into it. By the time I started getting a little bit more confident with it, I also started to kind of get sick of dynamic languages more and more, for instance JavaScript looked more and more odd, and Go’s language design and the way things are done there looked more and more OK.

Looking more and more into the language, what also attracted me a lot was its signature. I saw respected names in the community there, names like: Rob Pike, Ken Thompson & Robert Griesemer. For many people these people may not mean much or anything at all, for me they just made the language look even cooler and better and got me even more curious.

So really I was in the position when playing with dynamic languages wasn’t fun anymore. Even though I was in the game, was aware of most JavaScript gotchas, and felt pretty confident with it, it would still slap me every once in a while and the development was so crazy and changing pretty fast and can get frustrating a lot of the times. Transitioning to another programming language was already an option in my mind and I started considering the move.

First Impressions

Before even getting a job my impressions about the Go programming language were not the best. I thought the language was really: UGLY, PRIMITIVE and TOO SIMPLE. And I think anyone coming from a dynamic language full of nice & clever features will think exactly the same way.

Going through some simple tutorials and videos, it may seem like Go is a beautiful and really easy to use language. Which is not quite the case with JavaScript. So, right after I got the job, I of course had some expectations, specifically that the language won’t be that fun in the real world, because of my experience I had in the JavaScript realm. Usually the experience with JavaScript is as follows: you know all the gotchas, best practices but when jumping into the real world projects, it gets pretty messy and ugly and if we are talking about outsource companies where deadlines go before code quality, forget about best practices in general. So I was expecting pretty much the same from Go.

A lot of the times I thought the language is really just another extension of the C language, which not all of us really loved in university. Not to mention, in the beginning the language really looked ugly to me, especially the Error Handling. On top of that, I was expecting it to at least have OOP in place, and then surprise, surprise. We only got functions and structs that map to functions. First thing that comes in my mind is: THIS IS SO TERRIBLE. Also, it felt like you don’t have enough vocabulary to express yourself (25 keywords) only and I really thought it was too simple, and it’s meant to be used for toys, not real projects. Not to mention the so limited amount of features, without any kind of clever constructions which we are used to in other languages, especially JavaScript. So overall, my impressions were not very positive, I told myself, “I’m gonna try it, and perhaps stick to JavaScript, this is just another version of weird, modern C”, not long after that obviously my opinion changed.

To give you an example of how weird Go really looks in the beginning, have a look at a simple OOP example in Go. While Go claims it’s not OOP, this is how OOP can be achieved in Go, and I agree, just like you I thought what kind of an ugly language, and why would you do it this way?

Example:

The way OOP looks in Go

Expectations

With first impressions come expectations. As a JavaScript developer at the time, I had loads of expectations and a lot of them were not met. Because I was used to the way things are done in JavaScript, I of course expected the Go language & ecosystem to have the same things, by the same things I mean having loads of frameworks and libraries for really any stupid thing, and just import it and the job is done, having lots of features and clever ways of doing things. To my disappointment, not too many frameworks at all, not to mention they are discouraged in the community, the libraries out there are not as many. In fact what you’ll probably find are libraries for the most popular concepts such as: db drivers, algorithms and certain concept implementations. A lot of the rest you’ll have to write/implement yourself, either because the community thinks they are not needed, or they are too easy or custom to implement, which means anyone can do it by themselves.

I was surprised to see that Go’s standard library does not even have HTTP Session support, which most modern languages out there have built-in. Then you start asking yourself: What is an HTTP session? Is it a file based session?, is it a distributed session? Then you realise, some things are just too custom, and it’s wrong that someone has to decide for you. Which means at the end of the day you will look for a library which satisfies your needs or just implement it yourself according to your needs, which of course means you have to know the Concepts first.

Now because JavaScript has so many solutions for the same problem, I was expecting at least the same amount of clever & magical arsenal of language features.

Up to know (Go 1.16) there are only 25 keywords that make up the Go programming language, which may be surprising for many.

On top of how simple and minimalistic the language design is, coming from JavaScript and being biased by the C language I was expecting Go would have many gotchas & magic that I had to be aware before considering the language, and quite frankly I was surprised how transparent the language is, it’s plain & simple, sometimes really stupid, which makes no place for gotchas and magical code, which is a norm in dynamic languages such as JavaScript.

Similarities

Moving from one ecosystem to another, the best way to learn is of course by comparing and contrasting. It’s what got me into Go in the first place. So I gotta say there are a few similarities between Go & JavaScript:

Go is Easy to Prototype

It does not take you a dozen of classes and declarations to output some HelloWorld, or run complex things such as an HTTP server. The following code is ready to serve millions of requests without needing special tools or extra 3rd party solutions. It’s as simple as using the powerful standard library.

Example:

Production ready HTTP Server using Standard Library only

Go can get very Ugly

Just like JavaScript, things can go out of hand really quickly if no measures are taken. I should stress out though that we’re talking more about the readability of code, when I say Ugly. Luckily Go solves a lot of other ugly things right on the compilation level, so it’s not that Ugly, but it can get so, if not paying attention. Error Handling is one aspect I personally don’t like, because it gets out of hand really easy. There are ways to avoid if err != nil statements, but one that starts writing Go will get into this mess really fast, especially when code starts to grow.

Example:

Ugly Error Handling in Go

Go is a very Accessible & Productive language:

Even though Go is a statically typed language, a lot of the times it feels very dynamic. It just takes a little bit of getting used to the whole Typing thing, in rest it feels like it’s dynamic, which makes it so productive and helps bring ideas faster to life. Not to mention it’s so accessible, it runs on pretty much every major system out there with cross platform capabilities when building the project. Setting couple of environment variables before the build really is all that it takes. It goes as far that you can even run it in your browser inside Go Playground. The same applies for JavaScript, it literally runs everywhere and it is cross platform. What else one can ask for.

Differences

Obviously Go has a ton of differences compared to JavaScript, which I did not quite like in the beginning, but happen to have fallen in love with as I experimented with it.

Statically Typed nature

Of course, I picked up Go because of its Statically Typed nature, meaning it is a compiled language, not a scripting language. The best statically typed ecosystem in my opinion. On top of the fact that it feels very dynamic, it also has very strict rules and it sorts out a lot of things/bugs/issues right at the compilation phase. You may also think because it’s a compiled language, bigger projects take forever to compile, like Java for example. Well to my surprise and yours as well, IT REALLY TAKES SECONDS to compile a Go program.

Mostly used for Backend/Systems

The nice thing about JavaScript is that you can really use it for everything, which a lot of people out there do. Just hire JavaScript devs and they’ll do everything for you starting from: Frontend, Backend, Mobile, Desktop and you name it. It has a huge advantage in this area, whereas Go is mostly used for Backend and for programming Systems.

Stable (without breaking changes)

Compared to JavaScript and really any language, Go in my opinion is the most stable language. It has little to no changes in its ecosystem, and they are all backwards compatible, no breaking changes, which is hard to say about JavaScript code, which can break from month to month or even weeks, by simply upgrading a library and what not. Having a look at Go’s ChangeLog you can see the changes from release to release are literally just improvements, rarely small amounts of features that are either improvements or really necessary.

Simple language Design

Another thing that makes Go shine is its Simple Design. Simplicity is in its roots, which make it look really weird and primitive at first, then with a little bit of practice you realise you don’t need much to write modern software programs, and the language design is really what keeps me falling in love with it. Of course Simple does not always mean simple, many times you need to have context on what you are doing, but generally the language constructs and the way one would use it, is very predictable and has a simple design on every level. The is really no-one who can explain Simplicity better than Rob Pike, that’s why I recommend checking out his presentation on Simplicity is Complicated

No Centralised Registry

Now the thing we all love about JavaScript is the biggest global registry of packages called NPM. You can download anything you want from NPM, and literally while you sleep there are 22 new packages pushed to the registry every day. A lot of it s crap, but there are a good load of useful things as well. Now compared to JS, Go does not have centralised global registry. Go allows you to be flexible, so it supports really any kind of VCS, GitHub, BitBucket, or even your Custom Domain, really anything that supports Git, SVN and not only. This as well makes it a perfect fit for private packages & proprietary software. This makes it a very powerful tool, but of course making sure the dependencies are secure is your responsibility. With recent updates Go does try to mitigate security/performance issues when it comes to dependencies, but in general it’s the developer’s responsibility to deal with the security & safety of dependencies.

A nice way of discovering new packages/libraries is usually by accessing https://pkg.go.dev/

Libraries & Concepts over All in 1 Frameworks

When it comes to 3rd party libraries and frameworks, Go keeps on growing every day, due to the increase in adoption. However, when it comes to dependencies, the Go community encourages libraries & concepts over fully fledged frameworks that do it all. So knowing concepts is a far more common thing in Go, rather than importing a library which does it all for you.

Powerful Tooling

What makes Go even more attractive than any language, including JavaScript is its tooling. By simply installing the runtime, you get access to really anything you will ever need. By invoking the go command you get access to built in: build tool, package manager tool, testing framework, profiling & debugging tool, formatting tool, code check style tool, documentation tool, and really a bunch of many other things, you name it. I’ve never seen a language be so rich and have everything in one place. Usually you download the runtime, then start fetching X, Y, Z dependencies that work with the runtime. In Go everything is so well defined and to most people’s surprise, the standard library, runtime and tooling are just so good. A simple go help will give you all the options available.

Powerful Standard Library

Like the above mentioned tooling, I’ve always praised Go for it’s powerful Standard Library. I’ve never seen a language where you can do production ready things by simply importing the std library. In other languages, including JavaScript, you either have to use a framework/library or look for 3rd party solutions provided by giant open source players. Go really shines in this area, which justifies the fact that you don’t really need to rely that much on fully fledged frameworks. To prove you how powerful the standard library really is, I just implemented a TCP Memory Cache Server, in a very few amount of LoC using just the Standard Library. Run the following program and telnet into localhost:8080 and you’ll see things actually work 😉

Example:

Memory Cache TCP Server Implementation using Standard Library

Workhorse Performance

As stated in the beginning of this article, I never wanted to choose between performance or nice language design or productivity. Speaking of performance Go does not disappoint. In comparison to JavaScript’s Single Threaded model, Go is a Multi Core Concurrent Language with the best Scheduler I’ve ever seen. Making any piece of code run asynchronously only requires the keyword go. Yep, it is really as simple as that, and it also runs on multiple threads and is very efficient, much more efficient than languages that map application threads to OS threads directly. Go runs everything in its own tiny structures called Go Routines, which are memory efficient and blazing fast. Running the following example on a multi core machine will execute by default all go routines on as many threads as many physical cores your machine has.

Just FYI, Go does not even specify that it’s a concurrent language in it’s official docs. This is what it says when you open up golang.org

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Example:

Async code in Go

Things I Like

Overall, these are the things I fell in love with when picking up Go and still continue to love them from day 1:

Simplicity

There is no doubt so many people love Go, and one of the reasons why they do it is really Simplicity. Simplicity of writing/maintaining/testing/documenting Go code. It’s really what makes the language shine. To give you the smallest example on how simple Go is. Take for example Encapsulation. In Go as I said there are only 25 keywords, meaning there is no place for public/protected/private keywords. You just uppercase it or lowercase it, and it works for absolutely everything: constant, variable, function name, struct name, struct field, and really anything that has an identifier and is uppercase will be Exported, everything else will be Un-exported. This is again the tiniest example of simplicity, it goes much further than this.

Example:

Robustness & Strictness

Having a system which feels simple, requires very strict rules, which make the system far from breakable. Go fixes a bunch of issues present in C/C++ and also regarding Robustness I’ve never felt that confident when it comes to deployments, I don’t need to worry too much about how my code will behave or if it will not meet performance requirements. It’s something which simply works and it’s resilient, providing the clients with a production ready ecosystem.

Safety & Stability

Go is robust and makes slow decisions which results in little to no changes, unless they are required or pushed by the community. So it’s hard to break the language, or expect it to break your code in couple of years. For me personally feeling confident on this one is very important. And all I can say this pays off in the long run. Last time I checked my JavaScript project I probably had to upgrade tons of libraries, which 99% of them would break my application entirely. We are talking couple of months or even weeks difference. In Go things are pretty stable & safe when it comes to that.

Productive

The nice thing about Go is that you don’t need to sacrifice performance or safety for productivity. As mentioned earlier, even though the language is statically typed, overall with a little bit of getting used to feels so dynamic and productive, allowing to bring ideas to life easily, yet staying in the safety and high performance zone.

Can get hired without any Go experience

What scares a lot of people, is the gigantic amount of experience one must have in a language to get a decent position as a JavaScript developer. Because Go is relatively new for many companies and its adoption becomes crazy lately. Companies simply hire people with the right problem solving mindset, and expect engineers to get comfortable very fast, because yet again the language is so productive and accessible.

Things I Don’t Like

Too Simple

Go’s simple design is undoubtedly the best thing I love about the language, but sometimes it feels like it lacks more complex structures and features that other languages have. Having a simple design also takes time to understand how to use it for the best productivity, which results in a lot of messy code written by Go juniors, but it is not so bad, compared to messy JS code.

For example at the moment of writing this example, there is still no support for generics, which results in ugly type assertions, which again in my opinion this type of simplicity lacks a small amount of features which kind of defeat the purpose of keeping the language features as Minimal and the language design as Simple

Example:

Ugly type assertion in Go

Can get Ugly

Despite the fact that Go is a simple and clean language, it can get very ugly if measures are not taken. Especially Error Handling can get very messy. With a simple design in place comes ugliness due to incorrect use of the ecosystem.

Small Adoption/Market

While Go is a nice language to try, not many companies make the jump, most companies already have certain technology stacks in place, so they don’t really bother switching, because it usually implies wasting resources on training and perhaps finding other talented people to help with guidance and expertise. So while Go seems like a cool language, finding a real world job can be a struggle. It of course depends on the market, the are countries/specific cities where Go is getting a lot of traction making it easy for individuals to get a job. On the other hand there are companies who don’t like big changes, just like in my case, where the market is quite underdeveloped, and Go developers/enthusiasts can’t really get a job.

First Steps

By the time I got my hands on the Go programming language, I started seeing the brighter side and was ready to make the switch. Was a little bit confused on how do I do it, because I’ve never really had to make a decision like switching languages, specifically statically typed languages. So I made up my mind in the end and started picking up some learning resources.

A tour of Go

I started first with A tour of Go, which quite frankly was surprising for me to see how warming the language welcomes really everyone into the ecosystem without too much sweat, blood and tears. You can just open that in your own browser and by the end of walking through the Tour, you will already have an idea of what does Go feel like. It may seem stupid and may feel like you’re gonna miss on things, but really A tour of Go is pretty much going to walk you through the entire Go language.

Articles/Blog Posts/Videos

Picking up any new ecosystem is really about how rich it is when it comes to resources. So after finishing with A tour of Go, I started looking into other kinds of articles & videos. I soon realised Go already had a pretty big number of useful articles & blog posts and a bunch of pretty good reading resources to learn from. Could not say the same thing about video resources, which JavaScript was full of, on really any platform. I found some courses on Udemy as well, made sure to complete them, then started to ask myself, NOW WHAT?

Apply for a Job

Now that I started feeling a little more confident with the language, was thinking with the experience I have in JavaScript & all the concepts I know and my fresh knowledge of Go I should be ready to go ahead and apply for a job.

Soon I realised the local market was quite underdeveloped, at the time there was only 1 company I knew that was hiring Go developers, and a small number of startups that had Go in production but no open positions for Go. So in the end I was left with only 1 company, really only 1 option. And it also happened to be last open position they had. Without too much thinking I went ahead and applied for the job and to my luck got the job.

Recommendations

Overall here are my recommendations in order to make your transition from JavaScript to Go as smooth as possible. Again these are the things that helped me accept Go’s way of doing thing and evolve as a Gopher.

Change your Mindset

First and foremost, Go requires anyone a change of mindset. If you’re coming to Go and expect things to be similar, it will prove you wrong in the first instance. I remember when I made the switch from PHP to JS. Things were pretty much the same in terms of expectations. The only different thing was the ecosystem and the tooling. However when I made the transition from JS to Go, I did have expectations, and most of them were ruined in the first place, because things are just done differently, treated in a unique way, the Go Way. So yet again, be ready for weirdness and the way Go handles and treats things in the ecosystem.

Focus on Concepts not on Frameworks

The second thing you’ll find common in the Go community is focusing more on Concepts and less on ready to use solutions/frameworks/libs. I’ve honestly never really cared that much how the HTTP protocol or WebSocket protocol or how TCP servers work until I implemented one myself in Go. I realised there were so many things that sit under the umbrella of frameworks & libraries. I’m not saying we should not use libraries and frameworks, use them only if it’s something really necessary and crucial to your application. Reinventing the wheel is not something Go encourages, likewise violating the liberty Go gives you is also not an option, meaning don’t use a library or framework for the stupidest and simplest case. In rest, a lot of the things are much simpler to implement yourself, not to mention, in the real world projects a lot of the times require custom solutions and implementations which make frameworks get in the way, unless you don’t know how to implement them yourself.

Get used to Magicless Code

Another thing which is common for JavaScript developers, is to write clever/shorthand and sometimes magical code which does a lot of things and it’s so easy to write it, but becomes hard to read especially when the code overall becomes clumsy and gets bigger. My recommendation is get used to magicless code, to being explicit, get used to the longer/more boring version of coding. Go is really about being simple and explicit. Which goes against those hipsters who love clever & short statements, tens of ways to accomplish something, wasting time on formatting and code style and many others. So the takeaway, is make a step back and ready yourself to write old school C like code. Simple, Explicit, No Shortcut constructs.

Resources

Make sure to check out the GitHub repo for all the presentation notes, coding examples and more. For more information about learning resources on Go aka Golang, I recommend watching my good old YouTube video about Go Resources. Also if you wanna find out my opinion about Go in 2020, make sure to check out this YouTube video.

Let’s Connect

Facebook
Twitter
Instagram
LinkedIn
Discord Community
YouTube

Support Me

I’ve recently gave up my job and I made YouTube and online content creation my full time job. If you like what I do and find any value and want to be part of my dream feel free to support me on Patreon or with a small Paypal donation.

📝 Save this story in Journal.

--

--

Steve Hook

I’m a passionate self taught Software Engineer, who also happens to be a YouTuber @SteveHook. https://www.youtube.com/c/SteveHook