Let's say I have a method, Foo()
. There are only certain times when Foo()
is appropriate, as determined by the method ShouldFooNow()
. However, there are many times when the program must consider if Foo()
is appropriate at this time. So instead of writing:
if ShouldFooNow(): Foo()
everywhere, I just make that into one function:
def __name(): if ShouldFooNow(): Foo()
What would be a good name for this method? I'm having a hard time coming up with a good convention. IfNecessaryFoo()
is awkward, particularly if Foo()
has a longer name. DoFooIfShould()
? Even more awkward.
What would be a better name style?
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters.
For variables, the Java naming convention is to always start with a lowercase letter and then capitalize the first letter of every subsequent word. Variables in Java are not allowed to contain white space, so variables made from compound words are to be written with a lower camel case syntax.
Naming-convention definitionA collection of rules followed by a set of names which allow users to deduce useful information, based on the names' character sequence and knowledge of the rules followed; such as Manhattan's East-West streets being called "Streets" and its North-South streets being called "Avenues". noun.
A function name should clearly indicate what the function does. You don't have to scroll around, open the function source code to understand how it works. Also, the name should describe only one concept: one-to-one relation. In the end, you probably don't want to communicate like these guys!
I think you're pretty close. Put the action/intent at the head of the method name, for easier alphabetic searching. If I were writing something like that, I'd consider
FooIfNecessary() FooIfRequired()
Say, for instance,
ElevatePermissionsIfNecessary()
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