On Fri, 2017-11-03 at 08:36 +0100, Ulrich Schmidt wrote:
A few days ago i came over something like the following code lines:
func(blabla)
;(higgs or superman)(donald)
morefuncs()
looks strange to me. I reformatted the code sequence this way:
func(blabla);
(higgs or superman)(donald);
morefuncs();
Instead of adding semicolons, I would prefer to split the function call
into two lines. This way the person reading the code doesn't need to
understand that one tricky corner case of the Lua syntax.
local person = higgs or superman
person(donald)
You can also use a do-end block if you want to limit the scope of the
new variable:
do
local person = higgs or superman
person(donald)
end
I don't like the putting a semicolon after *every* statement because it
I think it can teach the wrong thing about the Lua syntax. It gives the
impression that any statement could potentially be ambiguous without a
semicolon after it when in fact the only ambiguity in the language
involves the the rare `()()` function call statement. And in that one
ambiguity the actual solution is to put the semicolon *before* the
confusing statement, not after it.
One thing that I have seen happen in Javascript is people writing
things like the following, thinking it would avoid the problem
func(blabla)
(higgs or superman)(donald);
morefuncs()
Often this happened when using a build system that concatenates
multiple Javascript files into a single file. In Javascript it was
common for modules to start with a `()()` function call statement
because of the Immediately Invoked Function Expression pattern.