3 ms·
Decided to try Golang this year. Compared to Python and Scala it is way more verbose for simple challenges as this. I almost feel like I am back in the early
by sireat 5y ago
Decided to try Golang this year.
Compared to Python and Scala it is way more verbose for simple challenges as this.
I almost feel like I am back in the early 1990s of writing C.
I miss zip, sum, map and list comprehensions...
- WoodenChair 5y agoGo has first-class functions and now has generics. So, you can definitely implement zip, sum, map, filter, reduce, etc. The fact that they're not included in the standard library I think has more to do with the opinionated creators of the language than any limitation[0]. You can absolutely implement them yourself (and a couple of these are pretty trivial to implement) in a library as an aid. I've done that in the past. I miss them too. In fact at the link below you'll see one of the creators explicitly say they're easy to implement (and his own implementation pre-generics) but he doesn't think you should use them (Rob Pike). "Having written it a couple of years ago, I haven't had occasion to use it once. Instead, I just use "for" loops. You shouldn't use it either." 0: https://github.com/robpike/filter https://github.com/robpike/filter
- Jtsummers 5y agoLooking at it, I wouldn't want to use it either. It seems to add a lot of overhead. In the first 15 lines of the function it's mostly implementing type checking at runtime using reflection. Every single time this is used it would redo that type checking. In most statically typed functional languages that would just be done once at compile time and the implementation would be the equivalent of the last 7 lines or so. I imagine with generics it could be greatly simplified, but I don't know Go well enough to venture how it would be done. Though if it weren't faster than that version I'd be shocked. For clarity, I was looking at reduce.go, all the others seem to do similar tricks with reflection that would also add overhead that generics should eliminate.
- WoodenChair 5y agoRight, using generics all of the reflection should be unnecessary and the implementation should be much simpler and more performant.