Not to nitpick this specifically but as a generic reminder not all complaints are worthy of shifting the trajectory of a massively popular programming language.
Balancing "worthy" and "unworthy" changes is really hard both in the community and discussions like this one. I don't envy the teams that have to do it.
getNext := iterableThing.Iterator()
for next, ok := getNext(); ok; next, ok = getNext() {
...
}
Which, yeah, the range cleans it up a bit, but it's not doing quite as much work as you're implying. for i.HasNext() {
current := i.GetNext()
...
}
And just mutate the internal state of the struct. Probably throw it behind some sort of interface like: type Iterator[T any] interface { // feel free to strip out the generic
HasNext() bool // if you really only have one type
GetNext() T // you do this with
}
I think this still loses to ranging over a function, but I still think it should be compared to what you can do with the current language as opposed to what was originally posted.Go has simplicity as a design goal. Part of that simplicity is not adding all the features we can think of to the language. Just because it would provide slightly leaner syntax for a relatively small group of use cases isn't a good reason to add new language features (imho, from my 10+ years using Go and watching it evolve).
If we can implement this using current language features, but it's complex and messy to implement, then it's a great case for a new library, possibly even inclusion in the standard library. If we can't implement this at all using current language features, then maybe it's a case for a new language feature to enable this. If we can implement it relatively cleanly using current language features, then we're good and don't need to do anything. This seems like a "can implement, but not very cleanly" case, which would be a great justification for a library, but not a language feature. Again, imho.
First sentence of OP:
> This post is about why we need a coroutine package for Go
Then in the girst section after the intro:
> Later, I will argue for an optimized implementation provided directly by the runtime, but that implementation should be indistinguishable from the pure Go definition.
The point I was trying to make is that some amount of people see the benefit in removing much smaller boilerplate. And so presumably at least as many people should see the benefit of removing a larger amount of boilerplate.
I'm just talking about the benefits here. There is also a cost to expanding the language. The costs might outweigh the benefits, but it doesn't mean that the benefits don't exist.
Agreed. I think this is where the discussion will focus. I'm glad that historically the Go team have weighted the costs heavily, and hope they continue to do so.
I guess I'm in the minority but boilerplate really doesn't bother me. Going the other way gets too much "magic" and we lose the ability to fine-tune behaviour.
That is not an advantage. That's a slight convenience feature that saves maybe a few seconds every now and then, from the least time-consuming part of programming, which is typing.
The price to pay in the long run for such conveniences is high, as demonstrated in nearly every language which went down that path. Once textbooks start advising against the use of language features because they carry the risk of making the code less legible, a language design has gone down a wrong path.
> people complain about `err != nil` after all.
People complain about many things. People complain about having to wait in line. People complain about taxes. People complain about having to use 2FA. People complain about trees taking up space they would like to have as parking lots for their SUVs.
The fact that people complain about X, doesn't mean X is bad, it doesn't mean X is wrong, it doesn't mean X has to change.