-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: math: add Iter #44394
Comments
Might have some overlap with #43557 |
Do you have any data or examples to back this up? They are perhaps a bit verbose and easy to mistype if you're not used to the idiom, but in practice I can't remember the last time I saw a bug caused by them directly. |
This seems hard to get good numbers on, and all my anecdotes are proprietary. It is mostly off by one errors, and it is not a deluge, but because |
This is a language change by another name. |
This proposal has been added to the active column of the proposals project |
I think this is a cute API, but (1) it seems inappropriate for package math (every existing function in package math has to do with floating point operations), and (2) there's no reason it needs to be in the standard library anyway (e.g., it doesn't expose any new types that separate modules need to agree on for interoperability). |
Also there is a lib for that, no need to change the language 😉 https://github.com/bradfitz/iter |
Based on the discussion above, this proposal seems like a likely decline. |
I agree that the three-part Personally, I hope that after generics land we may get a more holistic “iterator” API, and then we can provide a standard iterator for arithmetic sequences — this seems like a cleaner fit for a future |
Regarding iterator #43557 |
No change in consensus, so declined. |
background
I have found that over a sufficiently large sample, c style for loops,
for v := 0; v < 25; v++ {}
, can introduce iterator and comparator bugs. As such I preferfor range [N]struct{}{} {}
, orfor range make([]struct{}, N) {}
forN
that is notconst
, as suggested in #36308 (comment). Unfortunately may people have found this syntax confusing, so I have taken to usingiter.N
, which uses themake
form above, cleans up the syntax, and has a godoc explaining what is going on. But @bradfitz "encourage[s] [people] not to depend on this" and calls it out as "not ideomatic", despite the comment above. As such, I would like to have a discussion about including this to the stdlib.impl
alternatives
nop
We can always do nothing, but I think this syntax is reasonable and improves safety and readability of trivial loops. Clearly we still need the c for syntax for non-trivial cases.
inline
If desired, this could be implemented in a way that the compiler more fully inlines it, especially in cases where the index is unused.
names
I am happy to have this be named something different or live in a different package.
math
seemed like a decent fit, since there is nonumbers
,ints
, oriter
package, and I did not want the stutter offor range math.Range(10) {}
, but it would clearly indicate where it was intended to be used.The text was updated successfully, but these errors were encountered: