Hacker News new | ask | show | jobs
by thetruthseeker1 2994 days ago
When I learnt programming, i was confused by x=x+1;

After I understood what it really meant, I wondered why they didn’t use some other symbol to capture this semantic. Say something like x <- x+1 ; Which implies assignment rather than equality - That way this would be unambiguous and I feel is more clear. I now guess the choice of using ‘=‘ was probably an attempt at making a (compromised) choice given the limited symbols that were available back when High level languages were first written?

5 comments

Heh, I just read an explanation of this the other day:

https://www.hillelwayne.com/post/equals-as-assignment/

The summary is that C used it because assignment was a lot more common than equality checking, and back then, typing fewer characters was a big deal.

Go write a couple hundred lines of R (please don't actually do this R is atrocious imo) and then you'll understand why '=' is used instead of '<-' - because it's a pain in the ass, even with hotkeys
Hey, hey, hey! R IDEs give plenty of options which utterly mitigate such alleged difficulties:

https://stackoverflow.com/questions/1741820/what-are-the-dif...

R has = as well which has been working equivalently for me so far. Any caveats?
Similar notation is already used for mappings in general albeit from left to right with the bar arrow, and obscures one of the necessary characteristics of recursive functions, which is a mapping to the natural numbers.

Edit: Misunderstood, thought you were talking about math, not programming languages.

Some languages made slightly better design choices, just not the ones that became super popular!

https://en.wikipedia.org/wiki/Assignment_(computer_science)#...

this is exactly how R syntax works