IDENTIFIERS
Identifiers in Vint
Identifiers are used to name variables, functions, and other elements in your Vint code. This guide explains the rules and best practices for creating effective identifiers.
Syntax Rules
Identifiers can include letters, numbers, and underscores. However, they must adhere to these rules:
- Cannot start with a number.
- Case-sensitive: For example,
myVarandmyvarare considered different identifiers.
Examples of Valid Identifiers:
let birth_year = 2020 print(birth_year) // Output: 2020 let convert_c_to_p = "C to P" print(convert_c_to_p) // Output: "C to P"
In the examples above, birth_year and convert_c_to_p follow all syntax rules and are valid identifiers.
Best Practices
To make your Vint code more readable and maintainable, follow these best practices:
-
Use Descriptive Names: Choose names that clearly describe the purpose or content of the variable or function.
let total_score = 85 let calculate_average = func() { /* logic */ } -
Consistent Naming Conventions: Stick to a single naming style across your codebase:
- camelCase:
myVariableName - snake_case:
my_variable_name
- camelCase:
-
Avoid Ambiguity: Use meaningful names instead of single letters, except for common cases like loop counters:
for (let i = 0; i < 10; i++) { print(i) } -
Do Not Use Reserved Keywords: Avoid using reserved keywords as identifiers (e.g.,
let,if,switch).