Question mark in variable and function names

Harry George harry.g.george at boeing.com
Wed Oct 6 15:00:05 EDT 2004


andre.naess at gmail.com (Andr? N?ss) writes:

> 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?
> 
> I also found it neat that destructive operations were clearly marked
> with !.
> 
> Is there anything preventing this from being possible in Python?
> 
> One of the things I really love about Python is the way it feels when
> I type it. It just comes completely natural to write "for foo in bar"
> and then push the colon, all those curly braces on the other hand
> always feel awkward.

I had the impression that "!" and "?" were more Scheme-isms than
Common-Lisp-isms.  

For "?", a typical CL idiom is "p" suffix, without or without leading
"-".  For clarity, I always use the "-p" form.  In Python this becomes
"_p", as in "ready_for_data_p".  I do this for boolean (True/False)
variables, methods, and functions.

For "!", a typical CL idiom is "n" prefix (as in "nreverse").  I've
never tried doing a Python equivalent, because I only see destructive
operations in builtins (which are already named).

What prevents using "?" and "!"?  Hopefully a graceful and poetic
sense of balance on the part of language designers.  In the extreme
we'd have APL.  Partway there, we'd have Ruby and perl.  I personally
like Python the way it is.




-- 
harry.g.george at boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 342-0007



More information about the Python-list mailing list