Assignment Versus Equality

Christopher Reimer christopher_reimer at icloud.com
Sun Jun 26 14:47:25 EDT 2016


On 6/26/2016 6:21 AM, Steven D'Aprano wrote:

> On Sun, 26 Jun 2016 08:48 pm, BartC wrote:
>
>> On 26/06/2016 08:36, Lawrence D’Oliveiro wrote:
>>> One of Python’s few mistakes was that it copied the C convention of using
>>> “=” for assignment and “==” for equality comparison.
>> One of C's many mistakes. Unfortunately C has been very influential.
>>
>> However, why couldn't Python have used "=" both for assignment, and for
>> equality? Since I understand assignment ops can't appear in expressions.
> Personally, I think that even if there is no *syntactical* ambiguity between
> assignment and equality, programming languages should still use different
> operators for them. I must admit that my first love is still Pascal's :=
> for assignment and = for equality, but C's = for assignment and == for
> equality it *almost* as good.
>
> (It loses a mark because absolute beginners confuse the assignment = for the
> = in mathematics, which is just different enough to cause confusion.)
>
> But the BASIC style = for both assignment and equality is just begging for
> confusion. Even though = is not ambiguous given BASIC's rules, it can still
> be ambiguous to beginners who haven't yet digested those rules and made
> them second nature.
>
> And even experts don't always work with complete statements. Here is a
> snippet of BASIC code:
>
> X = Y
>
> Is it an assignment or an equality comparison? Without seeing the context,
> it is impossible to tell:
>
> 10 X = Y + 1
> 20 IF X = Y GOTO 50
>
>
> Now obviously BASIC was a very popular and successful language, for many
> years, despite that flaw. But I wouldn't repeat it in a new language.
>
>
>>> It should have copied the old convention from Algol-like languages
>>> (including Pascal), where “:=” was assignment, so “=” could keep a
>>> meaning closer to its mathematical usage.
>> (I think Fortran and PL/I also used "=" for assignment. Both were more
>> commercially successful than Algol or Pascal.)
> Fortran 77 used .EQ. for equality. I'm not sure about PL/I.
>
> I'm also not sure I'd agree about the commercial success. Fortran certainly
> has been extremely popular, albeit almost entirely in numerical computing.
> But PL/I has virtually disappeared from the face of the earth, while Pascal
> still has a small but dedicated community based on FreePascal, GNU Pascal,
> and Delphi.
>
> (Of the three, FreePascal and Delphi appear to still be getting regular
> releases.)

I started writing a BASIC interpreter in Python. The rudimentary version 
for 10 PRINT "HELLO, WORLD!" and 20 GOTO 10 ran well. The next version 
to read each line into a tree structure left me feeling over my head. So 
I got "Writing Compilers & Interpreters: An Applied Approach" by Ronald 
Mak (1991 edition) from Amazon, which uses C for coding and Pascal as 
the target language.  I know a little bit of C and nothing of Pascal. 
Translating an old dialect of C into modern C, learning Pascal and 
figuring out the vagaries of BASIC should make for an interesting 
learning experience.

Chris R.



More information about the Python-list mailing list