Live data from Hacker News

Go is not an easy language (2021)

arp242.net

1–10 of 37 posts

Re: Go is not an easy language (2021)

#3
I was writing a more involved change in golang for the first time and was surprised to find golang didn't support higher order functions like map and filter. It's not a big deal to have to implement them in a custom for loop but for a language that sells on simplicity, I was surprised to find these missing. I guess I have a different idea of simple than the golang team.

Re: Go is not an easy language (2021)

#5

I was writing a more involved change in golang for the first time and was surprised to find golang didn't support higher order functions like map and filter. It's not a big deal to have to implement them in a custom for loop but for a language that sells on simplicity, I was surprised to find these missing. I guess I have a different idea of simple than the golang team.

This was my impression coming to Go as well (from Python and PHP) but since then I've changed my mind and somehow find it easier to unpack a small for loop than a HOF with a lambda function argument.

When you introduce lambdas/closures/HOF you immediately have to think about scope rules, non-local references etc.

Meanwhile, a foor loop is just a for loop.

Re: Go is not an easy language (2021)

#6
post #5

I was writing a more involved change in golang for the first time and was surprised to find golang didn't support higher order functions like map and filter. It's not a big deal to have to implement them in a custom for loop but for a language that sells on simplicity, I was surprised to find these missing. I guess I have a different idea of simple than the golang team.

This was my impression coming to Go as well (from Python and PHP) but since then I've changed my mind and somehow find it easier to unpack a small for loop than a HOF with a lambda function argument. When you introduce lambdas/closures/HOF you immediately have to think about scope rules, non-local references etc. Meanwhile, a foor loop is just a for loop.

Until you spawn a goroutine from a loop and suddenly you have to think about scope rules, nonlocal references, etc...

(It doesn't bother me, just noting the same complexities do come up pretty often).

Re: Go is not an easy language (2021)

#7

I was writing a more involved change in golang for the first time and was surprised to find golang didn't support higher order functions like map and filter. It's not a big deal to have to implement them in a custom for loop but for a language that sells on simplicity, I was surprised to find these missing. I guess I have a different idea of simple than the golang team.

This wasn't feasable without generics, and now with generics they're already adding some convenience functions to the stdlib, like in the slices package.

For map, reduce etc it's not in the stdlib yet, but you can use https://pkg.go.dev/github.com/samber/lo

Re: Go is not an easy language (2021)

#8

I was writing a more involved change in golang for the first time and was surprised to find golang didn't support higher order functions like map and filter. It's not a big deal to have to implement them in a custom for loop but for a language that sells on simplicity, I was surprised to find these missing. I guess I have a different idea of simple than the golang team.

[deleted]

Re: Go is not an easy language (2021)

#9

I was writing a more involved change in golang for the first time and was surprised to find golang didn't support higher order functions like map and filter. It's not a big deal to have to implement them in a custom for loop but for a language that sells on simplicity, I was surprised to find these missing. I guess I have a different idea of simple than the golang team.

Higher order functions are not easy to grasp for beginners, but once you do, they simplify reasoning about the code a lot.

Go is targeted at system programming, which is a domain in which you need pretty advanced developers. But the language feature seems to favor use by absolute programming beginners. It's a trade-off which seems somehow inverted.

Re: Go is not an easy language (2021)

#10
post #5

I was writing a more involved change in golang for the first time and was surprised to find golang didn't support higher order functions like map and filter. It's not a big deal to have to implement them in a custom for loop but for a language that sells on simplicity, I was surprised to find these missing. I guess I have a different idea of simple than the golang team.

This was my impression coming to Go as well (from Python and PHP) but since then I've changed my mind and somehow find it easier to unpack a small for loop than a HOF with a lambda function argument. When you introduce lambdas/closures/HOF you immediately have to think about scope rules, non-local references etc. Meanwhile, a foor loop is just a for loop.

Map and filter name what they’re doing, while loops look too much alike.

I haven’t checked whether any Go compiler does list fusion between producers and consumers (to avoid leaving a slice in the heap after reading it just once).

Post reply on HN