Skip to content

Rewards style guide

Nejc Zdovc edited this page Oct 1, 2019 · 2 revisions

Accessing value in base::ListValue

void FooDOMHandler::Function(const base::ListValue* args) {
  std::string param1;
  args->GetString(0, &param1);
  int32 param2;
  args->GetInteger(0, &param2);
  service_->Function(param1, param2);
}

✔️

void FooDOMHandler::Function(const base::ListValue* args) {
  CHECK_EQ(2U, args->GetSize());
  if (rewards_service_) {
    const std::string param1 = args->GetList()[0].GetString();
    const int32 param2 = args->GetList()[1].GetInt();
    service_->Function(param1, param2);
  }
}

Assigning values

const std::string val("10");

✔️

const std::string val = "10";

Passing/assigning empty string

void Foo(bool ok) {
  std::string val = ":(";
  if (ok) {
    val = std::string();
  }

  FooSecond(val, std::string());
}

✔️

void Foo(bool ok) {
  std::string val = ":(";
  if (ok) {
    val = "";
  }

  FooSecond(val, "");
}

Const for function parameters

int Foo(int ok) {
  return ok + 1;
}

✔️

int Foo(const int ok) {
  return ok + 1;
}

Brackets for single lines

if (true)
  return;

✔️

if (true) {
  return;
}
Clone this wiki locally