bond_core icon indicating copy to clipboard operation
bond_core copied to clipboard

reformat bondcpp for better readability

Open kejxu opened this issue 6 years ago • 1 comments
trafficstars

reformatting bondcpp code according to https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines for better readability

  • indent with 4 spaces
  • place each function call parameter on separate line if they are broken into multiple lines
  • apply consistent coding style, this also provides clearer representation of a variable's type upon inspection
    • use type& name over type &name, the actual type of name is type&
    • use type* name over type *name, the actual type of name is type*

, and use early return for a clearer representation of logic:

void Bond::bondStatusCB(msg)
{
    if (msg->id == id_ && msg->instance_id != instance_id_)
    {
        // action
    }
}

has been changed to

void Bond::bondStatusCB(msg)
{
    if (msg->id != id_)
    {
        // filter out heartbeat from other bonds
        return;
    }
    if (msg->instance_id == instance_id_)
    {
        // filter out heartbeat from this bond
        return;
    }

    // action
}

this also reduces the number of layers in code, providing better readability

kejxu avatar Jul 12 '19 02:07 kejxu

kinetic build was showing this error message:

error: ‘>>’ should be ‘> >’ within a nested template argument list

while melodic builds fine

afaik, this is unnecessary as long as >> is not actually overridden, that's probably why melodic build was okay (since it uses a newer version of g++ compiler). However, this does not seem like something that has enough priority to be considered at the point. Changing >> to > > in favor of kinetic build.

kejxu avatar Jul 12 '19 17:07 kejxu