DEV Community

LinceMathew
LinceMathew

Posted on • Edited on

Learn Golang in 2025, You Won't Regret It

As I explained in previous articles, we are working on building LiveAPI, a super-convenient auto-API doc generation tool. LiveAPI's backend is in Golang, and I'm discovering the unique and cool features of Golang.

For those who don't know, Golang (Go) is a programming language designed at Google in 2009. It is syntactically similar to C.

Before working on Golang projects, I primarily used Node.js and Python web frameworks. For a beginner switching to Golang from another domain, it can be a little difficult initially, but once you practice and gain expertise, you won't leave.

My first Golang project was to convert a Python CLI tool, Glee, to Golang.

Imagcription

We found Python to be slower and maintaining a single compiled CLI binary to be very difficult, the binary sometimes not compatible with Mac OS. These and other issues forced us to switch to Golang. Here is a Reddit post on the story and the issues behind the switch.

In this article, I will explain the unique features in Golang that attracted me to it.

1. Goroutines - Lightweight Concurrency

func main() {
    go sayHello("World") // runs concurrently
    time.Sleep(1 * time.Second) 
}

func sayHello(name string) {
    fmt.Printf("Hello, %s!\n", name)
}
Enter fullscreen mode Exit fullscreen mode

Think of goroutines like tiny workers that can do tasks independently. They're much lighter than traditional threads - you can create thousands of them without a performance hit.

Imaription

2. Channels - Built-in Communication

func main() {
    messages := make(chan string)
    go func() { messages <- "ping" }()
    msg := <-messages
    fmt.Println(msg)
}
Enter fullscreen mode Exit fullscreen mode

Channels are like pipes that let goroutines communicate safely. Imagine two people passing notes through a tube - one writes and puts it in, the other takes it out.

3. Defer - Cleanup Made Simple

func readFile() {
    file, err := os.Open("test.txt")
    defer file.Close() // Will run when function exits 
}
Enter fullscreen mode Exit fullscreen mode

Defer is like setting a reminder for cleanup tasks. It's similar to writing a post-it note saying "don't forget to close the file" right when you open it.

4. Interface Implementation - Implicit Contracts

type Writer interface {
    Write([]byte) (int, error)
}

type ConsoleWriter struct{}

func (cw ConsoleWriter) Write(data []byte) (int, error) {
    return fmt.Println(string(data))
}
Enter fullscreen mode Exit fullscreen mode

Go's interfaces are satisfied implicitly - if a type has the right methods, it automatically implements the interface. It's like joining a club: you don't need to formally declare membership; if you can do what the club requires, you're automatically in.

5. Multiple Return Values - Native Error Handling

func divide(a, b float64) (float64, error) {
    if b == 0 {
        return 0, errors.New("cannot divide by zero")
    }
    return a / b, nil
}

func main() {
    result, err := divide(10, 0)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }
    fmt.Println("Result:", result)
}
Enter fullscreen mode Exit fullscreen mode

Multiple return values make error handling natural and explicit in Go. It's like getting both a package and a receipt when shopping - you can check if everything is okay before proceeding. This pattern encourages developers to handle errors properly.

These are just a few features I like in Go. There are also others, like single executable binaries, faster performance, type inference, built-in testing support, and cross-compilation.

If you're making resolutions for 2025, add Golang to your list. You won't regret it. Thanks for reading! If you want to learn Golang by contributing to an open-source project, check out glee and Lama2.

Top comments (17)

Collapse
 
dyfet profile image
David Sugar

Overall, what makes go special is simplicity. Go programs are easy to write and easy to read. This often makes them easy to debug, too.

Collapse
 
lincemathew profile image
LinceMathew

Exactly.

Collapse
 
algoorgoal profile image
Chan

Thanks for the great article.

How are go routines different from async functions in javascript? Here's what I found.

  1. Go routines are preemptible while async functions are non-preemptible.
  2. Go routines run on each thread, allowing multiple coroutines to run simultaneously.
  3. Go routines can communicate with each other easily by using channels, while async functions can't.
Collapse
 
adic_threex profile image
adic threex

I think Rust is much more easer. By your points:

  1. In go you write concurency code and you must write specific tests and compile with specific flags to detect data races. In Rust you just write concurency code, no data races possible at all.
  2. Manually descriptors closing looks like something from stone age. You dont need it in Rust.
  3. let result = divide(10, 0)?; 1 loc instead 4 loc with boilerplate.

Also no "Million dollar mistake" in Rust.

Collapse
 
meiyo profile image
Meiyo

It's not the same use case.

While I like Rust, Go is more like a Python++ in your toolbox, while Rust is C with every compile error screaming at you and slapping you with documentation links.

Although basic Rust is pretty straightforward, it takes time to get really productive, whereas Go is ready to use after a few days even less if you are already familiar with C/C++/Rust/Zig.
And complex code is easy to understand.

Whereas with Rust, you're lucky to understand complex code after a few weeks or months of daily rust.

Go is efficiency through simplicity.
Rust is reliability through strict rules which comes with complexity.

Collapse
 
adic_threex profile image
adic threex

Of course you really need language which may be learned in few days if you need to code for a few weeks or one month and then never touch programming at all. In the long run, an easier-to-use (see my previous comment) language will pay off the time you spent learning it.

About simplicity - in this case I recommend to use assembly. It's even easier then go: xor rax, rax - so clean, so compact. No abstractions. No implicit. Same as go, it's easy to read and understand just one line of code, but it doesn't make easier to read and understand big sources.

Collapse
 
manishmandal profile image
Manish Mandal

I built my first Go web server this year.

It was my best descision this year to learn Go!!

Collapse
 
_subrajeet profile image
Subrajeet Maharana

my fingers feel like waving in the air while writing Go code

Collapse
 
john_matthew_82c0880ee1c1 profile image
John Matthew

Old dog here, learned Python 15yrs ago, and always said if I learn a new language it would be GO. This article may move me forward :O

Collapse
 
alithedev profile image
ali taa

i love Golang, i learned it back in August 2024, had similar story with python apis, so decided to learn Golang and boy do i love it.

Collapse
 
nwby profile image
Sam Newby

Finally moving into Go full time in 2025

Collapse
 
rcls profile image
OssiDev

Go replaced PHP for me as the #1 language in 2024, but it really looks like I can't use it much in 2025 and I'm just sad

Collapse
 
meiyo profile image
Meiyo

Go replaced python for me.

Collapse
 
exvillager profile image
pradeep kumar

Im going to learn go in 2025

Collapse
 
lincemathew profile image
LinceMathew

Great decision. While learning, build a mini tool or product.