Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

361–367 of 367 posts

Re: Why Does “=” Mean Assignment?

#361
post #217

Earlier quoted context omitted.

Yes, but again, the issue is whether most developers will be hindered or helped by case-sensitivity in a language. Based upon my experience, identifier case-sensitivity is simply making things harder than they need to be on the developer. Conceptually, what is the difference between these two identifiers: myObjectInstance MyObjectInstance ? And the key here is the reason for the difference: if it's a typo, then a cas…

> Conceptually, what is the difference In Haskell, one is a variable, the other is a type, and that's enforced by the language. It's the same, albeit by convention, in Java. There are a lot of cases where you want to describe a type and a thing, so apple = new Apple() is pretty reasonable. When I think of case-insensitive languages, I'm thinking of Basic, LISP, SQL, and those don't have a lot of type declarations. An…

No, in my example they're both references to an object instance - they're simply identifiers. Languages that are case-insensitive tend to force one to use identifiers that are also descriptive as to their usage, which is very helpful when reading code as you can tell a type from a variable from a....

Re: languages: Pascal/Object Pascal is case-insensitive, and is statically-typed.

Re: SQL: all implementations that I'm aware of use case-insensitive identifiers for all of the reasons that I've outlined. Any that don't are problematic, at best.

Re: locales: the way that this is typically handled is by a) restricting the allowed characters to the English alphabet (older), or b) by using Unicode (UTF-16) encoding for source files (newer).

Re: Why Does “=” Mean Assignment?

#362
post #8

About once every year I have a brain fart on a sleepy morning and confuse myself by using = for comparitors and or == for assignment... shortly followed by "Nnarhh". [edit] :P LOL at downvotes, HN is no place for silly annecdotes "this is serious things we dooo".

There are better places if you just want to talk about yourself.

> There are better places if you just want to talk about yourself.

hmm, I don't agree with what you are implying defines acceptable comment content on HN. There are many if not a majority of comments highly rated on HN which are highly personal that necessarily talk about themselves, it's part of what makes those comments interesting, if we all commented like wikipedia articles it would be a dull place indeed. My comment maybe flawed in the eyes of other HN readers, but not for the reason you have highlighted.

In my case it's is both personal and relevant but to be honest - not interesting or insightful which is probably why someone mean enough gave me a downvote... but then afterwards I broke the "first rule of fight club" which on HN is equivalent to throwing yourself to the wolves, I accept that, and also can't help it, it's just my nature, I don't self censor for points.

Re: Why Does “=” Mean Assignment?

#363
post #293

Earlier quoted context omitted.

In what way would 'source -> destination' not reflect the "actual" flow of data?

I would be ok with that too! I must have misinterpreted dboreham as suggesting destination -> source Which is very confusing to me.

The arrow always reflects the direction of flow. Difference is just whether you like to have destination first or last. Basically are you Motorola or Intel..

Re: Why Does “=” Mean Assignment?

#364
post #8

About once every year I have a brain fart on a sleepy morning and confuse myself by using = for comparitors and or == for assignment... shortly followed by "Nnarhh". [edit] :P LOL at downvotes, HN is no place for silly annecdotes "this is serious things we dooo".

There are better places if you just want to talk about yourself.

Come now, that's not nice. It's fine to talk about one's experiences on HN. That's what people do in conversation.

Re: Why Does “=” Mean Assignment?

#365
post #355

Earlier quoted context omitted.

Yeah but this introduced an easy path for errors. You could mean to write `==` and instead write `=` and it'll work fine in C in practically all locations (even as conditions of if-statements). Using `:=` could have likely alleviated this error to a noticeable degree, if not entirely.

Chefs rather use a sharp knife then a blunt one, even if they cut themselves from time to time. If safety is a priority, there are special designed languages like Ada that use :=

But... sharp knives are safer than blunt knives, specifically because they reduce the likelihood of being cut. That's why they're preferred.

I see your point, though. I was just bringing up an alternative consideration in the debate regarding equality.

Re: Why Does “=” Mean Assignment?

#366
post #209

Earlier quoted context omitted.

-Wall can almost always catch the problem as it will insist on redundant parens surrounding an assignment. So you can only screw it up if you typed extra parens for an equality expression. Variable on left is conventional, it's how people sound it out in their head, so it's just easier to process mentally when the expression becomes more complex. Yoda syntax catches that single error at the expense of making all equa…

Also how do you prevent "if(a=b)" if both sides are variables?

I will let clang's amazingly detailed error messages speak for themselves:

  ben@burnination ~ $ cat test.c
  int main() {
      int a = 3;
      int b = 2;
      if (a=b) {
          return 1;
      } else {
          return 0;
      }
  }

  ben@burnination ~ $ clang -Wall test.c
  test.c:4:10: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
      if (a=b) {
          ~^~
  test.c:4:10: note: place parentheses around the assignment to silence this warning
      if (a=b) {
           ^
          (  )
  test.c:4:10: note: use '==' to turn this assignment into an equality comparison
      if (a=b) {
           ^
           ==
  1 warning generated.

Re: Why Does “=” Mean Assignment?

#367
post #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.

I agree in that this doesn't really take conscious thought anymore. However, the article had the following:

> How can a = a + 1? That’s like saying 1 = 2.

It looks like a lot of us don't have (never had?) trouble accepting a statement like `a = a + 1` and, upon stepping back, thought maybe it had to do with our internal dialog (which is now probably intuition as we've been processing statements like this for so long).

Post reply on HN