3 ms·
Generics were never required, just their lack was annoying and their presence makes some things just cleaner and easier For example I deal in ops stuff so pret
by ilyt 4y ago
Generics were never required, just their lack was annoying and their presence makes some things just cleaner and easier
For example I deal in ops stuff so pretty common task is "here are desired and current set, generate list of add/delete operations to get from one state to another".
I wrote iteration of that function a bunch of times pre-generics, eventually being just copy-paste-change-types but now I can just write [1] one that compares a slice of types and returns the elements present in left or right and [2] another that can do similar difference on disparate types via conversion function.
Then there is a whole slew of map/reduce and math stuff that now can just have `Map` or `Max` function without worrying about types. Hell I can "just" write "parse all the slice elements in parallel, keeping order [3] once and never worry about it. That's also code that I wrote more than once before generics
* [1] https://github.com/XANi/goneric/blob/master/slice.go#L77 https://github.com/XANi/goneric/blob/master/slice.go#L77
* [2] https://github.com/XANi/goneric/blob/master/slice.go#L106 https://github.com/XANi/goneric/blob/master/slice.go#L106
* [3] https://github.com/XANi/goneric/blob/master/parallel.go#L15 https://github.com/XANi/goneric/blob/master/parallel.go#L15