Michiel
Michiel

Reputation: 768

Not including data type in variable name

In a PR I got some suggestions to rename my variables. Suggestions were made to fi. concat *MutableLiveData.

private val _state = MutableLiveData<AppointmentsUiState>()
val state: LiveData<AppointmentsUiState>
    get() = _state

My two variables. It's an Android ViewModel. After the suggestions I agree that perhaps uiState would be beter. However, 2 suggestions were stateMutableLiveData and stateObservable. I don't like those names, but my problem is that I can't think of a valid reason to not use their suggestions, other than:

Why wouldn't one put data types in variable names?

Upvotes: 0

Views: 1467

Answers (1)

L&#233;o Schneider
L&#233;o Schneider

Reputation: 2295

  • Redundancy

You can see the type of your variables so if you write their type in their name, you just duplicate the information.

  • Maintanability

You couple the variable to its type, so if you change the type, you have to change the name.

  • Ambiguity

If your variable has multiple interfaces, you would have to chose one of them.

Upvotes: 1

Related Questions