Hash tables in Go and advantage of self-hosted compilers

(rushter.com)

19 points | by f311a 5 days ago

4 comments

  • cabirum 1 hour ago
    > Using empty structs also hurts readability

    An empty struct is idiomatic and expected to be used in a Set type. When/if the memory optimization is reintroduced, no code change will be needed to take advantage of it.

    • tym0 51 minutes ago
      Using a bool instead of empty struct also means that there is more way to use it wrong: check the bool instead of if the key exist, set the bool incorrectly, etc...

      I would argue using bool hurts readability more.

      Even better write/use a simple library that calls things that are sets `Set`.

    • ioanaci 53 minutes ago
      I also feel like map[T]struct{} communicates its purpose way better than map[T]bool. When I see a bool I expect it to represent a bit of information, I don't see why using it as a placeholder for "nothing" would be more readable than a type that can literally store nothing.
  • nickcw 36 minutes ago
    I wonder if the compiler really needs to allocate 1 byte so you can get the address of the struct {}

    In the general case then yes, but here you can't take addresses of dictionary values (the compiler won't let you) so adding 1 byte to make a unique pointer for the struct {} shouldn't be necessary.

    Unless it is used in the implementation of the map I suppose.

    So I conjecture a bit of internal magic could fix this.

  • andunie 40 minutes ago
    So what is this article about?

    1. How to do sets in Go?

    2. What changed between Go 1.24 and 1.25?

    3. Trusting an LLM?

    4. Self-hosted compilers?

    It is not clear at all. Also there are no conclusions, it's purely a waste of time, basically the story of a guy figuring out for no reason that the way maps are implemented has changed in Go.

    And the title is about self-hosted compilers, whose "advantage" turned out to be just that the guy was able to read the code? How is that an advantage? I guess it is an advantage for him.

    The TypeScript compiler is also written in Go instead of in TypeScript. So this shouldn't be an advantage? But this guy likes to read Go, so it would also be an advantage to him.

  • Hendrikto 1 hour ago
    > Another takeaway here, as always, is not to trust everything LLMs say.

    I would go even farther and say to not trust anything they say. Always be skeptical, always verify.

    • nasretdinov 46 minutes ago
      Applies to humans as well :)
      • lenkite 38 minutes ago
        There are many humans who are far more reliable than LLM's on a 99.9999% win streak.