mutable default parameter problem [Prothon]

Mark Hahn mark at prothon.org
Fri Jun 25 16:11:13 EDT 2004


Dave Brueck wrote:

> Ahh...so the method name is just _spelled_ with an exclamation point?

Yes, a Prothon identifier is the same as a Python identifier except that it
can end with an exclamation mark ( ! )or a question mark ( ? ).  These marks
can only appear at the end and there can only be one.  It is up to the
programmer to make sure he/she uses them properly.

Exclamation marks are to be used in identifiers if and only if it is a
method that modifies the target in-place.

Question marks are to be used on methods if and only if they return True or
False and nothing else.

> IOW, the ! is a token you can use at the end of an identifier, but it
> is not actually used by the language itself -

No, the marks are significant to the language just as any other part of the
identifier is.

> Seems like a waste to reserve a
> symbol for something so rarely needed.

I disagree.  In-place modification is significant and happens often.
Ignoring this is dangerous.

>>> Personally, I don't like the modify-in-place-and-return-the-object
>>> 'feature' - it's not needed _that_ often, but more importantly, it
>>> makes the code harder to read (to me at least).
>>
>> If you use the Prothon append!() exactly as you use the Python
>> append() you will get the exact same results.  This is just an extra
>> feature for those that want it.
>>
>> Guido avoided returning values from in-place modification functions
>> because of the confusion as to whether in-place mods were happening
>> or not.  We have solved that confusion with the exclamation mark.
>> Our code is very readable because of this.
>
> Clearly, readability is in the eye of the beholder. :)

How can you argue that the exclamation mark indicating in-place-modification
does not make it more readable?  Several other languages feel so also.  We
didn't just make this up.





More information about the Python-list mailing list