Lua Style Guide ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
96 messages Options
12345
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Lua Style Guide ?

J Doe
Hi,

I was wondering if there is an official or commonly accepted style guide for Lua ?  I have adopted the same style as Roberto while working through the 3rd and 4th edition of "Programming Lua", but I was wondering if there is an actual written or community followed standard (similar to how Python has PEP-8) ?

Thanks,

- J


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Jorge Eduardo
Dear J Doe, 

Yes, there is a Lua Style Guide available at http://lua-users.org/wiki/LuaStyleGuide.

Best regards!

Jorge Eduardo

Em 5 de jun de 2017 09:16, "J Doe" <[hidden email]> escreveu:
Hi,

I was wondering if there is an official or commonly accepted style guide for Lua ?  I have adopted the same style as Roberto while working through the 3rd and 4th edition of "Programming Lua", but I was wondering if there is an actual written or community followed standard (similar to how Python has PEP-8) ?

Thanks,

- J


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Pierre Chapuis
June 5, 2017 2:31 PM, "Edu Araújo" <[hidden email]> wrote:

> Dear J Doe,
>
> Yes, there is a Lua Style Guide available at http://lua-users.org/wiki/LuaStyleGuide.

It's on the wiki but it's not really "official".

I think those days there isn't an accepted style. The most "popular"
open style guide may be the one from Olivine Labs [1]. But basically
there is a style guide per company and/or project.

[1] https://github.com/Olivine-Labs/lua-style-guide

--
Pierre Chapuis

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Javier Guerra Giraldez
On 5 June 2017 at 17:52, Pierre Chapuis <[hidden email]> wrote:
> The most "popular"
> open style guide may be the one from Olivine Labs [1].


personal preferences; but i vehemently disagree with more than half of
the rules on that "style guide".

i don't think there's anything like a "popular" style. much less official.

--
Javier

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Charles Heywood
Ooh, thanks for showing that. I've already found a small quirk though :P - going to review in depth later.

On Mon, Jun 5, 2017, 12:06 Javier Guerra Giraldez <[hidden email]> wrote:
On 5 June 2017 at 17:52, Pierre Chapuis <[hidden email]> wrote:
> The most "popular"
> open style guide may be the one from Olivine Labs [1].


personal preferences; but i vehemently disagree with more than half of
the rules on that "style guide".

i don't think there's anything like a "popular" style. much less official.

--
Javier

--
--

Software Developer / System Administrator
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Nicola Fontana
In reply to this post by Javier Guerra Giraldez
Il Mon, 5 Jun 2017 18:06:27 +0100 Javier Guerra Giraldez <[hidden email]> scrisse:

> On 5 June 2017 at 17:52, Pierre Chapuis <[hidden email]> wrote:
> > The most "popular"
> > open style guide may be the one from Olivine Labs [1].  
>
>
> personal preferences; but i vehemently disagree with more than half of
> the rules on that "style guide".

I find that document really convenient instead.

PHP has so called "reccomendations" [1] that makes
interoperability a breeze. It would help to see something similar
in the Lua community but I'll not hold my breath.

[1] http://www.php-fig.org/

Ciao.
--
Nicola

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Marc Balmer
In reply to this post by Javier Guerra Giraldez
It's a guide only, not the law, nor the bible.

And yes, I find it ridicoulous as well.

Am 5. Juni 2017 um 19:06:59, Javier Guerra Giraldez ([hidden email]) schrieb:
On 5 June 2017 at 17:52, Pierre Chapuis <[hidden email]> wrote:
> The most "popular"
> open style guide may be the one from Olivine Labs [1].


personal preferences; but i vehemently disagree with more than half of
the rules on that "style guide".

i don't think there's anything like a "popular" style. much less official.

--
Javier

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua style guide ?

Roland
In reply to this post by J Doe
Hi Doe,

I am not aware of any official style guide for Lua. However, there are a fair common set of rules that Lua people tend to use and advocate. You can find them at:


I also recently came across these :
- Zaki's https://github.com/zaki/lua-style-guide
Hope these links help.

Regards,
Roland.


From: J Doe <[hidden email]>
Subject: Lua style guide ?
 
Hi,

I was wondering if there is an official or commonly accepted style guide for Lua ?  I have adopted the same style as Roberto while working through the 3rd and 4th edition of "Programming Lua", but I was wondering if there is an actual written or community followed standard (similar to how Python has PEP-8) ?

Thanks,

- J




------------------------------

Message: 2
Date: Fri, 2 Jun 2017 16:38:11 -0400
From: J Doe <[hidden email]>
Subject: Style guide for Lua ?
To: Lua List <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain;       charset=us-ascii

Hi,

I was wondering if there is an official or commonly accepted style guide for Lua ?  I have adopted the same style as Roberto while working through the 3rd and 4th edition of "Programming Lua", but I was wondering if there is an actual written or community followed standard (similar to how Python has PEP-8) ?

Thanks,

- J



------------------------------

_______________________________________________
lua-l mailing list
[hidden email]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/lua-l-lists.lua.org


