Thinking about this some more, I am not sure it is viable. Important operations, like “putIfAbsent” would not be possible with the current Go map syntax.
That being said, many of the Java collections interfaces declare “optional” methods, and I guess that could be used here. It would be easy to implement “putIfAbsent” with the standard map, and the standard map does have some methods - like len() - so maybe it’s possible. If the map implementation did not implement a method it would be a runtime panic(). > On Jan 1, 2021, at 2:40 PM, robert engels <reng...@ix.netcom.com> wrote: > > I was thinking more of an internal api - maybe stdlib authors only - writing > code similar to map.go to create an alternate map type, and allow selecting > of that map type in the make() call. It would be more difficult to write the > collections implementation, and the methods available are fixed to the > current Go map syntax - but I think it would address a large segment of the > need for generics without adding generics. I think many of the other use > cases can be dealt with using interfaces - maybe having many of them > predeclared in the stdlib for consistency. > > So then the issue becomes a purely technical one - how to write these > implementations and have them integrated into the build. > >> On Jan 1, 2021, at 2:18 PM, Ian Lance Taylor <i...@golang.org> wrote: >> >> On Fri, Jan 1, 2021 at 10:25 AM robert engels <reng...@ix.netcom.com> wrote: >>> >>> To Ian’s point, what if I could declare a map that had the semantics of a >>> concurrent hash map without adding generics? I think something like this >>> gives Go a leg up, rather than just making it “closer to Java” as some >>> complain. Go’s “other containers (i.e. sync.Map)” are very similar to Java >>> pre-generics - and better software engineers wrote wrappers then instead of >>> dealing with interface{}/Object everywhere. >> >> It's an interesting idea, and I've thought about it a lot. But as far >> as I can tell, it's a contradiction in terms. The goal for >> compile-time-type-safe containers is to be able to write the >> implementation of a data structure such that the implementation is >> independent of the types stored in that data structure. And that is >> the definition of generics: "Generic programming enables the >> representation of algorithms and data structures in a generic form, >> with concrete elements of the code (such as types) factored out." We >> can talk a lot about how to get there, but once we are there, no >> matter what it looks like in the end, we will have implemented >> generics. >> >> Ian >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXSganwnS-uKZkv8HcvHNPZd%3DMsVidwmVWAD5_OQ4TU0g%40mail.gmail.com. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/B3A67E98-519D-493F-99F4-5FCC1ADBC9D9%40ix.netcom.com.