When is a function name too long?

2019-03-22 14:53发布

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 "GetActionFromTypeName" or "GetSelectedActionType". At what point do functions get too long to manage (not too long for the compiler)?

27条回答
做自己的国王
2楼-- · 2019-03-22 15:25

As long as the functions actually do what their name suggest they do and you're not going for a code golf entry, I think it's a good thing.

查看更多
smile是对你的礼貌
3楼-- · 2019-03-22 15:25

I think that this is especially important for public names - they should not be too long, but how long too long is is very subjective. Always have better a longer and descriptive name than a too short name.
For private methods even very long names are really no problem in my opinion.

查看更多
萌系小妹纸
4楼-- · 2019-03-22 15:27

I don't think a method name can be too long as long as it is descriptive. If a method name goes over 40 characters I will see if I can convey the same meaning in fewer words. If not I'll live with the long name in for the sake of clarity.

查看更多
登录 后发表回答