Blog Home

IdentifierNamingPostForWorldWideWebBlog

2017-10-23

Names should be clear and precise.

Don't mention the type in the variable name. It's OK for the name and the type match.

Bad

std::string name_string;
std::list<std::time_t> holiday_date_list;

Good

std::string name;
std::list<std::time_t> holidays;
Payments payments;

Don't use overly specific names. Get more specific if there is a need for disambiguation.

Bad

Monster final_battle_most_dangerous_boss_monster;
Payments non_typical_monthly_payments;

Good

Monster boss;
Payments payments;

Do not repeat context.

Bad

class AnnualHolidaySale {
  bool PromoteHolidaySale();
  int annual_sale_rebate_;
};

Good

class AnnualHolidaySale {
  bool Promote();
  int rebate_;
}