Skip to content
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

replace some occurrences of iteration over 1:length with more idiomatic structures (mostly eachindex) #55137

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

LilithHafner
Copy link
Member

Base should be a model for the ecosystem, and eachindex(x) is better than 1:length(x) in almost all cases. I've updated many, but certainly not all examples. This is mostly a NFC, but also fixes #55136.

@jishnub
Copy link
Contributor

jishnub commented Jul 16, 2024

Should probably be backported?

Copy link
Contributor

@tecosaur tecosaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a pretty straightforward improvement, CI failures appear unrelated

@tecosaur tecosaur added iteration Involves iteration or the iteration protocol bugfix This change fixes an existing bug labels Jul 16, 2024
@jishnub jishnub added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 labels Jul 16, 2024
@LilithHafner LilithHafner merged commit 0945b9d into master Jul 16, 2024
11 checks passed
@LilithHafner LilithHafner deleted the lh/eachindex branch July 16, 2024 11:35
@@ -978,7 +978,7 @@ end

Return an array with element type `T` (default `Int`) of the digits of `n` in the given
base, optionally padded with zeros to a specified size. More significant digits are at
higher indices, such that `n == sum(digits[k]*base^(k-1) for k=1:length(digits))`.
higher indices, such that `n == sum(digits[k]*base^(k-1) for k in eachindex(digits))`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was clearer before since one is taking an exponential of k. The genericness of iterating indices just takes away from the point being made.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a reasonable position. OTOH, with 1:length, you have to worry about bounds errors which also distracts from the point. Personally, I think it's similar either way.

@KristofferC KristofferC mentioned this pull request Jul 23, 2024
42 tasks
@KristofferC KristofferC removed backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 labels Jul 23, 2024
@IanButterworth IanButterworth added the backport 1.11 Change should be backported to release-1.11 label Nov 6, 2024
@IanButterworth
Copy link
Member

Not clear why this was removed from backport. Adding it back to 1.11 at least as it makes other things easier to backport.

IanButterworth pushed a commit to IanButterworth/julia that referenced this pull request Nov 6, 2024
…ic structures (mostly eachindex) (JuliaLang#55137)

Base should be a model for the ecosystem, and `eachindex(x)` is better
than `1:length(x)` in almost all cases. I've updated many, but certainly
not all examples. This is mostly a NFC, but also fixes JuliaLang#55136.

(cherry picked from commit 0945b9d)
KristofferC pushed a commit that referenced this pull request Nov 11, 2024
…ic structures (mostly eachindex) (#55137)

Base should be a model for the ecosystem, and `eachindex(x)` is better
than `1:length(x)` in almost all cases. I've updated many, but certainly
not all examples. This is mostly a NFC, but also fixes #55136.

(cherry picked from commit 0945b9d)
@KristofferC KristofferC removed the backport 1.11 Change should be backported to release-1.11 label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug iteration Involves iteration or the iteration protocol
Projects
None yet
Development

Successfully merging this pull request may close these issues.

permute_dims fails in edge case because of use if 1:length
5 participants