[Python-ideas] What about allowing '?' in method names?

Ben Finney ben+python at benfinney.id.au
Thu Aug 6 11:40:51 CEST 2009

Tennessee Leeuwenburg
<tleeuwenburg at gmail.com> writes:

> I'm trying out an idiom of ending True/False returners with 'Q', i.e.
> self.isSomethingTheCaseQ() or self.shouldSomethingHappenQ() or
> self.getSomeFlagQ()... I find that's reasonably aesthetically
> pleasing, and is a good hint about what the method is for.

If you want it to be more likely to be recognisable to programmers (and
I would advise you to conform these names to PEP 8), you could name it
as “foo_p” which is computer-science shortcut for “foo as a predicate”.

    class Foo(object):

        def should_frobnicate_the_widget_p(self):
            if warble(self):
                return True
            return False

        def content_modified_p(self):
            if wibble(self):
                return False
            return True

 \          “When I get real bored, I like to drive downtown and get a |
  `\         great parking spot, then sit in my car and count how many |
_o__)                    people ask me if I'm leaving.” —Steven Wright |
Ben Finney

More information about the Python-ideas mailing list