epfl-lasa / wiki

Best practices, conventions, manuals and instructions for researchers at the LASA
5 stars 1 forks source link

Add line breaks for function arguments #6

Closed eeberhard closed 3 years ago

eeberhard commented 3 years ago

This always moves arguments back to near the function level, which helps to avoid massive indent blocks when the line before the arguments themselves are long.

This example function:

void foo(int a, int b, int c) {
  //
}

was previously wrapped to:

void foo(int a,
         int b,
         int c) {

}

Now it becomes:

void foo(
    int a, int b,
    int c
) {
  //
}

Here's a concrete example

Before

client_change_state_->async_send_request(request,
                                         [this, transition](rclcpp::Client<lifecycle_msgs::srv::ChangeState>::SharedFuture future) {
                                           auto response = future.get();
                                           if (response->success) {
                                             RCLCPP_INFO(parent_->get_logger(),
                                                         "Transition %i successfully triggered on component %s",
                                                         static_cast<int>(transition),
                                                         this->remote_node_name_.c_str());
                                           } else {
                                             RCLCPP_ERROR(parent_->get_logger(),
                                                          "Failed to trigger transition %i on component %s",
                                                          static_cast<unsigned int>(transition),
                                                          this->remote_node_name_.c_str());
                                           }
                                         });

After

client_change_state_->async_send_request(
    request, [this, transition](rclcpp::Client<lifecycle_msgs::srv::ChangeState>::SharedFuture future) {
      auto response = future.get();
      if (response->success) {
        RCLCPP_INFO(parent_->get_logger(), "Transition %i successfully triggered on component %s",
            static_cast<int>(transition), this->remote_node_name_.c_str()
        );
      } else {
        RCLCPP_ERROR(parent_->get_logger(), "Failed to trigger transition %i on component %s",
            static_cast<unsigned int>(transition), this->remote_node_name_.c_str()
        );
      }
    }
);
eeberhard commented 3 years ago

As a side product, it also automatically adds the @brief tag when generating a function docstring