lua-users home
lua-l archive

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

On 2017-11-03 12:46 PM, Hugo Musso Gualandi wrote:
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:

    ;(higgs or superman)(donald)

looks strange to me. I reformatted the code sequence this way:

    (higgs or superman)(donald);
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

You can also use a do-end block if you want to limit the scope of the
new variable:

         local person = higgs or superman

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

     (higgs or superman)(donald);

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.

I understand what you're saying, but ; is the identity function.

;(x) is x.

Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.