Question mark in variable and function names

Fernando Perez fperez528 at yahoo.com
Wed Oct 6 13:30:41 EDT 2004


Alex Martelli wrote:

> 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

Well, there would go the two remaining special, useful chars in ipython:

In [3]: x=1

In [4]: x?
Type:           int
Base Class:     <type 'int'>
String Form:    1
Namespace:      Interactive
Docstring:
    int(x[, base]) -> integer

    Convert a string or number to an integer, if possible.  A floating point
    argument will be truncated towards zero (this does not include a string
    representation of a floating point number!)  When converting a string, use
    the optional base.  It is an error to supply a base when converting a
    non-string.


In [5]: !uname -a
Linux haar.colorado.edu 2.4.22-1.2199.nptl #1 Wed Aug 4 12:21:48 EDT 2004 i686
i686 i386 GNU/Linux


Since I just finished replacing all uses of @ for ipython's magic functions,
I'm really not too keen on this idea.  And given that there is a lot of
precedent for !cmd meaning 'escape to shell' in several environments (gnuplot,
matlab), and for foo? as 'info about foo' (Mathematica), I hope I'd have a
stronger case of opposing these changes if they ever came to Guido.  

I did NOT oppose the @decorator one strongly, as I felt that ipython could just
adapt if there was consensus on the benefit of @ for the language, and that
the loss to ipython was near-zero (just a few hours of my time changing code
and docs).  The change was made, and current CVS ipytho uses %magic instead,
which is fine.

But if something like this (!?) were to be seriously considered, I would most
definitely try to oppose it.  Granted, my opinion is just one amongst many. 
But the fact that ipython is proving to be a growingly popular tool for
interactive work in multiple contexts, and that this popularity is in no small
part due precisely to the utility of features like !cmd and foo?, would
hopefully give my humble opinion the weight of a larger community.

That, and the fact that in _my_ opinion, names-with-embedded-punctuation look
ugly :)

Best,

f



More information about the Python-list mailing list