2 ms·
No expectations whatsoever. You can use pointer or a values. It's up to you.
by konart 3y ago
No expectations whatsoever. You can use pointer or a values. It's up to you.
- scottlamb 3y agoThat's silly. Language constructs and APIs are always made with expectations for how they're used, stated or not. You can write code that compiles without understanding and matching those expectations but it probably won't be good code. I'm asking because I think if it were expected that folks used large/expensive-to-copy map values, this construct would return a reference instead of copying. In Rust for example, the std library's "normal" [1] iterators return references. [1] not those returned by into_* or drain.
- deleted 3y ago[deleted]
- morelisp 3y agoReturning references to storage within the map would be a substantial footgun without borrowing.
- scottlamb 3y agoThanks, useful reply. I just realized that myself: https://news.ycombinator.com/item?id=37576558 https://news.ycombinator.com/item?id=37576558 The peer comments along the lines of "the expecation is it does what it does" are not so helpful from a perspective of learning to write code that is in harmony with the language philosophy.
- konart 3y agoHere an example: https://go.dev/play/p/He0lBEYZJ03 https://go.dev/play/p/He0lBEYZJ03 Value is always a copy. Either a copy of a struct (in case of map[T]struct{}) or a copy of a pointer (in case of map[T]*struct{})