I think official code style guidelines from Google are very helpful, but they do not cover naming conventions for view elements.
Let's say we simple Activity which contains one ImageView, one TextView and Button. Code would look like this:
class SimpleActivity extends Activity {
private ImageView mImageView;
private TextView mTextView;
private Button mButton;
}
Of course we won't give such names for widgets, cause they aren't descriptive. We should know the functions of this widgets. So let's imagine that ImageView represents user profile image, TextView represents username and Button represents continue button.
I would divide possible naming conventions in three categories:
1.
class SimpleActivity extends Activity {
private ImageView mUserProfileImageView;
private TextView mUsernameTextView;
private Button mContinueButton;
}
Big advantage of first conventions is that while using members in code, we know that this is TextView and we can use "setText()" method for example. Unfortunatelly name is very long, because lazy programmer is good programmer, this is it's drawback.
2.
class SimpleActivity extends Activity {
private ImageView mUserProfileImage;
private TextView mUsernameText;
private Button mContinueButton;
}
Here we have mixed convention, we still know what's kind of widgets it is while using somewhere in code, but maybe when we have more complicated functions of widgets these names would be still too long?
3.
class SimpleActivity extends Activity {
private ImageView mUserProfile;
private TextView mUsername;
private Button mContinue;
}
The laziest category.
Question
Which naming conventions do you use in code and what's your experience? Maybe there are better conventions which I didn't mention? What kind of convention Google is using?