[Python-ideas] What about allowing '?' in method names?
Tennessee Leeuwenburg
tleeuwenburg at gmail.com
Thu Aug 6 10:10:25 CEST 2009
On Thu, Aug 6, 2009 at 5:50 PM, Xavier Ho <contact at xavierho.com> wrote:
> On Thu, Aug 6, 2009 at 11:01 AM, Tennessee Leeuwenburg <
> tleeuwenburg at gmail.com> wrote:
>
>> this could be nicer than prefixing things with is, and makes things
>> clearer in some cases, e.g.
>>
>> def shouldSomethingHappenFlag(self, context):
>> if 'relevant' in context:
>> return True
>>
>> return False
>>
>> vs
>>
>> def shouldSomethingHappen?(self, context):
>> if 'relevant' in context:
>> return True
>> return False
>>
>> I just think it looks nicer, and is a good hint that a true/false or other
>> kind of flag is likely to come back.
>>
>
> What about
>
> hasSomethingHappened(self, context)
>
> or
>
> isRelevant(self, context)
>
> Either way.. I think ? has better uses though.
>
Well, probably everyone will want to do things differently. Not all method
names work with an 'is' stuck on the front, or a 'Flag' stuck on the end...
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.
Also, when working with someone else's code, they may already has isFoo()
style methods which don't return flags.
So Q is good enough for me, but ? would be even better, for me.
Cheers,
-T
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090806/fdbd1946/attachment.html>
More information about the Python-ideas
mailing list