Skip to content

Latest commit

 

History

History
40 lines (34 loc) · 1.11 KB

naming.md

File metadata and controls

40 lines (34 loc) · 1.11 KB

How To Name Your Variables

  • names should be short, but descriptive
  • avoid single-character names like a
  • ... but sometimes they are okay, like i for loop indices
  • avoid abbreviations like tok for tokenize, cpy for copy
  • choose a consistent style

Bad Example

?inline

int a;
int rct =
  scanf("%d", &a);
if (rct != 1)
  return -1;
printf("age: %d", a);

Good Example

?inline

int age;
int readCount =
  scanf("%d", &age);
if (readCount != 1)
  return -1;
printf("age: %d", age);

Naming Conventions

Above all else, use conventions consistently. For example, PascalCase for classes, camelCase for variables/functions, CAPS_CASE for macros. The C++ standard library uses snake_case for almost everything, but many developers do not follow this style.

The C standard library is a good example for breaking rule 4. It uses abbreviations extensively, which might harm readability (compare strstr strtok strcspn).

See Also

?creditFooter 614056212803092480