[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Code Formatting Guidelines
- From: HyperHacker <hyperhacker@...>
- Date: Mon, 27 Sep 2010 14:58:25 -0600
On Mon, Sep 27, 2010 at 10:37, GrayFace <sergroj@mail.ru> wrote:
>
>
> My preferences:
> 1)
> local a = {1, 2, 3}
>
> 2)
> local f = function()
> return
> end
>
> 3)
> Tabs as indents.
>
> --
> Best regards,
> Sergey Rozhenko mailto:sergroj@mail.ru
>
>
>
>
Mine looks like GrayFace's, but with a lot more complex "rules" I like
to follow and break.
--most tables initialized with leading line break, trailing comma and line
--break, few items per line, lined up into columns.
urls = {
'www.google.com', 'www.yahoo.com', 'www.microsoft.com',
'www.xkcd.com', '127.0.0.1:12345',
}
meta = {
__add = function(a,b) return a + b end,
__sub = function(a,b) return a - b end,
}
--when initializing to an array of numbers or short strings, no leading or
--trailing newline or comma, and single tab indentation. Hex numbers always an
--even number of digits unless some very good reason not to be.
numbers = {0x19, 0x0C, 0x1A, 0x00}
morenumbers = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,
377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657}
--'local function f' as opposed to 'local f = function'.
--Whether parameters are spaced generally depends on their length.
--Most function names in ProperCase; internal functions in lowercase and/or
--prefixed with underscore.
local function _call(fid, ...)
return functions[fid](...)
end
function DoSomethingCool(NumTrees, NumBoats)
error('Not implemented')
end
function Some.Random.Table:DoStuff()
self.AnswerToLife = 42
end
Lines do not exceed 80 characters; if one is only a few over that, I might just
delete some whitespace to make it fit, before trying to break it evenly so as to
end up with two lines of similar length.
As you can see I don't follow all of these rules strictly and there is probably
lots of room for improvement. Just thought I'd throw my own preferences into the
pool. More data is generally a good thing.
--
Sent from my toaster.