We're having a discussion at work, because of my tendency to name functions based on what they do.
For instance:
function notifyUserOfSomeThingThatHappened(){
// notification code
}
My coworker believes (and I kind of agree) that this function should be named based on why it's being called, rather than what it does, since what it does could change.
Something like this:
function someThingHappened(){
// notification code
// possible new code in the future
}
I agree with this, but with a catch: I think we should name functions that will only ever do one thing by their actual contents, but other functions by their reason for being called, like this:
function someThingHappened(){
notifyUserThatSomeThingHappened();
// possible new code in the future
}
function notifyUserThatSomeThingHappened(){
// original code
}
What are the best practices for naming functions? Why are these practices used? What are the advantages of one over the other?