Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

181–190 of 367 posts

Re: Why Does “=” Mean Assignment?

#181

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 ex…

That is, explicitly, the origin of ‘=’ for assignment in Fortran. The section describing assignment is titled ‘Arithmetic Formulas’:

A. An arithmetic formula is a variable (subscripted, or not), followed by an equals sign, followed by an expression.

B. It should be noted that the equals sign in an arithmetic formula has the significance of “replace”. In effect, therefore, the meaning of an arithmetic formula is as follows: Evaluate the expression on the right and substitute this value as the value of the variable on the left.

Re: Why Does “=” Mean Assignment?

#182
post #55

Earlier quoted context omitted.

The concept of assignment only makes sense in a context with a time axis. Computation has a time axis (location of the instruction pointer) but math does not.

Nope. Logical axioms are required logically, but not associated with time. Comprehension is associated with time, so I can understand how you might arrive where you did.

Sorry but I don't understand how you're using the word 'comprehension' here. I agree that logical axioms aren't associated with time (this is what I mean when I say that math doesn't require an idea of time).

Re: Why Does “=” Mean Assignment?

#183
post #132

Earlier quoted context omitted.

>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.

I definitely agree that assignments should be statement level operations.

I don't think case-folding identifiers is helpful. The language has decreed fooBar is the same as foobar, and that handles the error where you spelled the same idea two different ways, but it fails silently on the error where you spelled two different things a similar way. Worse, there are some people who are very sensitive to case and will be confused, while others will happily type their entire code in all caps.

I think a linter is the best way to catch these issues, and those subjective rules are precisely the sort of thing that need to develop more rapidly than the core parser.

Re: Why Does “=” Mean Assignment?

#184
post #164
post #161

= has contextual meaning in math, why not programming? It's not like we can fool ourselves into thinking that tests for equality don't also have wildly different meaning depending on context. No operator has a universal meaning, nor should they.

Can you provide an example where equals sign is not equality I'm curious.

Defining things, usually preceded by "let", "if", etc.: "let f(x) = 2x+1" or "let w = 2", etc.

Sometimes mathematicians us ":=" to be clearer and shorter.

Re: Why Does “=” Mean Assignment?

#185

IMHO, it was a mistake for some languages to make "=" mean assignment. Algol and Pascal got this right and used ":=" to mean assignment. Even the use of "variable" is wrong when talking about mutable memory. "Assignable" would be better.

Both excellent points.

Re: Why Does “=” Mean Assignment?

#186
It does? Never made much sense to me; especially considering that it already means something useful, equality; which then becomes == and sticks out like a sore thumb. I prefer 'let' for assignment and generic '=' for equality; Cixl[0] adds '==' for identity, can't remember where I stole that one.

https://github.com/basic-gongfu/cixl#equality

Re: Why Does “=” Mean Assignment?

#187

I actually rationalized the '=' symbol in assignment into the following statement, "Let 'left hand side' be equal to 'right hand side'". Using this wording resolves some dissonance around its overloaded usage.

I just intuitively understood that symbols can have different meanings in different contexts, so never felt any dissonance or had any trouble understanding it. Like "read" has different pronunciations, or "plane" has different meanings, "=" is just multiple things under different contexts.

Re: Why Does “=” Mean Assignment?

#188
post #174

My first programming teacher insisted we call the single = sign the 'gets' operator. So int x = 10 int y = x would read in English as x gets 10, y gets x. Shortly after that class I took a break from any coding. When I went to another school I saw Softmore and Junior level programmers still struggling with this. I retained the habit of using 'gets'and never had a problem with this.

I've heard the same but with 'becomes' rather than 'gets'. I think becomes works better for people with a mathematical background, where the concept of variables is totally natural. For people without this, 'gets' might be better because it helps anthropomorphize the variable. The coder 'gives' X a value to hold.

People with a mathematical background should be thoroughly familiar with words having overloaded and jargoned up meanings. Fiber Bundle, group, set, relation, etc... They all mean something different when you're not talking about mathematics, and '=' is no different.

Re: Why Does “=” Mean Assignment?

#189
post #23

Is it really worth allowing assignment in places so weird that you also need ==? Wouldn't it be easier to use = for everything and get rid of those weird edge cases?

I think using arrows would be nicer, especially for complex destructuring / pattern matching, and you arrows are incredibly clear.

A complex destructuring case would be something like this:

{cashMoney -> foo, stuff: {powerLevel -> bar} I think the arrows nicely indicate where data is flowing, and it's unambiguous what is a variable name and what is a field name.

Re: Why Does “=” Mean Assignment?

#190
post #131
post #118

Earlier quoted context omitted.

Elixir has borrowed the pattern matching approach from Erlang, but allows rebinds which makes code refactoring easier. iex(1)> x = 1 1 iex(2)> x = 2 2 iex(3)> ^x = 3 (MatchError) no match of right hand side value: 3 Notice the pin operator (^) to achieve the same effect.

I've used Erlang but not Elixir. Having an additional optional "pin" operator sounds like a bad idea, just piling on complexity. You can't mess up with the Erlang syntax.

The creator of elixir had a blog on this: http://blog.plataformatec.com.br/2016/01/comparing-elixir-an...
Post reply on HN