Question mark in variable and function names

Alex Martelli aleaxit at yahoo.com
Wed Oct 6 19:11:02 CEST 2004


Andr? N?ss <andre.naess at gmail.com> wrote:

> One thing I liked about Lisp was the ability to use the question mark
> (and the exclamation mark) in function names. I found this
> particularily useful when checking boolean properties of a object like
> for example myObj.isContextSet. It just feels so much more natural to
> write myObj.contextSet?

Even though I haven't used Lisp extensively, I agree with you.  Naming
all predicates with a trailing question mark, and:

> I also found it neat that destructive operations were clearly marked
> with !.

ops which modify their arguments with a trailing bang, IS a great idea
for readability.  (I hope this shows that one's preferences are NOT
entirely determined by what one's used to: e.g., even though I speak
Italian and not Spanish, I think Spanish has two great ideas which
Italian should adopt [not one chance in a zillion that it will, sigh]:
start questions and exclamations with reversed versions of
questionmarks, and bangs, respectively; and, mark down ALL the accents
that don't fall in the default syllable...).

 
> Is there anything preventing this from being possible in Python?

Nothing except Guido's decisions in the matter.  As this would cause no
backwards incompatibility, it could even be introduced in Python 2.5,
_IF_ Guido could be convinced (of course, for backwards compatibility, a
zillion existing methods in built-ins and the Standard Library would
still be spelled like they are today -- unfortunate but inevitable; at
best you could add SYNONYMS with trailing qmarks and bangs, alas).

Ruby has this convention and it seems to work wonderfully well for them.
I wish Python could grow it, too, but I don't think I stand any chance
of convincing Guido -- perhaps somebody else can.


Alex



More information about the Python-list mailing list