4 ms·
Spin showed up on HN recently as an interesting example of Go vs Rust hello world: (Rust) https://spin.fermyon.dev/ https://spin.fermyon.dev/ Vs (Go) https://s
by esprehn 5y ago
Spin showed up on HN recently as an interesting example of Go vs Rust hello world:
(Rust) https://spin.fermyon.dev/ https://spin.fermyon.dev/
Vs
(Go) https://spin.fermyon.dev/go-components/ https://spin.fermyon.dev/go-components/
The Go example seems a lot simpler without the Ok/Some/.into()/? That are unrelated to sending hello world. There's also no macro magic to understand.
In general my observation is the ancillary stuff (and in general number of things you need to understand) is greater in rust. That's paired of course with greater expressivity.
- mustache_kimono 5y agoI've never really understood why the lack of Result/Option types are somehow spun as a good thing. Other things about Rust can be complex and can require some diligence to learn, but Result/Option types over golang's way of handling the same thing? Seriously? That's the argument for golang?
- doctor_eval 5y agoI don’t think that’s the argument for Go. It’s a decision that Go developers accept as a trade off for other things that are nice about Go. I haven’t learned Rust yet, maybe one day I will, but it looks a lot more complex to me, and it’s hard to see how the extra complexity will help me write better web servers. It’s OK for Rust and Go to solve different problems with different trade offs.
- mustache_kimono 5y agoTotally agree with you. And I totally get why some people would prefer golang. Don't like how some constantly feel the need to compare golang and Rust (two very different languages), and how some feel like the comparison is always favorable to golang. Like you said -- there are tradeoffs. golang folks seems to have a problem acknowledging that Rust made a few good decisions too, like Result and Option types, mostly because they haven't ever used them. It's hard for me to imagine someone using them (golang has generics now, so get ready!) and not liking them. Especially golang. It's just so weird to hear that someone describe one of the warts of golang as actually beautiful, instead of, as you say, a tradeoff. Rust has a certain amount of friction. It takes some work to learn well enough to feel productive. I don't know if it's all that bad. But, yes, it is a clear tradeoff for people who mostly work in domains in which golang works well enough to really pretty great, like writing web servers.
- doctor_eval 5y agoOk. Ironically, your comment came across to me as a comparison, but I guess we were both reacting to the same sense, that it’s not a race. In fact, I’d really love to learn Rust - GC always feels like a nasty hack to me - but my current use case and time constraints mean that I won’t get to use what I learn, and will quickly forget, so it’s just a waste of time for me at the moment.
- tialaramex 5y agoHmm. I think you intended to link: https://spin.fermyon.dev/rust-components/ https://spin.fermyon.dev/rust-components/ What's nice about "Hello, World!" is that it's a canonical example where we know exactly what it's supposed to do, in contrast these pages are showing off features of writing Spin components in different languages so that makes it much harder to compare. In each case they're using a popular existing HTTP library for its familiar APIs, but the chosen APIs are of course not the same in Go and Rust. The Go API (from net/http) follows typical Go style, it assumes success, and doesn't worry too much about errors. If you write any data to the ResponseWriter (which this example does), you get a 200 OK response anyway. You don't need to set types, it'll guess, likewise you don't need to care about binary data, it'll guess. This is cheerful and will mostly work, if it doesn't work you can probably learn what you did wrong and try again. The Rust API (from the http crate) follows more typical Rust style. You must say whether you succeeded with Ok, so that failures can be handled appropriately. You can choose whether your response has a body we do have a body here so hence we need to write Some. Finally HTTP bodies are binary data, and we'd like to return a string, so we use the Into trait to get the UTF-8 encoded text out of the string as bytes, this is how Rust stores strings anyway so it will be trivial. The Rust code sets header "foo" to "bar" for some reason, and also prints (to console) all the information about the request, presumably because that's trivial to do in Rust, the Go code doesn't do either of these things. I agree that there certainly is a lot more Rust, it's just that I'd say it's beautiful rather than ugly, a matter of opinion.
- esprehn 5y agoThe link was the correct one, scroll down and you'll see a simple hello world example that matches what the golang one does.
- tialaramex 5y agoOn second glance I think that Rust example is needlessly verbose, which is fine if that's what you meant, but the Go doesn't do that.