logoalt Hacker News

wannabe44today at 5:41 PM4 repliesview on HN

Oh yeah totally agree. I don't understand why someone would want to write `slices.Contains(s, needle)` when you can write this beautiful poem like a Shakespeare in VSCode:

    found := false
    for _, v := range s {
        if v == needle {
            found = true
            break
        }
    }
Oh and I totally want to build a stack trace manually. It's like doing cardio to me.

    if err != nil {
       return fmt.Errorf("my function name but in spaces: %w", err);
    }
This is very elegant by the way, so that we need errors.Is now, which has to dynamically check if the error implements Unwrap() error or Unwrap() []error. Because having any language facilities for error handling is harmful.

Replies

b7e7d855b448today at 6:33 PM

I don't say it's perfect, but right in this moment I feel most comfortable with go and I don't mind jumping through a few hoops or writing things multiple times

show 1 reply
bayindirhtoday at 9:17 PM

> Because having any language facilities for error handling is harmful.

No, making error handling verbose mandatory is meant to make developers do mental cardio and be mindful of what they are doing.

You can either keep developers mindful or punish them after they make a mistake by shouting at them and make them waste their time during re-compiling.

P.S.: Yes, I love Go's error handling mechanics, which makes handling errors mandatory, not optional, and if you ignore the error, this is a deliberate choice and the burden is on the developer. Go does the former, Rust does the latter.

show 1 reply
msietoday at 6:05 PM

You forgot to put /s after your post.

logicchainstoday at 5:56 PM

Your handwritten one has a major performance bug:

    found := false
    for _, v := range s {
        if v == needle {
            found = true
            break
        }
    }
Do you see it? It copies the v into a local variable, which could be tremendously wasteful if it's a large struct. You should instead be taking a pointer to s[i] and comparing the value there with `needle`.

If you'd used `slices.Contains(s, needle)`, on the other hand, it could have such a performance bug in it and you'd never know.

show 4 replies