[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Thoughts on optional commas
- From: Mark Hamburg <mark@...>
- Date: Sun, 4 Mar 2012 10:45:43 -0800
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.