-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Better for loops, part 3/N #3556
Better for loops, part 3/N #3556
Conversation
I feel like a lot of changes in this PR decreases the readability of the code. I can't tell what the types are by looking at the code anymore. For example,
Can't tell whether n_neighbours is So what are the main benefits of making these changes? |
Sure. Please point them out and I'll remove them. That wasn't my intent.
I'll use Just to present my side: I'm of the opinion that despite C++ being a strongly typed language, most of the times, we shouldn't need to care about the return type. The language ensures that there's no overloading on return type. Code is a communication with the future readers*. Presence of the type implies that the person needed the type to be that, and couldn't trust the compiler; absence implies the compiler can choose the best type for this situation. Most of the times, we just want to work with the return type, so auto is a good fit. Maybe working with Haskell (and Python and Erlang) has made me not like overt types. *: This actually goes both ways. My code needs to be readable by the maintainers too, and I need to adapt to the community. |
@@ -73,7 +73,7 @@ pcl::FPFHEstimation<PointInT, PointNT, PointOutT>::computePointSPFHSignature ( | |||
float hist_incr = 100.0f / static_cast<float>(indices.size () - 1); | |||
|
|||
// Iterate over all the points in the neighborhood | |||
for (const int &index : indices) | |||
for (const auto &index : indices) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think auto here decreases readability for the same reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto
here enables changing the indices to std::size_t
or std::ptrdiff_t
later. That change will be quite difficult without minor changes like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kunaltyagi That's a valid point. But I would argue that the change won't be that difficult with vim + regular expression search and replace. So I would rather prefer keeping good readability.
Personally I am not a big fan of
this is way too long so if we do the below,
it shortens the code and I still know what type I think using |
It's an opinion, and a contentious one. I've modified the patch to remove that. I'll check other patches too 😄 |
a4aae08
to
24509fa
Compare
108 is a flaky test. Passes based on a timeout. Reported earlier too. |
I find myself on the |
No description provided.