Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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