lua-users home
lua-l archive

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

Hash: SHA1

> I don't regard the  while (var = function()) {} construct as a bad
> habit.  I certainly avoid it if the expression being evaluated is complex
> and unreadable.  But, it's an expressive and useful way of coding certain
> loops.  It is part of the C language, it is simple, and not ambiguous
> except to people unfamiliar with C.  It's not something I feel very
> strongly about, I just don't understand why anyone would find it
> difficult or dangerous.  

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

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

- --
Michael T. Richter
"Be seeing you."

Version: PGP Personal Privacy 6.5.3