lua-users home
lua-l archive

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

It was thus said that the Great Javier Guerra Giraldez once stated:
> On 5 June 2017 at 17:52, Pierre Chapuis <> 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

  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:

	<   aTime = 3
	>   aTime = 3,
	>   there = 4

  Compare with allowing ending commas:

	>   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
	for an example.

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