From b82543ea68acb51301b5a3f49ce696fb5c777ff4 Mon Sep 17 00:00:00 2001 From: Borja Sotomayor Date: Wed, 14 Sep 2022 11:16:20 -0500 Subject: [PATCH] #15: Added missing example (and reformated naming conventions section) --- style-guide/c.rst | 63 ++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/style-guide/c.rst b/style-guide/c.rst index b97a1e1..8dcf9d2 100644 --- a/style-guide/c.rst +++ b/style-guide/c.rst @@ -414,39 +414,58 @@ block comments instead:: Naming Conventions ------------------ -Variable and function names should use the `snake_case `_ -naming convention (i.e., ``lowercase_with_underscore``). For example: - -:: +- Variable and function names should use the `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