J
James Kuyper
On 05/02/2012 05:36 AM, BartC wrote:
....
At a more formal level, I've sometimes considered making assignment a
statement type, rather than an expression type. As a statement that is
not an expression, it would not return a value, and would therefore
never be confusable with equality comparisons. I almost never use the
return value from a assignment expression, so I don't see this as a
significant loss.
This is only for a new C-like language, of course; it would break too
much existing C code to make such a modification to C.
....
And the fix is easy: use different symbols for assignment and equality. By
using the natural "=" symbol for equality, you won't then fall into the trap
of using it by mistake instead of the very 1970s-looking "==".
Or use two symbols for assignment; one that returns the value of the left
side ("="), and one which returns void (eg. ":="). This could be added to C
today. It won't eliminate the problem, but can reduce it.
At a more formal level, I've sometimes considered making assignment a
statement type, rather than an expression type. As a statement that is
not an expression, it would not return a value, and would therefore
never be confusable with equality comparisons. I almost never use the
return value from a assignment expression, so I don't see this as a
significant loss.
This is only for a new C-like language, of course; it would break too
much existing C code to make such a modification to C.