Golang or TypeScript?
Henrique Leite
Posted on May 1, 2024
With so many languages to choose in 2024, we get confused about which one of these infinity of options is the best for our case.
In this article, we will see some of the defining points to help you decide what programming language you should use for your backend application.
We will focus more on TypeScript and Golang, but the lessons learned here can be applied to all other languages.
What is important when choosing a language?
There are four important topics to analyze when choosing any tool:
- Security
- Performance
- Community
- Productivity
Let's talk about them and then see how Golang and TypeScript do in this competition.
Security
Back in the old days, languages used to be insecure and contain a lot of flaws, but in recent years, practically all languages are very stable and secure, so our concerns come from other things: Dependencies.
The more dependencies your project has, the more vulnerabilities it has. A great example of it is the recent XZ incident, that almost infected billions of devices.
To avoid dependencies, the standard library of the language has to have most of the things that we need to build an application.
Performance
Any tool has to be performative, no one wants to wait 10 seconds just to do a simple action. A language specifically, to be used in most cases, has to be performative by itself, without the developer having to worry too much about how to make things work.
To do this, the maintainers of the language have to have this issue in mind: Make the language performative under the hood.
Community
One person cannot maintain a tool alone, it needs lots of maintainers and people interested in the tool to create new features, fix bugs, remake things when needed, and provide support for anyone who wants to use it.
If a tool doesn't have a large community, it's doomed to failure.
Productivity
Productivity mostly depends on how familiar you are with the tools that you work with, but also depends on having support tools that allow you to increase your productivity even more.
In a language specifically, we have to consider the following points:
- Verbosity: If a language requires you to write lots of things to make "basic" things work
- Learning curve: How big is the learning curve and how long it takes for you to be effective using it
- Supplementary tools: Like IDEs with autocomplete, linters, and things in general that help you to avoid bugs and mistakes
Comparing Golang and TypeScript
Security
The latest version of Golang, 1.22, has a lot of native features and I consider it finally ready for production. It has demonstrated a huge development in recent years, being able to keep a simple language that takes the boring decisions for you and lets you focus on your business logic. You don't need to add a thousand dependencies to make your product work, you already have (almost) everything that you need in the language.
TypeScript, on the other hand, has the philosophy of leaving most of the things to external libraries and letting you do the things your way. It can be very flexible, but it's extremely insecure because most of the time you depend not only on the maintainer of the language, but the maintainer of the dependencies that you are using, and the maintainers of the dependencies that your dependencies are using.
Performance
Golang is actively trying to make everything more performative for you, under the hood, and without you having to change anything in your code. The benchmarks of Golang are one of the best among the most famous languages, faster than Java, Python, and JavaScript and becoming even faster over the years.
Performance is the last concert of TypeScript, the maintainers and the community are already used to not being the fastest language, this is not their goal.
TypeScript's performance isn't the worst of them, but definitely isn't something to brag about.
Community
The Golang community is growing, but still very small compared to older languages like Java, PHP, and JavaScript.Besides that, it is still one of the biggest communities of the "not most popular" languages.
TypeScript probably has the largest community in the entire programming language. People will find a way to run JavaScript even in a toaster if they want to (even if it means that the toaster has to have 3GB of free RAM). The TypeScript ecosystem is extremely complete, having the most famous and most used IDE written and compatible with TypeScript (VSCode), tons of thousands of libraries, examples, and documentation about how to do anything. It's easy to find developers to work with it, and easy to get from 0 to 10.
Productivity
Let's talk about the points appointed before.
Verbosity: This can be kinda of suggestive, but personally I think that both Golang and TypeScript are very very similar in this point, but Golang is a little more verbose.
Here is a code example:
Golang:
package main
import (
"fmt"
)
type Foo struct {
Bar string
}
func main() {
foo := Foo{
Bar: "bar",
}
fmt.Println(foo.Bar)
}
TypeScript:
interface Foo {
Bar: string
}
function main() {
const foo: Foo = {
Bar: "bar",
}
console.log(foo.Bar)
}
Learning curve: I consider learning Go a little easier than learning TypeScript. On one side, you have a lot more types to learn, but on the other hand, you don't have to deal with a transpiler to convert TypeScript to JavaScript and then finally run it, which can be very confusing for beginners.
Supplementary tools: Golang has most of the dev tools necessary tools built-in, like a testing library and its own linter/compiler. VSCode also has an amazing extension to help you write your code.
Conclusion
Golang can be missing some features (like enums) but has a lot more advantages than TypeScript.
Posted on May 1, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.