this post was submitted on 10 Feb 2024
1 points (54.5% liked)

Golang

1645 readers
1 users here now

This is a community dedicated to the go programming language.

Useful Links:

Rules:

founded 1 year ago
MODERATORS
 

I've seen that a new "range-over-func" experiment is available with Go 1.22. In this article, I took a closer look and evaluated the feature for myself.

you are viewing a single comment's thread
view the rest of the comments
[–] codesoap@feddit.de -1 points 7 months ago (1 children)

Maybe I'm a little tired. I've argued a lot about this on reddit as well and have become a bit frustrated with people telling me I'm missing things, without being able to actually provide any convincing real world examples. It's not my goal to cause drama or offend anyone. Sorry, if I came across a little cranky.

Thanks for linking some resources! I'll take a look and see if I can find some compelling arguments there.

[–] icb4dc0de@programming.dev 2 points 7 months ago* (last edited 7 months ago)

I can imagine how…exhausting these discussions were 😅

Apart from the more synthetic examples and the obvious things like iterating custom containers - I understand your argument that this is not a every day use case but there are certainly some use cases - there are things like:

  • iterating a bufio.Scanner
  • iterating SQL results
  • streaming chunked HTTP results

That can benefit from the range-over-func approach.

Furthermore there’s another “class” of tasks that are quite a good fit: generators 😍 Think of an infinite slice of random numbers or Fibonacci numbers or prime numbers…all of this can be expressed as a function you can iterate and “just stop” as soon as you have enough.

Probably this gives you an idea what else the whole experiment is good for 😉

Edit: there’s for instance a Python library letting you generate the holidays of a state for the next 1000 years based on some algorithm without having the data pre-calculated/stored anywhere but you can iterate/filter/… whatever you want