Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my web app framework, each page can have a precondition that needs to be satisfied before it can be displayed to the user. For example, if user 1 and user 2 are playing a back-and-forth role-playing game, user 2 needs to wait for user 1 to finish his turn before he can take his turn. Otherwise, the user is displayed a waiting page.

This is implemented with a predicate:

def precondition(self):
    return user_1.completed_turn

The simplest name for this API is precondition, but this leads to code like if precondition(): ..., which is not really obvious. Seems to me like it is more accurate to call it precondition_is_met(), but not sure about that either.

Is there a best practice for naming methods like this?

share|improve this question

closed as primarily opinion-based by durron597, MichaelT, GlenH7, Snowman, gnat Jul 31 '15 at 10:21

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 1 down vote accepted

The precondition seems to be part of the public API. Therefore, the naming should primarily reflect its usage by a consumer of your API. How your code handles that internally is another question all together.

I assume a user will provide a Page object that implements this precondition method. In that case, implementing a method precondition feels much more natural, declarative, and DWIMmy that the verbose (to the point of being Javaesque) precondition_is_met. Notice that the method is this precondition, and invoking it determines whether it was met.

If I am mistaken and the function is solely used in your internals, the longer name seems to be justified, although you could perhaps elide the is and use precondition_met or precondition_fulfilled.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.