End of lua-l Digest, Vol 83, Issue 4
************************************

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Sean Conner
In reply to this post by Javier Guerra Giraldez
It was thus said that the Great Javier Guerra Giraldez once stated:
> On 5 June 2017 at 17:52, Pierre Chapuis <[hidden email]> wrote:
> > The most "popular"
> > open style guide may be the one from Olivine Labs [1].
>
>
> personal preferences; but i vehemently disagree with more than half of
> the rules on that "style guide".

  I've "violated" over half the guidelines there.  And I agree with Javier.
But the thing is---that particular style guide has no rational for each
rule.  Just to pick on two rules:

* Define functions externally to table definition.

  This is in reference to defining functions within a table.  It's
consistent with their rule further down:

* Prefer function syntax over variable syntax.  This helps differentiate
between named and anonymous functions [Oooh!  A rational!  Unfortunately,
this is rare in the document]

but to be, the rule "define functions externally to table definition"
violates the DRY (Don't Repeat Yourself) for single use functions.  Here,
definition and use are separated and you stand a better chance of generating
an error due to a typo (easily fixed, but still annoying).  I would only
define the function externally to the table if I'm using the function
definition more than once. [1]

  Next rule:

* Leading commas aren't okay.  An ending comma on the last item is okay, but
discouraged.

  Their rule might lead to nice looking code (but "nice looking" is in the
eye of the beholder [3].  Taking a look at their "good" example:

        -- good
        local thing = { -- No comment on their brace placement <shudder>
          once = 1,
          upon = 2,
          aTime = 3
        }

  Add a new item, and the patch becomes cluttered with extraneous details:

        6c6,7
        <   aTime = 3
        ---
        >   aTime = 3,
        >   there = 4

  Compare with allowing ending commas:

        6a7
        >   there = 4,

  The rational for leading commas is to avoid the patch cluttering issue
while still allowing for no trailing comma, but with that, you *still* have
the cluttering issue of you move the initial item to a new place (or add a
new item before the first one).  

  Me?  I use ending commas not necessarily for the uncluttered patches
(because other quirks of my style do lead to very cluttered patches) but
because it's one less thing to remember (don't add an ending comma).  

  -spc (Really people!  You should all be using my style! 8-P

[1] I may allow such use for single use functions for modules, but then
        again, I do modules a bit differently [2] to maintain easy
        compatability with Lua 5.1.

[2] Check out https://github.com/spc476/lua-conmanorg/blob/master/lua/date.lua
        for an example.

[3] Or eyes, if you are talking about a beholder from Dungeons and
        Dragons, but I digress ...

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

steve donovan
In reply to this post by Pierre Chapuis
On Mon, Jun 5, 2017 at 6:52 PM, Pierre Chapuis <[hidden email]> wrote:
> [1] https://github.com/Olivine-Labs/lua-style-guide

"Using four spaces or tabs will result in public flogging". Ouch!

Reminds me of when Mike Pall said he would never collaborate with
anyone who used three-space indents.

Sean has it, I think: there's really not enough rationale for these
arbitrary things. I would go with Roberto, I don't think he would flog
anyone for using four spaces.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Pierre Chapuis
June 6, 2017 9:13 AM, "steve donovan" <[hidden email]> wrote:

> "Using four spaces or tabs will result in public flogging". Ouch!
>
> [...]
>
> Sean has it, I think: there's really not enough rationale for these
> arbitrary things. I would go with Roberto, I don't think he would flog
> anyone for using four spaces.

For what it's worth: I use four spaces. My company has its own internal
style guide which differs from Olivine Labs', I was just pointing at it
because it's kind of popular.

There is clearly not a community-wide style. I do like languages that
have one (Python, Go...) but history makes it hard to do for Lua.

I think style guide are important at company- or project- level: you
typically don't want mixed styles in your code base.

At community level I don't care about this. If we could all agree on
things that matter even when you don't look at the code (e.g. usage
of globals in modules, etc) I would be happy.

--
Pierre Chapuis

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Soni L.
In reply to this post by steve donovan


On 2017-06-06 04:13 AM, steve donovan wrote:

> On Mon, Jun 5, 2017 at 6:52 PM, Pierre Chapuis <[hidden email]> wrote:
>> [1] https://github.com/Olivine-Labs/lua-style-guide
> "Using four spaces or tabs will result in public flogging". Ouch!
>
> Reminds me of when Mike Pall said he would never collaborate with
> anyone who used three-space indents.
>
> Sean has it, I think: there's really not enough rationale for these
> arbitrary things. I would go with Roberto, I don't think he would flog
> anyone for using four spaces.
>

Actually, spaces are a waste of horizontal screen space. Keep them low
so we can go deeper.

At 80col, I can do 40 indents @ 2 spaces, but only 20 indents @ 4
spaces. 3 spaces is incompatible with 80col.

--
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.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

steve donovan
In reply to this post by Pierre Chapuis
On Tue, Jun 6, 2017 at 2:32 PM, Pierre Chapuis <[hidden email]> wrote:
> I think style guide are important at company- or project- level: you
> typically don't want mixed styles in your code base.

Yes, that's part of being a professional and fitting in with everyone.

> At community level I don't care about this. If we could all agree on
> things that matter even when you don't look at the code (e.g. usage
> of globals in modules, etc) I would be happy.

