News for hackers. Stuff that matters.
Re:Why I Don't Like Golang (2016) by sam0x17 on Tuesday June 14, 2022 @02:24AM (#31735382)
Another big area that is lacking is Go makes it so hard if you want to use something other than a primitive as a hash key (Rust is guilty of this as well, mind you). This is something that should come out of the box in any modern language in my opinion.
Re:Why I Don't Like Golang (2016) by the_duke on Tuesday June 14, 2022 @03:37AM (#31735878)
> Rust is guilty of this as well, mind you

#[derive(Hash)] struct X{ ... }

Seems easy enough to me? The only annoyance is if a third party type didn't implement Hash, but you can solve that with a manual implementation instead of a derive.

Re:Why I Don't Like Golang (2016) by stonewareslord on Tuesday June 14, 2022 @12:31PM (#31741870)
> you can solve that with a manual implementation instead of a derive.

How? I thought the orphan rule said you can only define trait implantations at struct definition or trait definition

Re:Why I Don't Like Golang (2016) by the_duke on Tuesday June 14, 2022 @06:25PM (#31746798)
Yeah, for foreign types you will have to use the "newtype" pattern, aka: define your own wrapper struct.
Re:Why I Don't Like Golang (2016) by sam0x17 on Tuesday June 14, 2022 @12:39PM (#31742012)
ding ding ding! This has been a problem for me a number of times. The quick workaround is pray that it implements Debug and in a reasonable way and take the hash of the string instead
Re:Why I Don't Like Golang (2016) by genthor on Tuesday June 14, 2022 @03:49AM (#31735955)
Maybe I misunderstood you, but you can use structs as keys of a map.
Re:Why I Don't Like Golang (2016) by sam0x17 on Tuesday June 14, 2022 @12:43PM (#31742076)
not if it doesn't have equailty defined. Then you have to define it. Oh, and it's an AST node someone at X company wrote and there are 100+ node types. Have fun!

In crystal there is a reasonable data-based default hash implementation that you can just rely on.

Re:Why I Don't Like Golang (2016) by yencabulator on Tuesday June 14, 2022 @11:20AM (#31740781)
The map key type can be anything for which `==` is defined. This includes structs for which `==` is defined for every field. Composite keys etc are trivial.

https://go.dev/ref/spec#Map_types