top | item 39677855

(no title)

thisismyswamp | 2 years ago

> Learn golang

Having to "if err != nil" every single function call is a big put off - imagine having to "try catch" everything in a language like C#!

discuss

order

jen20|1 year ago

Two functions solve this (in Go):

    func Must(err error) {
        if err != nil {
            panic(err)
        }
    }

    func Panic[T any](v T, err error) T {
        if err != nil {
            panic(err)
        }
        return v
    }

AdamJacobMuller|1 year ago

I love it.

It forces me to think about how my programs can fail and what I should do when they fail.

thisismyswamp|1 year ago

Being forced to think about every possible failure state is a sure way to spend a lot of time on not creating value for the end user