You need two functions:
1. Retrieves plain text from a DB.
2. Based on 1, retrieves rich text - with new lines, font styles etc.
You expect function 2 to be much more used than function 1.
Would you name 1 text() and 2 - rich_text() or would you use the simpler text() for the name of 2, since it's expected to be more popular and use something like plain_text() for 1?
The more general question would be - do you consider function's expected "popularity" when naming it?
No, I don't consider a function's popularity. It's best to have descriptive names for both functions (e.g. one is plain_text()
and one is rich_text()
).
I think that it's best to use relatively specific names for all functions, since using more general names 1.) doesn't give the user too much of an idea of what the function does by reading the name and 2.) can lead to confusion.
Of course, how you name your functions is your choice: I just recommend that you give them somewhat descriptive names and that you name them (and order the arguments) consistently.
I hate nothing more than programming with an API where every function name is short and cryptic (PHP's string functions are that way, even though I'm used to it now -- strstr
and strtok
are hardly intuitive names for what they do).
It's worth thinking about popularity, sometimes, if the code is going to be very widely used. Common words in natural languages tend to be short.
Unless you think you're writing the next UNIX, however, you're probably better off to make the names descriptive and not worry about length.
I'd go for getPlainText()
and getRichText()
.
As a rule of thumb, I always name my functions loosely based on what they do. If I was in your shoes, I would name function one retrieve_plain_text()
and function two retrieve_rich_text()
. I can now glance at either function name and immediately have a basic understanding of what the function is supposed to do: Retrieve (get from something, in this case the database) plain/rich (the type) text.