When is a function name too long?

后端 未结 27 1666
伪装坚强ぢ
伪装坚强ぢ 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:10

    Ah, a question with no answer!

    I tend to find if I can't encapsulate it in a few words, then there's something up with the design (paracribbing from Code Complete).

    So while I'm happy with FindArticlesWithoutTitles I would probably be disgusted by FindArticlesWithoutTitlesThenApplyDefaultStyles. This is just wrong; either the name is too technical and not describing it's actual function (titles without articles often need styles to be fixed, so this would be FixArticleStyles) or it should be two functions: FindArticlesWithoutTitles/ApplyDefaultStyles.

    Also: frequency has much to do with it. If it's used often, I want it to be short, to reduce the glare of the code; long repetitive names make code ugly to read and a pain to type. If I'm always finding FindArticlesWithoutTitles I might just shorten to FindNoTitles depending on the appropriate context or maybe even just FindArticles if I have no other article finding functions.

提交回复
热议问题