193k views
4 votes
multi word variable names - a variable name should _______ its purpose - descriptive variable names may include multiple _____

User Petrichor
by
7.1k points

1 Answer

0 votes

Final answer:

A multi-word variable name should reflect its purpose, and descriptive names often include multiple words joined by specific conventions. They enhance code readability and clarity, and sometimes hyphens are used when the name serves as a modifier.

Step-by-step explanation:

A multi-word variable name should reflect its purpose, providing clarity on what the variable represents or is used for in the code. Descriptive variable names may include multiple words, which are typically joined together using a convention like camelCase, snake_case, or kebab-case. For instance, a variable that stores the total score of a game could be named totalScore or total_score. These naming conventions serve the dual purpose of enhancing readability and providing contextual information about the function or role of the variable within the program.

It's important to avoid sweeping generalizations or using a dictionary definition as a variable name, as these do not provide the specific context needed. Instead, using descriptive variable names that act as definite descriptions can greatly improve the understandability of the code. Additionally, when constructing descriptive names that serve as modifiers before a noun, hyphens may be used to join the words if necessary, maintaining clarity on how the words modify the variable.

User Xizzhu
by
7.5k points