开发者

Is starting a one-word function with a capital letter a good practise? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 12 years ago.

I have read in K&R 开发者_如何学编程that functions containing more than one word should be capitalized.Should one-word functions like prime(),be written as Prime()?Is this a good practise?


I have never seen this in K&R, are you sure it's not another book?

K&R always use lowercase, abbreviated function names without underscores for their function name throughout their book. The only identifier-related advice I can find in their book is: Don't start with an underscore, variables are lowercase, symbolic constants all uppercase.

As others have said, the important part is consistency. The three common styles are:

  • lowercasetogether
  • CamelCase
  • lcase_underscore_sep


It's more important to be consistent.

Edit: What looks weird to you might look normal to someone else. Consistency is what's important; as long as all one-word functions are lower-case and all multiple-word functions are initially upper-cased, I think you're good to go. If you get to choose, choose what makes the most sense to you; if you're working with existing code, comply with what's already been done. If the existing code is inconsistent, fix it.


I believe consistency with your code base and with the libraries you are using is important as well as language custom is important when considering capitalization and camelCase vs under_score. I may be wrong but I haven't seen many c single word uppercase functions.


It's completely up to you. What matters is that you should be persistent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