3 ms·
I want Go to remain simple but having written a hell of a lot of code in Go that needs to iterate over a stack whose size cannot be computed ahead of the iterat
by hnlmorg 3y ago
I want Go to remain simple but having written a hell of a lot of code in Go that needs to iterate over a stack whose size cannot be computed ahead of the iteration, I can confirm that writing such code in Go does get very complicated very fast. There are a lot of footguns to take into account:
- how do you acknowledge the end of a stack?
- how do you cancel the operation mid iteration?
- how do you make it thread safe?
- how do you make fast?
The proposal here simplifies these concerns and thus makes it easy to write and use iterators. It makes it easier to read iterators too. And it does so without adding hacks to the standard library.
This is one of those instances where the proposal might seem to add complexity but actually it simplifies the code a lot (unlike generics, for example, which complicates the syntax of your code in its effort to dedup lines of code. To be clear, I’m not being critical against generics here. Just using that as an example to show contest).