Skip to content

Commit

Permalink
#15: Added missing example (and reformated naming conventions section)
Browse files Browse the repository at this point in the history
  • Loading branch information
borjasotomayor committed Sep 14, 2022
1 parent 6da5e18 commit b82543e
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions style-guide/c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -414,39 +414,58 @@ block comments instead::
Naming Conventions
------------------

Variable and function names should use the `snake_case <https://en.wikipedia.org/wiki/Snake_case>`_
naming convention (i.e., ``lowercase_with_underscore``). For example:

::
- Variable and function names should use the `snake_case <https://en.wikipedia.org/wiki/Snake_case>`_
naming convention (i.e., ``lowercase_with_underscore``). For example::

sum_of_squares
print_happy_birthday
total_apples



Constants names should use snake_case with all caps:

::
- Constants names should use snake_case with all caps::

PI
MAX_CLIENTS
MAX_IRC_MSG_LEN


Use descriptive names for parameter names, variables, and function
names. Use short names for local
variables. In general, the further away a variable will be used, the more
descriptive the name needs to be.

However, you should not assume from the above that loops should *always* use
one-letter variable names. Here is an example where doing so can make your
code hard to read:


The names of functions that perform an action should include a verb:

::
- Use descriptive names for parameter names, variables, and function
names. Use short names for local
variables. In general, the further away a variable will be used, the more
descriptive the name needs to be.

- However, you should not assume from the above that loops should *always* use
one-letter variable names. Here is an example where doing so can make your
code hard to read:

No::

for (int i = 0; i < num_employees; i++)
{
// ...
// 10 lines of code
// ...
float y = m / 60;
// ...
// 50 lines of code
// ...
data[i] += y
}

Yes::

for (int employee_id = 0; employee_id < num_employees; employee_id++)
{
// ...
// 10 lines of code
// ...
float hours_worked = m / 60;
// ...
// 50 lines of code
// ...
data[employee_id] += hours_worked;
}

- The names of functions that perform an action should include a verb::

Yes: read_column_from_csv
No: column_from_csv
Expand Down

0 comments on commit b82543e

Please sign in to comment.