4 ms·
>B) does this count as generics? I think "generic programming" is more about generic algorithms than it is about data structures. Because without generic funct
by ainar-g 8y ago
>B) does this count as generics?
I think "generic programming" is more about generic algorithms than it is about data structures. Because without generic functions, generic data structures are less useful.
Can you create a new map type in Go? Yes. Can you create a function that works on any map? Only with reflection, which you should consider your last measure.
- jimmy1 8y ago> Can you create a function that works on any map? Only with reflection Most experienced go developers at this point would template the function and generate it for any type they might need it for, before they reach for reflection.
- ainar-g 8y agoDepends on the environment, I guess. I've been programming Go professionally for over 3 years, and I've never used such "templates" for generic types. As I've said in another thread, I've had a need for sum types much more often than a need for generics.
- paulddraper 8y ago> template the function and generate it for any type they might need it for How? This is C++ generics. I thought Go didn't have generics?
- ainar-g 8y agoI think they meant literal generation of files based on templates. Basically sed 's/T/int/g' file@T.go > file@int.go Some people do that, I guess.
- pjmlp 8y agoThey do https://www.reddit.com/r/rust/comments/5penft/parallelizing_enjarify_in_go_and_rust/dcsgk7n/ https://www.reddit.com/r/rust/comments/5penft/parallelizing_...
- jimmy1 8y agolittle more 'go' than that, using go generate and the template package. There are also other generators that can generate a 'Stringer' for any type, etc.