variable declaration

Antoon Pardon apardon at forel.vub.ac.be
Thu Feb 10 08:23:44 EST 2005


Op 2005-02-10, Nick Coghlan schreef <ncoghlan at iinet.net.au>:
> Antoon Pardon wrote:
>> Well it seems you have some fair points. I'll just stop here stating
>> that I would like to have it, even if it proved to be slower. Speed
>> is not that big a factor in the things I write.
>
> Oh, certainly. I wasn't suggesting the speed hit was enough to kill the idea - I 
> was just pointing it was something that you would use when correctness and being 
> explicit was considered more important than a small price in speed. And if the 
> name check got optimised out like an assert does. . . Hey, that gives me an idea 
> (see below).
>
>> I just would like
>> to ask a question relating semantics. Supose the following code.
>> 
>> x = 42
>> 
>> def f():
>>   x := 21   #  or x .= 42  I don't remember what you used exactly
>
> Alex used ':=' in a couple of examples, but you'll have to ask him his reasons.
>
> I used '.=' instead mainly because I think colons are ugly, but also because 
> ':=' has the ability to trigger confusion due to its slightly different use in 
> those languages which use it for assignment (Eiffel and Pascal come to mind. . . 
> since Pascal uses it, I guess Delphi does too).

I don't think that would be a big issue. Python uses '=' also
differently from a number of languages. My preference would
currently be for ':=' because I have the impression that if
you don't leave spaces the period in '.=' tends to be obscured.

  x.=42   vs    x:=42

seems a clear win for the second IMO.

-- 
Antoon Pardon



More information about the Python-list mailing list