lua-users home
lua-l archive

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


On Sun, Mar 4, 2012 at 11:45, Mark Hamburg <mark@grubmah.com> wrote:
> The one case where I find myself wishing for optional commas is when putting function declarations inside of tables. The space from one entry to the next tends to be long enough that one mentally shifts out of "I'm building a table" mode — or at least I do.
>
> The habit that would fix this for me would be to write:
>
>        {
>
>        a = function()
>                -- This is the first function
>        end
>
>        , b = function()
>                -- This is the second function
>        end
>
>        -- etc
>
>        }
>
> In other words, put the commas on the line where we add an extra item. I have seen this practice in C++ and one gets used to it, but it does fly in the face of conventional comma usage in written language.
>
> If one were to try to deal with just this case, another choice would be allow function declarations inside of tables and make commas implicit at the end of them:
>
>        {
>
>        function a()
>                -- This is the first function
>        end
>
>        function b()
>                -- This is the second function
>        end
>
>        }
>
> For the list of functions, one would still need commas to distinguish calls from sequencing though I could see insisting that for a function declaration to be callable it might need to be wrapped in parentheses (at the expense of breaking compatibility unlike the above proposal which uses an existing unsupported case in the language grammar).
>
> That all said, having a syntax checking editor helps a lot and it's generally pretty easy to figure out that one needs to add a comma...
>
> Mark
>
> P.S. One thing I love about Lua over JavaScript is that Lua's grammar actually makes semicolons optional as opposed to JavaScript which tries to patch things up after the fact with rules for semicolon insertion.
>
>

I want to point out that a semicolon is also a valid table delimiter,
so if having a comma after the last item looks ugly to you, perhaps
you can use semicolons instead and not be as bothered by the
aesthetics? :-) Especially if you're the kind to end every statement
with a semicolon.

-- 
Sent from my toaster.