Request For Comments: 3-space indentation style

classic Classic list List threaded Threaded
51 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Request For Comments: 3-space indentation style

immerrr again...
Hi all

Emacs mode for Lua [1] has been proposing 3-space indentation as
default for its new users for ages, but at some point I've started
receiving rather regular requests (here's a public example: [2]) to
change this to 2 (according to "canonical" style used in Lua-related
books [2]) or at least 4 (to match other languages' conventions).

So, it'd be nice to collect some opinions/statistics about indentation
offsets that are currently used community-wide. Admittedly, I haven't
programmed in Lua for quite a while.

Aside from that, does anyone remember the origin of this 3-space
indentation convention? I tried to trace it recently but the only
relevant responses I found were smth like "three spaces is Lua code
style, don't ask why".

Cheers,
immerrr

1. https://github.com/immerrr/lua-mode/
2. https://github.com/immerrr/lua-mode/issues/56
3. http://lua-users.org/wiki/LuaStyleGuide

Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Rena
On Sat, Jan 4, 2014 at 6:52 PM, immerrr again <[hidden email]> wrote:
Hi all

Emacs mode for Lua [1] has been proposing 3-space indentation as
default for its new users for ages, but at some point I've started
receiving rather regular requests (here's a public example: [2]) to
change this to 2 (according to "canonical" style used in Lua-related
books [2]) or at least 4 (to match other languages' conventions).

So, it'd be nice to collect some opinions/statistics about indentation
offsets that are currently used community-wide. Admittedly, I haven't
programmed in Lua for quite a while.

Aside from that, does anyone remember the origin of this 3-space
indentation convention? I tried to trace it recently but the only
relevant responses I found were smth like "three spaces is Lua code
style, don't ask why".

Cheers,
immerrr

1. https://github.com/immerrr/lua-mode/
2. https://github.com/immerrr/lua-mode/issues/56
3. http://lua-users.org/wiki/LuaStyleGuide


I've always used 4 spaces myself, but this is a topic over which many (flame)wars have been fought.

--
Sent from my Game Boy.
Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Vadi
Two spaces here, like it is used in Lua books.
Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Tim Hill
In reply to this post by immerrr again...

On Jan 4, 2014, at 3:52 PM, immerrr again <[hidden email]> wrote:

> Hi all
>
> Emacs mode for Lua [1] has been proposing 3-space indentation as
> default for its new users for ages, but at some point I've started
> receiving rather regular requests (here's a public example: [2]) to
> change this to 2 (according to "canonical" style used in Lua-related
> books [2]) or at least 4 (to match other languages' conventions).
>
> So, it'd be nice to collect some opinions/statistics about indentation
> offsets that are currently used community-wide. Admittedly, I haven't
> programmed in Lua for quite a while.
>
> Aside from that, does anyone remember the origin of this 3-space
> indentation convention? I tried to trace it recently but the only
> relevant responses I found were smth like "three spaces is Lua code
> style, don't ask why".
>
> Cheers,
> immerrr
>
> 1. https://github.com/immerrr/lua-mode/
> 2. https://github.com/immerrr/lua-mode/issues/56
> 3. http://lua-users.org/wiki/LuaStyleGuide
>

We standardize on 4 for indents here to match across all languages and platforms .. makes code more consistent to read. I’ve always felt 4 is a good “Goldilocks” width, not too wide (stops code creep across page) and not too narrow (too hard for eye to follow).

I think 3 came from the “tabs stops at prime number intervals” camp? :)

—Tim


Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Johnneylee Jack Rollins


On Sat, Jan 4, 2014 at 5:04 PM, Tim Hill <[hidden email]> wrote:

On Jan 4, 2014, at 3:52 PM, immerrr again <[hidden email]> wrote:

> Hi all
>
> Emacs mode for Lua [1] has been proposing 3-space indentation as
> default for its new users for ages, but at some point I've started
> receiving rather regular requests (here's a public example: [2]) to
> change this to 2 (according to "canonical" style used in Lua-related
> books [2]) or at least 4 (to match other languages' conventions).
>
> So, it'd be nice to collect some opinions/statistics about indentation
> offsets that are currently used community-wide. Admittedly, I haven't
> programmed in Lua for quite a while.
>
> Aside from that, does anyone remember the origin of this 3-space
> indentation convention? I tried to trace it recently but the only
> relevant responses I found were smth like "three spaces is Lua code
> style, don't ask why".
>
> Cheers,
> immerrr
>
> 1. https://github.com/immerrr/lua-mode/
> 2. https://github.com/immerrr/lua-mode/issues/56
> 3. http://lua-users.org/wiki/LuaStyleGuide
>

We standardize on 4 for indents here to match across all languages and platforms .. makes code more consistent to read. I’ve always felt 4 is a good “Goldilocks” width, not too wide (stops code creep across page) and not too narrow (too hard for eye to follow).

I think 3 came from the “tabs stops at prime number intervals” camp? :)

—Tim



I wouldn't say 'across all languages and platforms' because some languages don't follow this and you're roundly chided for not conforming.

I personally prefer 2 spaces, not tabs. But mostly because I'm narcissistic and live vicariously through my code and prefer it to look the way I wrote it.

~Johnneylee
Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

D. Matt Placek
In reply to this post by immerrr again...

On Sat, Jan 4, 2014 at 6:52 PM, immerrr again <[hidden email]> wrote:
So, it'd be nice to collect some opinions/statistics about indentation
offsets that are currently used community-wide. Admittedly, I haven't
programmed in Lua for quite a while.

Aside from that, does anyone remember the origin of this 3-space
indentation convention?

I didn't even realize this was the convention; I've always set my indent levels to 3 anywhere I can in emacs and just assumed lua mode was picking it up from somewhere else.

For most of my career I've always used 3 spaces, mostly because it feels "just right" and I'd been lucky enough to work in environments where I could get away with it, but it's certainly less conventional than 4 which is more common for {} languages, or 2 which seems to be popular for the scripting languages.  Four is just a stretch more than is necessary, and two is not quite enough for the indentation to stand out.  Three seems to be perfect.  That's a completely unscientific and purely aesthetic opinion, of course.

Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Pierre-Yves Gérardy
In reply to this post by immerrr again...
At one point, I naturally came to three spaces for indenting my Lua
code, and it looked quite good.

I didn't know it was the Emacs default, and it somehow felt like
living a dangerous life, away from the familiar powers of two...

I switched to two for my current projects, but it may change again.

—Pierre-Yves

Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Hisham
On 5 January 2014 00:33, Pierre-Yves Gérardy <[hidden email]> wrote:
> At one point, I naturally came to three spaces for indenting my Lua
> code, and it looked quite good.
>
> I didn't know it was the Emacs default, and it somehow felt like
> living a dangerous life, away from the familiar powers of two...
>
> I switched to two for my current projects, but it may change again.

I use three spaces in the LuaRocks codebase, and I've seen it used in
other projects as well. It fits nicely in a language with
"end"-terminated blocks.

-- Hisham

Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Philipp Janda
Am 05.01.2014 03:53 schröbte Hisham:

> On 5 January 2014 00:33, Pierre-Yves Gérardy <[hidden email]> wrote:
>> At one point, I naturally came to three spaces for indenting my Lua
>> code, and it looked quite good.
>>
>> I didn't know it was the Emacs default, and it somehow felt like
>> living a dangerous life, away from the familiar powers of two...
>>
>> I switched to two for my current projects, but it may change again.
>
> I use three spaces in the LuaRocks codebase, and I've seen it used in
> other projects as well. It fits nicely in a language with
> "end"-terminated blocks.

I prefer two spaces for a similar reason:

     if a >= b and
        b <= c then
       print( b )
     end

Using three spaces misaligns with a wrapped if-condition. Of course I
try hard to follow a foreign indentation style if modifying an existing
file, that's when I appreciate (bottom) modelines[1].

>
> -- Hisham
>

Philipp

   [1]: https://bugzilla.wireshark.org/tools/modelines.html



Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Dirk Laurie-2
In reply to this post by Hisham
2014/1/5 Hisham <[hidden email]>:

> I use three spaces in the LuaRocks codebase, and I've seen it used in
> other projects as well. It fits nicely in a language with "end"-terminated
> blocks.

Thanks for explaining that. I've been using three spaces in Lua, two in C,
four in Python for as long as I can remember, but I never knew why.
Now I do!

Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Roberto Tirabassi
I've been using 3 spaces since I started, didn't know why. My guru teached
me that 3 was the path to savage and I followed that path.
Now my eyes refuse to look at "even indented code" as well as that code
can't be understood.
Being serious the only thing that really matters to meet is: no matter how
much do you indent, please take care of using spaces and only spaces. If
you religion don't allow this, than use only tabs. Never mix those styles.
When people having different methods try to work together flame wars are
behind the corner...

Roberto Tirabassi.

--3D Informatica, Via Speranza 35, 40068, S.Lazzaro di Savena - Bologna, Italy
Tel: +39051450844 | Fax: +39051451942
WWW: http://www.3di.itDocumentation: http://wiki.3di.it FTP:
ftp://[hidden email], Download:/3di, Upload:/incoming

**** Informativa Privacy
- Ai sensi del D. Lgs n. 196/2003 (Codice Privacy) si precisa che le
informazioni contenuti in questo messaggio sono riservate e ad uno
esclusivo del destinatario. Qualora il messaggio in parola Le fosse
pervenuto per errore, La preghiamo di eliminarlo senza copiarlo e di non
inoltrarlo a terzi, dandocene gentilmente comunicazione. Grazie.
--



2014/1/5 Hisham <[hidden email]>:

> I use three spaces in the LuaRocks codebase, and I've seen it used in
> other projects as well. It fits nicely in a language with "end"-terminated
> blocks.

Thanks for explaining that. I've been using three spaces in Lua, two in C,
four in Python for as long as I can remember, but I never knew why.
Now I do!




Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Choonster TheMage
In reply to this post by immerrr again...
On 5 January 2014 10:52, immerrr again <[hidden email]> wrote:

> Hi all
>
> Emacs mode for Lua [1] has been proposing 3-space indentation as
> default for its new users for ages, but at some point I've started
> receiving rather regular requests (here's a public example: [2]) to
> change this to 2 (according to "canonical" style used in Lua-related
> books [2]) or at least 4 (to match other languages' conventions).
>
> So, it'd be nice to collect some opinions/statistics about indentation
> offsets that are currently used community-wide. Admittedly, I haven't
> programmed in Lua for quite a while.
>
> Aside from that, does anyone remember the origin of this 3-space
> indentation convention? I tried to trace it recently but the only
> relevant responses I found were smth like "three spaces is Lua code
> style, don't ask why".
>
> Cheers,
> immerrr
>
> 1. https://github.com/immerrr/lua-mode/
> 2. https://github.com/immerrr/lua-mode/issues/56
> 3. http://lua-users.org/wiki/LuaStyleGuide
>

Personally, I've always used tabs set to four spaces for my Lua code.
This is probably because it's the default setting in Notepad++ (the
first programming editor I used).

Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Enrico Colombini
On 05/01/2014 10.33, Choonster TheMage wrote:
> Personally, I've always used tabs set to four spaces for my Lua code.
> This is probably because it's the default setting in Notepad++ (the
> first programming editor I used).

I switched from two to four spaces ages ago [1] and stayed there, but
being an author I can fully appreciate the reason for using two spaces
in a book (and the need to balance name readability with the available
horizontal space).

[1] I think I used eight spaces in early assembly language code, but you
don't need indentation there.

Well, it's just a convention, probably not deserving the number of
messages written about it (including this one).

--
   Enrico

Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Joseph Manning
In reply to this post by immerrr again...
On Sat, January 4, 2014 23:52, immerrr again wrote:

>> So, it'd be nice to collect some opinions/statistics about indentation
>> offsets that are currently used community-wide. Admittedly, I haven't
>> programmed in Lua for quite a while.

immerrr,

   It's three for me!

   To my eye, it's the sweet spot between too little to easily see,
   and too much that deeply-nested code runs off the page.

   Incidentally, on the topic of indentation, I also indent my 'end's,
   since it makes it easier to spot the start of the next statement.
   However, it appears that such a level of indentational enlightenment
   is quite rare amongst other Lua programmers :-)

Joseph

------------------------------------------------------------------------
Joseph Manning / Computer Science / UCC Cork Ireland / [hidden email]
------------------------------------------------------------------------



Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Paul E. Merrell, J.D.
It's two spaces for me. Just enough to be visibly noticeable and no more.

Paul

--
[Notice not included in the above original message:  The U.S. National
Security Agency neither confirms nor denies that it intercepted this
message.]

Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

steve donovan
In reply to this post by Joseph Manning
On Sun, Jan 5, 2014 at 12:48 PM, Joseph Manning <[hidden email]> wrote:
>    Incidentally, on the topic of indentation, I also indent my 'end's,
>    since it makes it easier to spot the start of the next statement.
>    However, it appears that such a level of indentational enlightenment
>    is quite rare amongst other Lua programmers :-)

Indeed, sir!  I'd find it a little strange at first (basically have to
boot up my Python visual recognizer)

Can't say I have a standard preference; ldoc is 3, Penlight is 4.
Tabs are (of course) for other people.  For vim users who produce
files with indentation built from a mixture of spaces and tables,
remember that just averaging between two standards does not lead to
sanity.

Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

David Given
In reply to this post by Tim Hill
On 05/01/14 01:04, Tim Hill wrote:
[...]
>> Aside from that, does anyone remember the origin of this 3-space
>> indentation convention?

I *think* it came from Visual Basic --- that's certainly where I first
encountered it, back in the Win3.1 days. But I don't remember whether it
got it from QuickBasic (back in the DOS days); I found a copy of
gorilla.bas and it uses two-space indentation.

I'm afraid the VB connection means that three-space indentation is
irrecoverably tainted with evil and must be abandoned forthwith.

(FWIW, I've never encountered the three-space Lua standard before.)

--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "There does not now, nor will there ever, exist a programming
│ language in which it is the least bit hard to write bad programs." ---
│ Flon's Axiom


signature.asc (845 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

steve donovan
On Sun, Jan 5, 2014 at 2:53 PM, David Given <[hidden email]> wrote:
> I'm afraid the VB connection means that three-space indentation is
> irrecoverably tainted with evil and must be abandoned forthwith.

Mike Pall once said that he would refuse to take anyone seriously who
used three spaces, so clearly feelings get surprisingly strong on the
subject.  (I don't claim that this represents his current position)

Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Peng Zhicheng
In reply to this post by David Given
于 2014-1-5 20:53, David Given 写道:
> On 05/01/14 01:04, Tim Hill wrote:
> [...]
>>> Aside from that, does anyone remember the origin of this 3-space
>>> indentation convention?
> I *think* it came from Visual Basic --- that's certainly where I first
> encountered it [...]
> (FWIW, I've never encountered the three-space Lua standard before.)
>

Not having much VB experience, but _my_ first meeting of the
3-space indentation style was the Verilog language (which
is not a software developing language, anyway).

And my _personal_ Lua coding style uses mostly 4-space indentation.
As personally I perfer a relatively looser coding style (white spaces
and blank lines), I feel 2-space indentation is not quite noticeble.

But I have not actually tried the 3-space indentation style in Lua,
I would not comment more. Maybe I'm gonna give it a try?




Reply | Threaded
Open this post in threaded view
|

Re: Request For Comments: 3-space indentation style

Hisham
In reply to this post by steve donovan


On Jan 5, 2014 11:03 AM, "steve donovan" <[hidden email]> wrote:
>
> On Sun, Jan 5, 2014 at 2:53 PM, David Given <[hidden email]> wrote:
> > I'm afraid the VB connection means that three-space indentation is
> > irrecoverably tainted with evil and must be abandoned forthwith.
>
> Mike Pall once said that he would refuse to take anyone seriously who
> used three spaces, so clearly feelings get surprisingly strong on the
> subject.  (I don't claim that this represents his current position)

I remember that. I assumed he was joking, or else it would be quite rude (judge someone's work by their indentation, really?) Anyway wasn't there a programming adage that said that the less relevant the subject, the stronger people's opinions are? 

I'll just sit in my corner and keep coding my stuff... with three-space indentation.

123