I frequently find myself pulling up helper methods in order to make my code better, but end up with duplicate method names. Is there a standard way to name such methods without getting duplicate names?
Example of code before:
function hello(suffix) {
if (typeof suffix === 'string') {
return `Hello ${suffix}`
} else {
return 'Invalid entry'
}
}
Becomes:
function hello(suffix) {
const isSuffixString = isSuffixString(suffix) // can't do in JavaScript
if (isSuffixString) {
return `Hello ${suffix}`
} else {
return 'Invalid entry'
}
}
Of course this is contrived and isn't very useful, but it illustrates the point.
I could call the helper getIsSuffixString
, for example, but it feels like too much.
I just find that the helper method name and the ensuing variable often should have the same name.