[Rust] > golang ?
Things that rust fixes over golang:
- Using
.expect("error msg")on an Err lets you just choke in one line. it takes four lines of golang to do this every. single. time. or you write an ugly wart of a wrapper. (or you just handle errors) impl something for anotherthingmakes it possible to say formally and explicitly that you're implementing an interface. In golang it's always implicit (plus comments)- "shadowing" (subsequent
let foocalls) is not a thing in golang and it makes a mess. This is also nice because it's something that's common in Python to make code easier to read with the added benefit that it's explicit. Resultis formalization ofType, Error(or is itError, Type, orType, Type, Error...) and it's nicer for a few reasons.- Since it's part of the language, the so can the
foo()?operator be. - There's no awkward returning of
nil, Error()orValue, nil, orMyStruct{}, Error()
- Since it's part of the language, the so can the
- Rust has no
null,nil,NoneorNull... That statement all by itself shows you that there's a problem withnil. There's some "famous remark" aboutnilfrom the founder and inventor ofnilsuggesting that it might just be fundamentally a bad thing. Of course, there are probably programming languages that leveragenilto do some mindbendingly cool things. All symbols matter. BUT, rust shows that you can just omit the concept completely and still have a programming language. It's so ubiquitous that I never really thought of that as an option. But I do recall lots of learning hurdles withnilat their core somewhere. Getting rid of the idea completely, at least in rust, makes you think in a different way and doesn't all you to say,let var = __SHRUG. - [off-theme, but] It would be helpful if the rust book emphasized that it's the VALUE of a variable that goes out of scope, etc. Folks are so used to thinking in terms of the scope of the name or thing it's bound to ,
var. The two things are forever tied together. I have a mental cartoon where the value, that has a chain of references above it gets smashed with the memory hammer and the references above go "zap, zap, zap..." in turn, all the way up to the current variable you're looking at (It's hard to describe mental cartoons. And like a lot of things, I'm sure that's not exactly the right mental model.) - In golang, errors are values. In rust, errors are variants.
- Does golang have re-exports? It should.
- Serde is way nicer than things like
`json:foo`and marshaling and unmarshaling every nook and cranny of your types.