tags:

views:

102

answers:

4

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?

A: 

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

Max
+1  A: 

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.

Dave
Many a times I come across such conditions where I have to use both one-word functions and multiple-word functions together.In such condition It looks weird to name one-word functions in small case and multiple-word functions capitalized.
fahad
A: 

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.

Roman A. Taycher
+3  A: 

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
schot