Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

71–80 of 367 posts

Re: Why Does “=” Mean Assignment?

#71

> Prolog came out the same year as C and popularized logic programming, and you can sort of fake assignment with cuts. Can anyone explain to me what this is supposed to mean? (I know Prolog, I understand cuts very well. But I don't know what the author means here.)

It means I don't understand Prolog very well and really shouldn't have namedropped it :P

Re: Why Does “=” Mean Assignment?

#74
post #39

more broadly, why schools are merging reduction and equality in arithmetic ?

What do you mean?

in primary school the focus in expressions involving = is reduction more than equality:

    2 + 2 = 4
     = 
I don't recall teacher showing you equalness through stupid but important ideas:

    2 + 2 = 2 + 2
    2 + 2 = 2 + 1 + 1
all these are equal, and it's important later on when expression, with variables, aren't reducible to a constant but to another expression which is equal to the other one. IMO it would help a lot for people to try to simplify a problem into a known identity or interesting form (for instance the 'trick' of adding and subtracting one to get closer to binomial formula or other)

Re: Why Does “=” Mean Assignment?

#75
this might not be fact but I like to think that the colon in := might have been dropped just like diacritic symbols were dropped from the English alphabets. I am not a native English speaker so I had similar issues learning the English script. It was particularly hard to grasp things like why 'do' and 'go' are pronounced differently. But overtime I released that eliminating extra characters reduces a lot of unnecessary complexity and makes your writing faster.

Re: Why Does “=” Mean Assignment?

#76

I've been programming professionally for 25 years using mostly C inspired languages, and I will still regularly write "if(foo = bar)" on a daily basis and not notice until there's an error. It's easily the most common syntax error I write, followed closely by using commas in my for-loop as apparently it looks like a function to my fingers: "for(x=0, x<10, x++)"

Which IDE so you use? Even VIM has plugins to warn on assignment in an if() statement.

Re: Why Does “=” Mean Assignment?

#78
post #10
post #5

Because K&R had terrible keyboards so they abbreviated everything as much as possible. Traditionally := was used for assignment, which makes sense since it is an asymmetric symbol for an asymmetric operation.

There’s also <-, most commonly seen in R but draws it’s heritage from the APL keyboard

Common in Pre-Python pseudo code and algorithms.

Re: Why Does “=” Mean Assignment?

#79
post #15

The length of symbols should roughly be negatively correlated with its frequency. Since in procedural language, assignment is a much more common operation than equality check, it is reasonable to favor "=" over ":=" or even "<-".

also, there's no hand balance on either of the composite symbols. := is my right pinky, <- is different fingers, but bottom and top row. neither exactly flows from the fingertips.

Re: Why Does “=” Mean Assignment?

#80
It isn't just mathematically unsound, it's the cause of many errors, especially in C. Certainly a "million dollar mistake".

A classic way to guard against accidental use of assignment in logic statements is to write it "backwards", i.e.:

    if (2 == x) {...}
Since (2 = x) won't compile, while (x = 2) will not only compile but might appear to work for a very long time.
Post reply on HN