When is a function name too long?

后端 未结 27 1543
伪装坚强ぢ
伪装坚强ぢ 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 18:47

    It may be a bit off topic, but as you asked specifically for a function name guideline (as opposed to say, method), I figured I would quote Linus Torvalds on naming (although it more refers to variables, but still - the principles hold).

    Chapter 3: Naming

    C is a Spartan language, and so should your naming be. Unlike Modula-2 and Pascal programmers, C programmers do not use cute names like ThisVariableIsATemporaryCounter. A C programmer would call that variable "tmp", which is much easier to write, and not the least more difficult to understand.

    Short, descriptive names go well with short, specific functions... which go well with code reuse.

提交回复
热议问题