Go 1.x draft

It appears that talk of Go 2.0 is starting to get serious, and the two big crowd pleasers are better error/null checking and generics. I’m not going to attempt discussing implementations of Generics, but the Error handling is a bit annoying. I’m all for forcing developers to do a better job with setting default values, ensuring variables are declared, etc. it’s just that there’s something that feels wrong about devoting so many lines to err null checking redundantly. That, and reproducible builds are about the only things I can complain about, and the build checks have been fixed along with the dependency management. I think the Sum Types proposoal would afford a more flexible typing model similar to Crystal’s, and help reduce all the nil error check repetition to boot. Something like an extension of the structs concept:

type maybeInt nil | int

then set a default condition:

type Error[Type, Failure] oneof {
    default Type
    Failure
}

which could be used like:

/* !void is a shortcut for Error[void, error] */
func WriteFile(name string, data []byte, perm os.FileMode) !void {
    file := os.Create(name, perm)
    if !file {
        /* os.Create is func(name, perm) -> !void */
        /* !file ≡ true means this is alternative failure branch, error in this case */
        return file
    }
    for len(data) > 0 {
        /* (*os.File) Write([]byte) !int */
        written := file.Write(data)
        if !written {
            return written
        }
        data = data[written:]
    }
}

and nils could be handled the same:

type Option[Type] oneof {
    default Type
    void
}

The more I learn; the more I realize this language AND implementation were well designed. My understanding is that full OOP objects require compaction in the GC phase, thus increasing “stop the world” latency. Structs and Channels aren’t really so weird. Pointers are old fashioned, but straight forward enough. The language was designed around the GC, or in conjunction with it. Either way, it works well. As neat as Crystal is; the more advanced embedded runtime, GC, and documentation in Go makes it my primary home. Sorry Crystal, I’ll check back in 10 years.

UPDATE: and we have generics, but no Go 2.0, apparently, ever. This is good. How many languages promise never to break backwards compatiblity? Still hoping for something better with error handling