Reputation: 1739
This is not a code question.
I was just naming a Fragment
and it got so long that I got confused.
I'm not sure if the Fragment
's name is appropriate because it's too long.
What is the right way to name Activity
or Fragment
?
When naming, does the word Fragment
or Activity
have to be included?
For example, MovieListFragment
-> MovieList
, MovieActivity
-> Movie
It's because sometimes it gets too long if i include these.
Or does it matter if I include it and it's long?
There are more than 22 letters to make it easier to recognize the Fragment
I'm trying to name.
Upvotes: 2
Views: 490
Reputation: 58
It doesn't matter if you're working with Activities or fragments, Your Activity or fragment name should be simple and meaningful such that when friends or colleagues read your codes it will make sense to them. Your project files names should also give a pictorial idea of what each variable, function or class does.thus it doesn't matter if the name is long or short. finally adding the word Activity
or Fragment
when naming your Activity or Fragment does not make sense and I will advise you not to do it.
Upvotes: 1
Reputation: 2680
It is the right name when it's intention gets clear.
You should avoid abreviations like MLF
or MLFragment
.
MovieListFragment
makes it perfectly clear.
This counts not just for class names but also for variable names. Though the smaller the scope, shorter names are fine, like in a loop for example:
for (i in 0..array.lastIndex) {
// i might be some index
// the loop has a small scope, so it's easy to get its meaning
}
In other words, if you have to scroll pages of code up to get the idea what that name is, its probably not a good name.
Think about, when you are not looking at this code for long time and you are coming back, would you still get what that name means?
And don't make names shorter just to save 2-3 characters. Days where this kind of optimization were required are long gone, and the compiler will optimize it for you anyway.
Upvotes: 3
Reputation: 298
It all depends on what you and your team are most comfortable with. It does not matter if the name becomes too long or too short. I always name my project files keeping in mind that if I come back to my project after few months I should not be confused with file names and it is pretty intuitive.
Upvotes: 2