...
To realize the benefits of problem domain naming, prefer naming collections just using plural problem domain words (ex. employees
) rather than including names of exact programming data types (ex. employee_list
). Such names are shorter to read and can help programmers focus more on the problem domain. Only include additional solution domain suffixes if needed for differentiation in a body of code, and first consider if there may be other ways you could word a variable name.
See the following examples:
Navitabs tab wizard |
---|
{"type":"custom","custom":{"tabs":[{"id":"c3961700-aab1-466e-8461-3c31352819ce","value":"C++","body":{"version":1,"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 1 - Unnecessary “List” or “Array” Suffixes"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Including exact data type (“list” or “array”) in the variable name:"}]},{"type":"codeBlock","attrs":{"language":"c++"},"content":[{"type":"text","text":"std::list<std::string> cpp_compiler_options_list = \n{\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\",\n \"output_program\"\n};"}]},{"type":"paragraph","content":[{"type":"text","text":"While “lists” don’t have to be solution domain concepts (plenty of “lists” exist out in the real-world), inclusion of suffixes like this in variable names is typically more indicative of some programming data type (and even if not, is often an unnecessary word for people to read) and thus is best avoided."}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Orienting the variable name more in the problem domain - just a plural list of compiler options:"}]},{"type":"codeBlock","attrs":{"language":"c++"},"content":[{"type":"text","text":"std::list<std::string> cpp_compiler_options = \n{\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\",\n \"output_program\"\n};"}]},{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 2 - Unnecessary “Set” Suffix"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"\"set\" in this name is referring to the programming \"set\" data type."}]},{"type":"codeBlock","attrs":{"language":"c++"},"content":[{"type":"text","text":"std::set<std::string> index_names_set = { \"index1\", \"index2\" };"}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Focuses on the problem of representing multiple index names. \"unique\" has been added as an alternative way to communicate that the index names are expected to be unique, but that prefix may not be necessary in all circumstances."}]},{"type":"codeBlock","attrs":{"language":"c++"},"content":[{"type":"text","text":"std::set<std::string> unique_index_names = { \"index1\", \"index2\" };"}]},{"type":"paragraph","content":[]}]},"type":"your-content"},{"id":"87c1a862-726c-4033-88b6-d7b6acc3dc69","value":"C#","body":{"version":1,"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 1 - Unnecessary “List” or “Array” Suffixes"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Including exact data type (“list” or “array”) in the variable name:"}]},{"type":"codeBlock","attrs":{"language":"csharp"},"content":[{"type":"text","text":"List<string> cppCompilerOptionsList = new List<string>\n{\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\",\n \"output_program\"\n};"}]},{"type":"paragraph","content":[{"type":"text","text":"While “lists” don’t have to be solution domain concepts (plenty of “lists” exist out in the real-world), inclusion of suffixes like this in variable names is typically more indicative of some programming data type (and even if not, is often an unnecessary word for people to read) and thus is best avoided."}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Orienting the variable name more in the problem domain - just a plural list of compiler options:"}]},{"type":"codeBlock","attrs":{"language":"csharp"},"content":[{"type":"text","text":"List<string> cppCompilerOptions = new List<string>\n{\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\",\n \"output_program\"\n};"}]},{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 2 - Unnecessary “Set” Suffix"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"\"set\" in this name is referring to the programming \"set\" data type."}]},{"type":"codeBlock","attrs":{"language":"csharp"},"content":[{"type":"text","text":"HashSet<string> indexNamesSet = new HashSet<string> { \"index1\", \"index2\" };"}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Focuses on the problem of representing multiple index names. \"unique\" has been added as an alternative way to communicate that the index names are expected to be unique, but that prefix may not be necessary in all circumstances."}]},{"type":"codeBlock","attrs":{"language":"csharp"},"content":[{"type":"text","text":"HashSet<string> uniqueIndexNames = new HashSet<string> { \"index1\", \"index2\" };"}]},{"type":"paragraph","content":[]}]},"type":"your-content"},{"id":"6326e3fa-9c0f-4268-8179-b6106fcabe29","value":"Java","body":{"version":1,"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 1 - Unnecessary “List” or “Array” Suffixes"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Including exact data type (“list” or “array”) in the variable name:"}]},{"type":"codeBlock","attrs":{"language":"java"},"content":[{"type":"text","text":"List<String> cppCompilerOptionsList = List.of(\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\",\n \"output_program\"\n);"}]},{"type":"paragraph","content":[{"type":"text","text":"While “lists” don’t have to be solution domain concepts (plenty of “lists” exist out in the real-world), inclusion of suffixes like this in variable names is typically more indicative of some programming data type (and even if not, is often an unnecessary word for people to read) and thus is best avoided."}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Orienting the variable name more in the problem domain - just a plural list of compiler options:"}]},{"type":"codeBlock","attrs":{"language":"java"},"content":[{"type":"text","text":"List<String> cppCompilerOptions = List.of(\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\",\n \"output_program\"\n);"}]},{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 2 - Unnecessary “Set” Suffix"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"\"set\" in this name is referring to the programming \"set\" data type."}]},{"type":"codeBlock","attrs":{"language":"java"},"content":[{"type":"text","text":"Set<String> indexNamesSet = new HashSet<String>();"}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Focuses on the problem of representing multiple index names. \"unique\" has been added as an alternative way to communicate that the index names are expected to be unique, but that prefix may not be necessary in all circumstances."}]},{"type":"codeBlock","attrs":{"language":"java"},"content":[{"type":"text","text":"Set<String> uniqueIndexNames = new HashSet<String>();"}]},{"type":"paragraph","content":[]}]},"type":"your-content"},{"id":"8caf241f-665e-466e-a888-2ad20ec41966","value":"Python","body":{"version":1,"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 1 - Unnecessary “List” or “Array” Suffixes"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Including exact data type (“list” or “array”) in the variable name:"}]},{"type":"codeBlock","attrs":{"language":"python"},"content":[{"type":"text","text":"cpp_compiler_options_list: list[str] = [\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\", \"output_program\"\n]"}]},{"type":"paragraph","content":[{"type":"text","text":"While “lists” don’t have to be solution domain concepts (plenty of “lists” exist out in the real-world), inclusion of suffixes like this in variable names is typically more indicative of some programming data type (and even if not, is often an unnecessary word for people to read) and thus is best avoided."}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Orienting the variable name more in the problem domain - just a plural list of compiler options:"}]},{"type":"codeBlock","attrs":{"language":"python"},"content":[{"type":"text","text":"cpp_compiler_options: list[str] = [\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\", \"output_program\"\n]"}]},{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 2 - Unnecessary “Set” Suffix"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"\"set\" in this name is referring to the programming \"set\" data type."}]},{"type":"codeBlock","attrs":{"language":"python"},"content":[{"type":"text","text":"index_names_set: set[str] = { \"index1\", \"index2\" }"}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Focuses on the problem of representing multiple index names. \"unique\" has been added as an alternative way to communicate that the index names are expected to be unique, but that prefix may not be necessary in all circumstances."}]},{"type":"codeBlock","attrs":{"language":"python"},"content":[{"type":"text","text":"unique_index_names: set[str] = { \"index1\", \"index2\" }"}]},{"type":"paragraph","content":[]}]},"type":"your-content"},{"id":"c26e1920-0a45-438d-bfd2-a504145fefec","value":"JavaScript","body":{"version":1,"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 1 - Unnecessary “List” or “Array” Suffixes"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Including exact data type (“list” or “array”) in the variable name:"}]},{"type":"codeBlock","attrs":{"language":"javascript"},"content":[{"type":"text","text":"let cppCompilerOptionsArray = [\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\",\n \"output_program\"\n];"}]},{"type":"paragraph","content":[{"type":"text","text":"While “lists” don’t have to be solution domain concepts (plenty of “lists” exist out in the real-world), inclusion of suffixes like this in variable names is typically more indicative of some programming data type (and even if not, is often an unnecessary word for people to read) and thus is best avoided."}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Orienting the variable name more in the problem domain - just a plural list of compiler options:"}]},{"type":"codeBlock","attrs":{"language":"javascript"},"content":[{"type":"text","text":"let cppCompilerOptions = [\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\",\n \"output_program\"\n];"}]},{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 2 - Unnecessary “Set” Suffix"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"\"set\" in this name is referring to the programming \"set\" data type."}]},{"type":"codeBlock","attrs":{"language":"javascript"},"content":[{"type":"text","text":"let indexNamesSet = new Set([\"index1\", \"index2\"]);"}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Focuses on the problem of representing multiple index names. \"unique\" has been added as an alternative way to communicate that the index names are expected to be unique, but that prefix may not be necessary in all circumstances."}]},{"type":"codeBlock","attrs":{"language":"javascript"},"content":[{"type":"text","text":"let uniqueIndexNames = new Set([\"index1\", \"index2\"]);"}]},{"type":"paragraph","content":[]}]},"type":"your-content"},{"id":"0f7500a6-9eac-4a9c-a1a3-13828301fdbb","value":"TypeScript","body":{"version":1,"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 1 - Unnecessary “List” or “Array” Suffixes"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Including exact data type (“list” or “array”) in the variable name:"}]},{"type":"codeBlock","attrs":{"language":"typescript"},"content":[{"type":"text","text":"let cppCompilerOptionsArray: string[] = [\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\",\n \"output_program\"\n];"}]},{"type":"paragraph","content":[{"type":"text","text":"While “lists” don’t have to be solution domain concepts (plenty of “lists” exist out in the real-world), inclusion of suffixes like this in variable names is typically more indicative of some programming data type (and even if not, is often an unnecessary word for people to read) and thus is best avoided."}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Orienting the variable name more in the problem domain - just a plural list of compiler options:"}]},{"type":"codeBlock","attrs":{"language":"typescript"},"content":[{"type":"text","text":"let cppCompilerOptions: string[] = [\n \"-std=c++17\",\n \"-Wall\",\n \"-O2\",\n \"-g\",\n \"-o\",\n \"output_program\"\n];"}]},{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Example 2 - Unnecessary “Set” Suffix"}]},{"type":"paragraph","content":[{"type":"text","text":"Poor practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"\"set\" in this name is referring to the programming \"set\" data type."}]},{"type":"codeBlock","attrs":{"language":"typescript"},"content":[{"type":"text","text":"let indexNamesSet: Set<string> = new Set([\"index1\", \"index2\"]);"}]},{"type":"paragraph","content":[{"type":"text","text":"Better practice: ","marks":[{"type":"strong"}]},{"type":"text","text":"Focuses on the problem of representing multiple index names. \"unique\" has been added as an alternative way to communicate that the index names are expected to be unique, but that prefix may not be necessary in all circumstances."}]},{"type":"codeBlock","attrs":{"language":"typescript"},"content":[{"type":"text","text":"let uniqueIndexNames: Set<string> = new Set([\"index1\", \"index2\"]);"}]},{"type":"paragraph","content":[]}]},"type":"your-content"}],"design":null,"minHeight":0,"vertical":false,"isEmbedded":false}} |
Make the Meanings of Keys and Values Obvious in Map/Dictionary/Lookup Types
Status | ||||
---|---|---|---|---|
|
...