Naming a predicate: "precondition" or "precondition_is_met"?
Posted
by
RexE
on Programmers
See other posts from Programmers
or by RexE
Published on 2013-10-25T18:36:04Z
Indexed on
2013/10/25
22:10 UTC
Read the original article
Hit count: 329
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?
© Programmers or respective owner