lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Because it is far too error-prone.  It's the juxtaposition of = and ==
that
> makes this dangerous.  For example, what happens if the programmer in your
> example above had intended to compare the value of var to the result of
> function (i.e. "while (var == function()) {}") instead of assignment?
This
> is a single-character error that could be buried deep inside a complex
> block of code.  It is difficult to find and, if, say, a maintenance
> programmer were looking at it, the intent isn't necessarily obvious and
> clear.

    Juxtaposing = and == is always a syntax error in C.

    Confusing = and == can happen at any place where either are used.
That problem is not specific to the "while (var = function()) {}" construct.
I agree that people who create programs should write nice clear code
that makes maintenance easier.  All the same, the maintenance programmer
must understand the capabilities of the language.

    Some programmers write nice, clear code regardless of the constructs
they use.  Other programmers create an unmaintainbable  mess even when
they avoid `dangerous' contstructs.


> Making assignment not be usable inside an expression eliminates a fairly
> common source of irritating (and sometimes devastating) error at the
> expense of adding a single extra line of code in most circumstances where
> it would be used.

    I have sometimes confused = and ==, but NEVER in a loop control
expression.  All bugs are irritating and sometimes devastating.  I still
don't see how using this construct provides any extra opportunity
to generate bugs.


>  I think this is a fair trade-off myself, and I would beg
> that Lua's creators not turn assignment into an expression.

    I'm not suggesting that it be added to LUA.  I'm only considering
C programming, and once more I apologise for being off topic.