Assignment Versus Equality

Rustom Mody rustompmody at gmail.com
Sun Jun 26 10:26:34 EDT 2016


On Sunday, June 26, 2016 at 6:51:58 PM UTC+5:30, 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.

This is a tad bit unfair (I think)
Initially Basic (BASIC as things were spelt then) used
LET X = Y
for the assignment

The general success of the succinct and confusing approach starting Fortran and
exploding with C I guess prompted the shortening

[My impression: Dont know the history exactly]


More information about the Python-list mailing list