8 ms·
Go has a much easier time of it for including some batteries, because it’s a simpler language. Take HTTP, for example: the decision of the data type to use for
by chrismorgan 5y ago
Go has a much easier time of it for including some batteries, because it’s a simpler language.
Take HTTP, for example: the decision of the data type to use for storing headers is easy, because there are really only four possibilities, two binary decisions to make: ① do you use string or []byte; and ② do you use map[T][]T, or join values with commas and special-case that pesky Set-Cookie header somewhere and use map[T]T? And so map[string][]string was fairly obviously the best choice from the start, and I think still is—in Go.
Meanwhile, in Rust, are you going to go Vec<(Vec<u8>, Vec<u8>)>, can you get away with HashMap<String, Vec<String>>, do you store a central buffer and work with slices for fewer allocations, or do you say “no, that’s stupid, headers aren’t strings, they’re just serialised as strings” and go all fancy typey in one of a variety of ways, some the most efficient of which depended on GATs which are only recently stable?
Go could have net/http from the start. I don’t know if there’s something better now (I don’t use Go), but I expect that the better would still be very similar in API.
If Rust had had a std::net::http at 1.0, it would certainly have been deprecated by now. Probably even over four years ago.
(Disclosure: I wrote the first de facto standard HTTP library in Rust, rust-http, back in 2013. Then in 2014, realising its design was a dead end, I went to write a new one from scratch, Teepee, but never finished it because of decision paralysis, others took up much of my work and finished the concept off in Hyper, and I’m glad I got out of the critical path and I’m glad they took it up.)
- xigoi 5y agoThen you go “Can you multiply a duration with a number? No, that wôuld be stupid. Can you multiply a duration with a duration? Heck yeah!” Such an intelligent type system.
- chrismorgan 5y agoHmm? std::time::Duration doesn’t implement Mul<Duration>, and does implement Mul<u32>, and has methods mul_f32 and mul_f64. So you can multiply a duration with a number; and you can’t multiply a duration with a duration because that would be stupid.
- xigoi 5y agoI was talking about Go.
- chrismorgan 5y agoOh wow, that is nasty.