motine/cppstylelineup

GNU Example - should it use camel case?

Closed this issue · 11 comments

hww commented

From the GNU Coding Standards "For example, you should use names like ignore_space_change_flag; don’t use names like iCantReadThis."

You use lower and upper camel case.

void Cowboy::makeBang (const int &HowMany)
void someVeryLongMethod (int param1, int param2, int param3, int param4, int param5)

Why?

uh interesting. I merged the contributed pull request and apparently it is wrong. thanks for catching this!

would you mind submitting a PR which corrects this?

@Wongboo, after reviewing your contribution again, I am not sure how the PR was meant:
You added the basic structure of the Microsoft and GNU formats. Did you already apply the rules of of the standard too?
Can you help here?

hww commented

uh interesting. I merged the contributed pull request and apparently it is wrong. thanks for catching this!

would you mind submitting a PR which corrects this?

No. I do not. I'm not sure I'm right, I'm just pointing out the inconsistency with the documentation. Such an inconsistency is possible if, for example, GNU has a separate rule for class members (I did not find it). However, I would like to clarify the question and make sure that your example is fully GNU compliant.

no reason to become defensive. it's all good :)

I reached out to Wongboo who added the style guide. let's see what he answers. If you find something in the meantime, please let us know.

@hww, you are right, I only run

clang-format --style=gnu  xxx.cpp

It's wrong, It should be

clang-format --style=gnu  gnu.cpp -- -std=c++11

I get

#include <iostream>

namespace western
{

enum ShootingHand
{
  LEFT,
  RIGHT
};

class Cowboy
{
public:
  Cowboy ();
  Cowboy (int GunCount);
  ~Cowboy ();

  void Shoot (std::string who);
  int
  get_age ()
  {
    return age_;
  } // minor functions have lower case

protected:
  void MakeBang (const int &how_many);

  int gun_count_;
  int age_;
};

Cowboy::Cowboy () : age_ (45), gun_count_ (2)
{
  std::cout << "I am alive!" << std::endl;
}

Cowboy::Cowboy (int gun_count) : age_ (45), gun_count_ (gun_count)
{
  // And this is the longest inline comment you have every seen. Lorem Ipsum.
  // Bacon! Cheese. Bread. Beer. Fish. Mobile fridge. More random words come
  // here...
  std::cout << "Howdy!" << std::endl;
}

Cowboy::~Cowboy () { std::cout << "RIP" << std::endl; }

void
Cowboy::Shoot (std::string who)
{
  age_++;
  int someNumber = 5 + 7 * 3;
  MakeBang (someNumber);
  if (someNumber > 10)
    {
      return;
    }
  switch (age_)
    {
    case 45:
      age_--;
      break;
    default:
      age_++;
    }
}

void
Cowboy::MakeBang (const int &how_many)
{
  for (int i = 0; i < how_many; ++i)
    std::cout << "Bang!" << std::endl;
}

void
someVeryLongMethod (int param1, int param2, int param3, int param4, int param5,
                    int param6, int param7, int param8, int param9,
                    int param10)
{
  std::cout << "So long..." << std::endl;
}
} // namespace western

using namespace western;

int
main ()
{
  Cowboy Amy;
  Cowboy Angus (2);
  Cowboy *current_cowboy = &Amy;
  current_cowboy->Shoot ("yourself");
  return 0;
}

// ADDITIONAL NOTES:
// - Chromium mostly follows Google.No such file or directory

but I found out class name and method are still not lower_case, I don't know gnu style exactly, but if you want to make them lower case, run

clang-tidy --fix --config='CheckOptions:                                                                                ─╯
- key:             readability-identifier-naming.ClassCase
  value:           lower_case
- key:             readability-identifier-naming.EnumCase
  value:           lower_case
- key:             readability-identifier-naming.FunctionCase
  value:           lower_case
- key:             readability-identifier-naming.MemberCase
  value:           lower_case
- key:             readability-identifier-naming.NamespaceCase
  value:           lower_case
- key:             readability-identifier-naming.VariableCase
  value:           lower_case' gnu.cpp -- -std=c++11

ah, super cool @Wongboo. thanks for clearing this up. how would you proceed in regards to the class casing (i am not a C++ pro)?

hww commented

Better, but I still not sure the someVeryLongMethod is a GNU compliant way.

Why someVeryLongMethod has the first letter lowercase while other functions has UpperCamelCase? BTW, GNU standard doesn't seem to clarify how to name functions, I only found that variable name should be lowercase+underscore style.

interesting. what do you propose?

closing due to inactivity.

please feel to re-open when needed.