I am writing a library, so, I want its functions to be named as clearly and cleverly as possible. Currently, I use the following principles:
I'm interested in knowing if there's something I'm missing. Also, can you think of some other prefixes other than is, has, get and set?
Naming Convention for Functions So, similar to variables, the camel case approach is the recommended way to declare function names. In addition to that, you should use descriptive nouns and verbs as prefixes. For example, if we declare a function to retrieve a name, the function name should be getName.
One of the more universal, yet simple rules is: Function names should be verbs if the function changes the state of the program, and nouns if they're used to return a certain value.
One of the more universal, yet simple rules is: Function names should be verbs if the function changes the state of the program, and nouns if they're used to return a certain value.
One more important thing to do when writing a library is to use the same word to describe the same action every time. don't write a function named getName in one class and another function named retrieveNumber in another class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With