When is a function name too long?

后端 未结 27 1553
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 18:45

I try to be rather descriptive with my function names, where possible. This occasionally results in function names in the twenty to thirty character range such as \"GetActionFr

27条回答
  •  既然无缘
    2021-02-03 19:13

    I think you should worry more about when a function name is too short, or not descriptive enough. As long as your function does what its name describes (and everything its name describes), it is well-named. I often write functions with long names like getPropertyNameArrayFromObject (though I tend to underscore rather than camelize), which could be called getObjPropArr or something else but wouldn't be as descriptive. I tend to stay away from abbreviations because they become ambiguous when you go work on something else and come back to the code.

    On the other hand, consider many built in PHP functions such as stricmp which should really be named something along the lines of caseInsensitiveStringComparison.

    And there are cases where I intentionally write very short function names that are not descriptive at all. Sometimes I just want a short JavaScript function to act as a shortcut. For example, I generally alias $(id) to document.getElementById(id) because I get sick of typing that out.

提交回复
热议问题