I'd like to know if writing the name of the variable
is necessary. Could we just write the variable name
(if not variable's name
) instead?
Examples:
To reuse data, reuse the name of the variable that stores it.
Scope is the part of the program where a particular identifier, such as a variable or a function name is accessible.
It can lead to conflicting names of the variables.
It depends heavily on the context.
To explain:
To reuse data, reuse the name of the variable that stores it.
This is correct because we're talking about the name (a property) of the "variable that stores the data".
To reuse data, reuse the variable's name that stores it.
This is incorrect because now we're saying its the name (that belongs to the variable) storing the data.
To reuse data, reuse the variable name that stores it.
This is incorrect because we're still saying the variable name (as a thing) stores the data.
Scope is the part of the program where a particular identifier, such as a variable or a function name is accessible.
This is correct because we're saying the function name (as a thing) is accessible.
Scope is the part of the program where a particular identifier, such as a variable or a function's name is accessible.
This is correct, and is basically identical to the sentence above. We're saying the name (that belongs to a function) is accessible.
It can lead to conflicting names of the variables.
This is grammatically correct but very badly written. We're saying there are "conflicting names" that are properties of the "variables", but this makes it sound like all variables have names that are conflicting.
It can lead to conflicting variable names.
This is correct and makes much more sense than the sentence above. Now, it is clear that we are talking about the variable names (as things) conflicting with each other.
Source: Native speaker & author. Hobbyist coder.
EDIT: Detailed answer to an example from the comments:
The book's title is confusing when compared to the content of the book.
This is correct because we are saying the title (that belongs to the book) is confusing when compared to the content (a property) of the book.
The book's title is confusing when compared to the book's content.
This is correct because we are still saying the title (that belongs to the book) is confusing when compared to the content (that belongs to the book).
These two sentences are very similar. In this context, they mean the same thing.
-------------BONUS TIP---------------
Because we have already explained that we're talking about the title that belongs to the book, we don't need to explain that the content also belongs to the book. Instead, we can use the possessive form of the generic noun "it" and say:
The book's title is confusing when compared to its content.
This is correct because we are saying the title (that belongs to the book) is confusing when compared to the content (that belongs to it). We can assume that "it" = the book because we are not talking about any other objects.
Note: Be careful to not confuse "its" with "it's". "Its" is the possessive form of "it". "It's" is a contraction of "it is".