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

Apply clang-format to simulation module #3356

Merged
merged 2 commits into from
Sep 25, 2019

Conversation

taketwo
Copy link
Member

@taketwo taketwo commented Sep 20, 2019

No description provided.

@jasjuang
Copy link
Contributor

I don't think by default clang-format will automatically make something like

void doSim(Eigen::Isometry3d pose_in);

into

void 
doSim(Eigen::Isometry3d pose_in);

unless specified in the config file, please correct me if I am wrong. IMO this makes the code less readable and it creates more lines for no reason. I am curious to know what's the main reason behind this decision.

Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

A few indentation related issue (and some unrelated ones that I pointed out coz I saw them).

@jasjuang There was a discussion regarding the code-style where the content of .clang-format was decided. #3190

simulation/src/model.cpp Outdated Show resolved Hide resolved
simulation/src/range_likelihood.cpp Outdated Show resolved Hide resolved
0.00000008f, 0.00000007f, 0.00000006f, 0.00000006f, 0.00000005f,
0.00000004f, 0.00000004f, 0.00000003f, 0.00000003f, 0.00000003f,
0.00000002f};
float normal_sigma0x5_normal1x0_range0to3_step0x01[] = {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe update to use constexpr function returning to a std::array. Too many magic numbers. make them go away

{
if (a%2 || b%2) return level;
while (true) {
if (a % 2 || b % 2)
Copy link
Member

Choose a reason for hiding this comment

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

Plus the function (by documentation) smells fishy. For example: EXPECT_TRUE(max_level(1025, 4095), 10) fails.

So many questions...

Is it a cleanly divisible test? Are a and b non-negative? Are they powers of 2?

This function is only used twice (L163, L865) so it might be depending on special behavior since there's no test for this

Copy link
Member Author

Choose a reason for hiding this comment

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

🤷‍♂️ 😆

simulation/tools/sim_test_simple.cpp Outdated Show resolved Hide resolved
write_file_ = false;
}
}

// Handle normal keys
void
on_keyboard (unsigned char key, int, int)
on_keyboard(unsigned char key, int, int)
{
double speed = 0.1;

if (key == 27)
Copy link
Member

Choose a reason for hiding this comment

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

Will switch-case make better sense than if-else ladder? Or even a std::tolower to reduce the code density

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. But I wouldn't mix formatting and refactoring. A follow-up PR is welcome ;)

@taketwo
Copy link
Member Author

taketwo commented Sep 21, 2019

@jasjuang You are right, we have this rule explicitly in the config file.

IMO this makes the code less readable

I have the opposite opinion. In a template-heavy library like PCL, return types are often long. The method names, when prefixed with class and namespace names (as it usually happens in HPP files), are also long. Therefore, I believe it's easier to visually parse function declarations when the type is put on a separate line.

and it creates more lines for no reason

Here I also see a benefit since it consistently creates more lines. As explained above, return type together with function name are often long and in many cases exceed line length, so a line break is required anyway. With this rule, we have a line break always, so the look of the code is more homogeneous.

I would say it's not like either option is better than another; they both have pros and cons. Therefore any choice would have been opinionated. So we just kept the old PCL style guide, avoiding making choices ;)

@kunaltyagi Thanks for the review! I will go through it later.

simulation/src/range_likelihood.cpp Outdated Show resolved Hide resolved
{
if (a%2 || b%2) return level;
while (true) {
if (a % 2 || b % 2)
Copy link
Member Author

Choose a reason for hiding this comment

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

🤷‍♂️ 😆

simulation/tools/sim_test_simple.cpp Outdated Show resolved Hide resolved
write_file_ = false;
}
}

// Handle normal keys
void
on_keyboard (unsigned char key, int, int)
on_keyboard(unsigned char key, int, int)
{
double speed = 0.1;

if (key == 27)
Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. But I wouldn't mix formatting and refactoring. A follow-up PR is welcome ;)

print_info ("\n");

print_info ("\n(Note: for multiple .pcd files, provide multiple -{fc,ps,opaque} parameters; they will be automatically assigned to the right file)\n");
print_error("Syntax is: %s <file_name 1..N>.<pcd or vtk> <options>\n", argv[0]);
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not so sure what to do about such help printing functions (we will see more of them in other modules). The formatting is messed up now, but is disabling clang-format completely a good idea?

Copy link
Member

Choose a reason for hiding this comment

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

They way they are written, any further formatting isn't expected. The alternative would be using fixed width columns for output (std::setw or "%{amount}s", with amount in negative for left-align) which will align them normally without having to rely on the code layout.

But this breaks the visual aspect of the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, and then this mixing of info/value printing to colorize the output... I'm leaning towards leaving this as-is for now.

Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

Some patterned code blocks need an opinionated fix, but LGTM

simulation/src/range_likelihood.cpp Outdated Show resolved Hide resolved
simulation/src/range_likelihood.cpp Outdated Show resolved Hide resolved
simulation/src/range_likelihood.cpp Outdated Show resolved Hide resolved
simulation/src/range_likelihood.cpp Outdated Show resolved Hide resolved
simulation/src/range_likelihood.cpp Show resolved Hide resolved
simulation/src/range_likelihood.cpp Outdated Show resolved Hide resolved
@taketwo taketwo merged commit 00cd8b7 into PointCloudLibrary:master Sep 25, 2019
@taketwo taketwo deleted the format-simulation branch September 25, 2019 11:46
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.

5 participants