I'm not sure what you are getting at here. Re-writing that without the
assignment in the if() gives us:
T x;
x = getvalue();
if (x==0)
{
print("ERROR!");
}
Which should generate precisely the same object code as your version.
That is not the case with the while() code I presented before. There, the
version with the assignment inside the while() is more efficient
(space-wise
at least; it should be a wash speed-wide) then the version without the
assignment.
One could argue one is stylistically better than the other, but
programming style wasn't even on the radar when C was created. Writing
the
smallest, fastest code in 1970s era machine was the only concern.
Yes, but I wasn't arguing the reasons why C included it, simply a reason why
removing it would be a greater pain than anything else. It is a touch late
to be concerned about explaining Cs reasons, they just don't matter that
much anymore.
Also, your original argument said "clumsy", not inefficent. You seemed to be
talking style quite clearly to me.
cannot be changed into a >> non-expression without removing the
functionality of while and a number of other things.
Yes, but you're looking at it from the wrong way. Assignment is an
expression, because they wanted to do assignments inside a while() (to
make
writing a C program easier), and wanted to use the same expressions
evaluator for while statement as elsewhere (to make writing a C compiler
easier).
I don't think I'm looking at it from the wrong way at all. If C had chosen
to disallow assignment as an expression I would probably think it a mistake.
I don't consider languages that special case everything to be terribly well
designed. If the expressions if, while, for, and method calls can accept are
different, you are basically turning what is a simple, logical structure
into a horrible mess. Could you imagine the learning process?
Yes, you can use assignments in while and for and even lock, but not if, of
course unless you put it in parentheses.
No, you cannot use increments in if statements.
No, no conditional expressions in the first or third part of for.
It just doesn't make sense. Never will. C may have made its choices for
speed, but it certainly doesn't mean that those ideals should be thrown away
simply because speed isn't any issue(many performance based ones are already
gone in C# and java, like arrays are pointers). The end result is a language
that is exceedingly simple to parse and quite flexible to write in. And,
above all, a language that isn't hacked together and nearly impossible to
ever be comfortable with, which, IMHO, the changes proposed would do(or
atleast start the process of doing so).
It is a failing to many languages fall into, protecting from errors at the
cost of capacity to get work done.