Soppo - Go, with the features it's missing

58 points by wezm


nemin

I was skeptical when clicking on this, but color me impressed, this all seems remarkably reasonable.

My only nitpicks being string interpolation being universal instead of opt-in, which I think could be a source of annoyance, and I'm not sure how you can have both seamless interop and nil safety. Also I feel like error handling is still not ergonomic enough. The docs give this example:

// Custom handling
port := parsePort(config) ? {
	return fmt.Errorf("parse failed")
}

This feels barely shorter than the usual if err != nil dance, so to me it feels completely superfluous. An actually useful solution imo would be to have a shorthand for return fmt.Errorf("{message}: %w", err).

Say port := parsePort(config) ?? "port parsing failed" would extend to:

port, err := parsePort(config)
if err != nil {
        return fmt.Errorf("port parsing failed: %w", err)
}

And port := parsePort(config) ?? ("port parsing on %q failed", config.IPAddress) would turn to:

port, err := parsePort(config)
if err != nil {
        return fmt.Errorf("port parsing on %q failed: %w", config.IPAddress, err)
}

(Obviously in cases where (T, error) is the return value, it'd unfold into return ([default value of T], fmt.Errorf(...)))


Other than these, yes, yes, and yes. Go is so close to being a perfect "a hammer is a hammer" language, but it still has some sharp corners, that it feels like it really shouldn't have anymore.

It annoys me so much that const is such a constrained modifier in Go. I'd love if I could mark almost everything const and only do var (or :=) when I know I'll actually modify things. It may be a Rustism, but one I genuinely believe to be good for everyone involved (you're more confident about correctness, the compiler can optimize more freely, the next reader will be certain no monkey business happens dozens of lines down, etc.)

Better matching functionality would clear away the weird "check on variable X, but then variable Y becomes actually that type" syntax. And with nil checks, the compiler can take off some needless mental bookkeeping from the programmer.