Skip to content

Conversation

mika314
Copy link
Contributor

@mika314 mika314 commented Jul 17, 2018

No description provided.

@Gathros Gathros added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Jul 17, 2018

// M will be the point on the hull
auto M = 2u;
for (auto i = 0u; i < N; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you using auto so much, it's hard to read.

Copy link
Contributor Author

@mika314 mika314 Jul 21, 2018

Choose a reason for hiding this comment

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

I follow C++ Core Guideline: ES.11: Use auto to avoid redundant repetition of type names

Copy link
Contributor

Choose a reason for hiding this comment

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

This also obfuscates a bug: if the vector is large enough so that N > size_t(0u - 1) then this turns into an infinite loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In both lines above the type of vars is clear: 2u is unsigned int, 0u is unsigned int. Core Guidelines states: Use auto to avoid redundancy. I want to use unsigned int and writing it instead of writing auto violates the guideline.

Reply to the comment about big vector bug: It is more work to make code work for cases if array size is bigger 4 billion elements and code does not look nice. I believe handling cases for arrays bigger 4 billion elements is special case and require special treatment.

Copy link
Member

Choose a reason for hiding this comment

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

I realize this discussion happened a while ago, I am catching up now. Reading the guidelines (ES.11), there are a few notable exceptions to using auto:

Exception: Avoid auto for initializer lists and in cases where you know exactly which type you want and where an initializer might require conversion.

(I added emphasis)

So it would seem that there is no problem using unsigned int or size_tbecause those are the specific types we want here. We are also not using the types incessantly and are working on code at a fundamentally different scale than the guideline was created for.

In my opinion, unsigned int M = 2 is understandable no matter what background you have auto M = 2u is not.


// M will be the point on the hull
size_t M = 2;
for (size_t i = 0; i < N; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the loop needs to start from 0 since you know points 0, 1, and 0 are co linear and the points 0,1, and 1 are too. So start from i = 2.

}
// All points are collinear
if (i == N - 1)
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a space after this line, the no brackets if statement is confusing when the lines are this close together.

@Gathros
Copy link
Contributor

Gathros commented Jan 4, 2019

Another stale pull request.

@Gathros Gathros closed this Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)

4 participants