Ditto and likewise! Some things are not a good idea, and there are
tools which can identify these.

I once had to use Pylint, and I've never come across a more
opinionated piece of software, ever. And the real problems were
happily buried in the style advice noise.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

steve donovan
In reply to this post by Soni L.
On Tue, Jun 6, 2017 at 2:43 PM, Soni L. <[hidden email]> wrote:
> At 80col, I can do 40 indents @ 2 spaces, but only 20 indents @ 4 spaces. 3
> spaces is incompatible with 80col.

Ah, the magic number 80!  Actually, 3 spaces is pretty common in Lua.

There is an argument that if you need 40 indents, you need shorter functions ;)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Francisco Olarte
On Tue, Jun 6, 2017 at 2:56 PM, steve donovan <[hidden email]> wrote:
> There is an argument that if you need 40 indents, you need shorter functions ;)

I would say if you USE 40 indents, you should TRY shorter functions.
If you NEED them, it is because you cannot do it with shorter
functions.

Francisco Olarte.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Francisco Olarte
In reply to this post by Soni L.
On Tue, Jun 6, 2017 at 2:43 PM, Soni L. <[hidden email]> wrote:
> Actually, spaces are a waste of horizontal screen space. Keep them low so we
> can go deeper.

They are something more, even for tyou, otherwise you'll be doing 0-spaces.

> At 80col, I can do 40 indents @ 2 spaces, but only 20 indents @ 4 spaces. 3
> spaces is incompatible with 80col.

Now, you can't, you can do 39 and 19, otherwise it's just an empty
line with trailing whitespace ( which lately luacheck likes to
complain about ).

And, with 3 spaces, you can do 25 levels plus fgh() ( I was trying to
find a useful lua construct in two chars for 26*3, did not find any,
biut did not try too hard ).

Francisco Olarte.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Marc Balmer
Tabs are holy.  Spaces, no matter how many, are just a cheap substitute.

Any yes, any line shall never exceed 80 characters, that's the eleventh commandment!

Am 6. Juni 2017 um 15:10:39, Francisco Olarte ([hidden email]) schrieb:

On Tue, Jun 6, 2017 at 2:43 PM, Soni L. <[hidden email]> wrote:
> Actually, spaces are a waste of horizontal screen space. Keep them low so we
> can go deeper.

They are something more, even for tyou, otherwise you'll be doing 0-spaces.

> At 80col, I can do 40 indents @ 2 spaces, but only 20 indents @ 4 spaces. 3
> spaces is incompatible with 80col.

Now, you can't, you can do 39 and 19, otherwise it's just an empty
line with trailing whitespace ( which lately luacheck likes to
complain about ).

And, with 3 spaces, you can do 25 levels plus fgh() ( I was trying to
find a useful lua construct in two chars for 26*3, did not find any,
biut did not try too hard ).

Francisco Olarte.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Javier Guerra Giraldez
On 6 June 2017 at 14:25, Marc Balmer <[hidden email]> wrote:
> Tabs are holy.  Spaces, no matter how many, are just a cheap substitute.


at last reason surfaced!

that's all the style you need. the rest is being too picky

--
Javier

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Rena
In reply to this post by Sean Conner
On Jun 5, 2017 18:38, "Sean Conner" <[hidden email]> wrote:
Me?  I use ending commas not necessarily for the uncluttered patches
(because other quirks of my style do lead to very cluttered patches) but
because it's one less thing to remember (don't add an ending comma).

Being able to leave a trailing comma is a great feature. I'm always bothered when using languages that don't allow it.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Lua Style Guide ?

Dirk Laurie-2
In reply to this post by Marc Balmer
2017-06-06 15:25 GMT+02:00 Marc Balmer <[hidden email]>:
> Tabs are holy.  Spaces, no matter how many, are just a cheap substitute.
>
> Any yes, any line shall never exceed 80 characters, that's the eleventh
> commandment!

WIth great respect to all those who are gleefully enjoying the direction
this thread is going, a quotation from the Bible [1]:

  Whitespace of whitespaces, saith the Programmer; all is whitespace.

After all, Lua is whitespace-agnostic; you can just pass your chunk
of code to quite a simple reformatter [2].

Style is much more than that.

It deals with questions such as:

- Do you explicitly code 'nil' in situations where it will be supplied
by default?
- Do you write "y=10*x" or "y=10.0*x" when you know that x is
floating-point?
- Do you monkeypatch globals?
- Do you use closures to encapsulate upvalues?

[1] Modern Geek Version.
[2] Any idiot can write one.[3] My first Lua program (part of my LuaTeX
primer) was just such a reformatter.
[3] Not necessarily a good one. My first Lua program can't reformat
itself (failure to take into account the "--[^\n]*\n" comment construction).

12345
Loading...