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

Disentangled arrays in iteration: repl, serialization and shared arrays #15463

Merged
merged 1 commit into from
Mar 13, 2016

Conversation

dfdx
Copy link
Contributor

@dfdx dfdx commented Mar 11, 2016

As suggested in #15434, replaced occurrences of for i=1:length(A) by either for a in A or for i in eachindex(A) for flexibility and speed.

I omitted 2 kinds of cases:

  • for i=1:n where n comes from outside (e.g. length of array being deserialized) or is used in function logic anyway (see deserialize(s::SerializationState, t::DataType) for example);
  • loops over custom indexes (e.g. for i=2:length(A)).

Let me know if there's a way to improve these 2 cases as well.

cc: @timholy

@@ -116,16 +114,16 @@ function serialize(s::SerializationState, t::Tuple)
writetag(s.io, LONGTUPLE_TAG)
write(s.io, Int32(l))
end
for i = 1:l
serialize(s, t[i])
for e in t
Copy link
Contributor Author

Choose a reason for hiding this comment

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

e for "element" (of array).

Copy link
Contributor

Choose a reason for hiding this comment

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

this is not a great variable name, since it's also a constant 2.718...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I haven't thought about it. Would you suggest another name which is normally used for elements of a vector in Julia core? (I think I saw x a couple of times)

Since this PR is already merged, I'm going to include the change into the next one.

Copy link
Contributor

Choose a reason for hiding this comment

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

for elem in t maybe?

Copy link
Member

Choose a reason for hiding this comment

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

Isn't x more common? elem is quite verbose.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's 4 characters... this one-letter habit is harmful, variable names that describe what's going on would be a big improvement

Copy link
Member

Choose a reason for hiding this comment

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

for elem in appears only once in the code while for x in is used a lot. Once people get used to a convention, it can work even if it's not very explicit.

Anyway, this example is so short that either solution is perfectly fine IMHO.

timholy added a commit that referenced this pull request Mar 13, 2016
Disentangled arrays in iteration: repl, serialization and shared arrays
@timholy timholy merged commit 4b1f0ea into JuliaLang:master Mar 13, 2016
@timholy
Copy link
Member

timholy commented Mar 13, 2016

Many thanks!

@dfdx dfdx mentioned this pull request Mar 21, 2016
@dfdx dfdx deleted the separate_indexes_serialization branch March 21, 2016 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants