4 ms·
I am not saying that the type is unusable. Plenty of high profile software has been written with C strings too yet we almost universally recognize them today as
by ATsch 6y ago
I am not saying that the type is unusable. Plenty of high profile software has been written with C strings too yet we almost universally recognize them today as a mistake.
What I'm saying is that the design flaws of net.IP, the absence of which would have benefited the whole ecosystem, fall into a familiar pattern that can be learned from. It is good to see that addressed, even if by third parties.
- zeeboo 6y agoIf you can look at any widely used API that has existed for an extended period of time and not find a single tradeoff or hindsight flaw, you aren't looking hard enough.
- ATsch 6y agoI think being able to compare or hash IP addresses is a pretty baseline feature for an IP address type. I don't think that's some kind of unpredictable hindsight or tradeoff.
- tptacek 6y agoObviously, people routinely compare and hash IP addresses in Go programs.
- ATsch 6y agoI can't tell if your're being sarcastic but it's hard to find a program that uses UDP and doesn't at some point store IP addresses in a hashmap. Many more will do the same for per-IP rate limiting. I think those are reasonable use cases for go.
- tptacek 6y agoYes, I ship several of those commercially. Like I said: obviously, people hash and compare IP addresses routinely in Go.
- benhoyt 6y agoOut of interest, how do you compare/store in a map? Do you convert to a string, or a [4]byte array (for IPv4), or some other comparable/hashable type?
- tptacek 6y agoEither strings or (in the common case where I know I'm dealing with v4) uint32's. In fact, I probably do v6 stuff with uint32s too (I'm never working with an arbitrarily large v6 prefix). I think this post is right about net.IP, though I also think the solution they've reached is Lovecraftian. But I write Rust, too, and I'd take net.IP over Sockaddr any day of the week.
- comex 6y agoI assume you mean std::net::SocketAddr? Out of curiosity, what's wrong with it?
- ATsch 6y agoI'd assume the lackluster selection of operations and how deeply nested some of the information is within the type. Definitely not the most ergonomic thing. My personal favorite is probably the python ones. Only annoyance is difficulty of creating modified objects from existing ones.
- kortilla 6y agoJust not using the built in IP type, which is stupid.
- cratermoon 6y agoBrad Fitzpatrick isn't exactly a third party. He was on the golang team until 2020 and you'll find his contributions all over the language. It wouldn't surprise me one bit if this ended up in the stdlib for Go 2.0.
- ATsch 6y agoThat's great to hear! Hope you're right.