by symlock · 8y ago · 0 comments
That aside, I don't think I've ever really been bothered by the lack of generics for actual work code.
Do you have any recommendations for how to write this code without generics, without sacrificing performance, and without hundreds of lines of duplicated code?
The constructor might be harder to abstract as a single thing since there are variations for each image type... but that's the gist of how I'd tackle it with all of my 10 minutes of experience with your code :-) If this approach is workable, it should end up being clean and testable IMO.
I could understand not missing this if you're coming from a dynamically typed environment, but understand that many people aren't.
void do_stuff(Integer[] integers) {
....
}
do_stuff(new String[]{"1", "2", "3"})
Compiler: whoops, you passed an array of strings when the API called for an array of integers. x := reduce(func(a, b int)int{return a*b}, []int[1,2,3])
y := reduce(func(a, b string)string{return a+b}, []string{"a", "b", "c"})
Rob Pike implemented "ivy", an array programming language, in Go but producing something like an array programming package that can be used from Go (sort of like NumPy for Pyhton) can be very messy to use or implement (even with the use of reflect package).Or, for another example, you can't write a generic LinkedHashMap, which is a weird data structure that allows you to write constant time LRU caches, and which I presume Go doesn't have.