I bet I'm not the only one here that has had problems with something like this: you want to check something in a language that has the == operator for checking equality and instead you do something like: if (a=5) which always returns true, given that the language uses = for assignation (which the most common thing by far if it doesn't always happen)
I don't know what might be the advantages of that, best case scenario I can think it's saving to write one extra line of code, as I cannot think in any situation where the assignation cannot be done before of after that, which is hardly worth the bother considering that something like that can lead to hard to find bugs.
Is there something I'm missing?
=and==are two distinct operators in the programming language. By making them unambiguous, you save the compiler (and the compiler developer) an enormous amount of work trying to suss out whether you mean equals or assignment from the context. In most modern programming languages (and even some compilers for the older languages), saying a=5 in a conditional will cause a warning or error. – Robert Harvey Aug 18 '16 at 23:00if (obj = getResource(x,y,z)) { doStuff(obj); } else { log('Problems!'); }. As an aside, if you find yourself having this problem often, a good habit to get into is to swap the order of your comparisons. If you get used to writing your literals on the left, your compiler will catch these issues early for you, because it's not about to let you do(5 = a)– Chris O'Kelly Aug 19 '16 at 00:05