Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

151–160 of 367 posts

Re: Why Does “=” Mean Assignment?

#151
post #123
post #79

Earlier quoted context omitted.

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.

I don't think that is a big issue. Just bind it to something else. In RStudio by default <- is bound to alt and -.

But that is still 2 keystrokes. That is why in R they came to the compromise to use both <- and =.

Re: Why Does “=” Mean Assignment?

#152
The third option: an assertion of fact

A language could reasonably use plain = to let the programmer state that two things are equal. In a debug build, this could be compiled into code that validates the condition. A debug build would abort if the condition is not met. For a performance-optimized build, the compiler could use the information for optimization. It could be like the __assume keyword that Microsoft supports.

Re: Why Does “=” Mean Assignment?

#153
post #132
post #4

Because programming languages are typically designed for the tiny group of existing programmers than the much larger group of future programmers. The same reason unnecessary tokens exist, and 'drop' means delete in databases. It's entirely cultural.

>Because programming languages are typically designed for the tiny group of existing programmers... So this is a dilemma I have while working on a new language. I'd like to go with `:=`, but `=` is absurdly popular, and I'm trying to keep the language as approachable as possible. I don't think the clarity of `:=` is so compelling that it outweighs the `ew, why are there colons in there` reaction that I think most nov…

The key isn't whether you use := or =, it's whether you allow assignment in expressions.

My advice: don't allow assignment in expressions. To me, it's like the case-sensitive issue: the language designers think it's a useful feature, but it actually works against most developers.

Re: Why Does “=” Mean Assignment?

#154
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

In the original Smalltalk implementation, the character corresponding to _ in ASCII was a left facing arrow, which Smalltalk used for assignment at the time.

Re: Why Does “=” Mean Assignment?

#155

Earlier quoted context omitted.

Traditionally? I don't think there was a "tradition". ":=" was used in Algol. "=" was used in Fortran. COBOL didn't use either "=" or ":=".

> "=" was used in Fortran. And most BASICs, though some (most?) required the keyword LET to introduce an assignment, as well.

> And most BASICs, though some (most?) required the keyword LET to introduce an assignment, as well.

LET was virtually always optional; an expression by itself on a line (like 'X 10') is a syntax error anyway, so removing LET doesn't introduce any ambiguity.

Re: Why Does “=” Mean Assignment?

#156
post #151
post #123

Earlier quoted context omitted.

I don't think that is a big issue. Just bind it to something else. In RStudio by default <- is bound to alt and -.

But that is still 2 keystrokes. That is why in R they came to the compromise to use both <- and =.

Well, it also adds a space before and after so you're saving one keystroke vs space = space

Re: Why Does “=” Mean Assignment?

#157
I think they are forgetting that a lot of languages take que's from old math textbooks where you would see function definitions written as "f(x) = nx + b" or "y = nx + b" and constant assignment with a "c = " notation.

if you want to calculate the output of a function into a data table(which is what early computers were often doing) iterating a variable x over a f(x) = xn + b(with n and b being fixed constants) is exactly how you would do it on paper so it's probably a case of computers emulating applied math rather then simply being pure theory machines.

Re: Why Does “=” Mean Assignment?

#158
post #2

The '=' sign is used because after that statement the variable will indeed have equality with the r-value. Coincidentally in async languages like Verilog there is a another assignment operator '<=' which means that the variable won't take the new value until the next clock cycle (or more explicitly the next evaluation of the process block). '=' exists also and has the same meaning as with traditional languages.

[deleted]

Re: Why Does “=” Mean Assignment?

#159

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.

It's better to use -Wall -Werror options for C compiler.

That won't always catch the error and even if it did, why is it better?

Re: Why Does “=” Mean Assignment?

#160
Simple, programming is like using Old Speech, the language of Dragons. We cannot lie in that language and therefore when we make a statement it becomes true. (In case I'm being too obtuse.. Earthsea)

But really, this is such a pedantic discussion, trying really hard to not get sucked in.

Post reply on HN