Is starting a one-word function with a capital letter a good practise? [closed]
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.
精彩评论