elm-format: 2-space vs 4-space indent

1,231 views
Skip to first unread message

Aaron VonderHaar

unread,
Dec 18, 2015, 11:37:33 PM12/18/15
to elm...@googlegroups.com
There are now several more editor plugins supporting elm-format, so I'd like to settle on an answer to the indentation size that we'll be happy with so I can make a stable release of elm-format in the next few weeks.

In the previous thread, most people who spoke up seemed to prefer (or at least be able to tolerate 2-space) indents.  (Though it's possible only those people spoke up because the initial build used 4-space indents.)

I've done a run of what elm-format would produce with 2-space indents instead of 4-space indents.

You can see the diffs here: https://github.com/avh4/elm-format/compare/two-spaces?diff=split&expand=1&name=two-spaces

Please share any thoughts about the two, and/or log your opinions on the Elm Code Indentation Survey http://goo.gl/forms/4WPmHXrqY8

Thanks!

Peter Damoc

unread,
Dec 19, 2015, 2:46:56 AM12/19/15
to elm...@googlegroups.com
I defaulted to 4 space because of my Python background but since then I discovered that I need things to be nested in Elm more than in Python mainly due to frequent use of case + let and html. 

Looking at:   
I think there would be a good choice to go with 2 spaces. 

I would like to add that there is a very good idea to create a process that formalizes all this stuff. 
A RFC style guide would be a wonderful resource to point newcomers too and gently tell them: this has been discussed thoroughly and a decision has been made. The Best Current Practice for code formatting is: ...

The equivalent to PEP-8 is way more powerful than "this has been discussed many times, let me provide you with a link to the last discussion". 


            


--
You received this message because you are subscribed to the Google Groups "elm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elm-dev/CAMZecXngobuscFU_oXkejET%3DmHTjvSSWdgTU0i1dn%3D4cAM4_uw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
There is NO FATE, we are the creators.
blog: http://damoc.ro/

Jeff Smits

unread,
Dec 19, 2015, 3:46:36 AM12/19/15
to elm-dev

The 2-space output looks great. I like how nested records look more consistent and how you save a lot of horizontal space in lets and cases.

Adrian Cîrstei

unread,
Dec 19, 2015, 5:37:49 AM12/19/15
to elm-dev
2 spaces also, here.

Laszlo Pandy

unread,
Dec 19, 2015, 6:07:56 AM12/19/15
to elm-dev
I have never used 2-spaces for any code in my life. I was strongly for 4-spaces (actually in most of my code I use tabs). But I think I've changed me mind. The 2-space indent for elm looks nice. I can't say it's better than 4-space. Objectively they are very similar, so I can accept if it becomes the standard.

My only concern is that as we gain more horizontal space, we lose scalability, and won't be able to clearly see the blocks in a big chunk of code.

On Sat, Dec 19, 2015 at 11:37 AM, Adrian Cîrstei <adici...@gmail.com> wrote:
2 spaces also, here.


--
You received this message because you are subscribed to the Google Groups "elm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-dev+u...@googlegroups.com.

Desmond D'Souza

unread,
Dec 19, 2015, 12:13:51 PM12/19/15
to elm-dev
Definitely 2 spaces for me. I don't like how 4 spaces works out with let case and variants of parenthesis.

Dobes Vandermeer

unread,
Dec 19, 2015, 1:37:04 PM12/19/15
to elm-dev
I'm also a big fan of 2-space indent.

Alex Neslusan

unread,
Dec 19, 2015, 2:02:25 PM12/19/15
to elm-dev
I've always used 4 spaces, but 2 space looks ok too.

Richard Feldman

unread,
Dec 19, 2015, 3:05:58 PM12/19/15
to elm-dev

I prefer 4, but I can get behind 2 for the sake of uniformity. :)


--
You received this message because you are subscribed to the Google Groups "elm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-dev+u...@googlegroups.com.

Noah Hall

unread,
Dec 19, 2015, 3:13:37 PM12/19/15
to elm...@googlegroups.com
With Haskell-like syntax, I've always preferred 2. Readable names in
pure functional programming languages tend to be long, and indenting
by 2 instead of 4 helps there.

That being said, I have no strong feelings. As long it can be made to
keep indention a multiple of 2 (be it a fixed amount or
project-dependant) and consistent within a project, I don't mind.
> https://groups.google.com/d/msgid/elm-dev/CAORaYgbyb1n6NrG89%2BpbVSWKa3KZBH8HuNyTZ8uX6SisqSHt%3Dw%40mail.gmail.com.

gyz...@gmail.com

unread,
Dec 20, 2015, 12:59:35 AM12/20/15
to Noah Hall, elm...@googlegroups.com
I prefer 2 :)

Best regards,
Fedor Nezhivoi

Max Goldstein

unread,
Dec 20, 2015, 8:21:27 AM12/20/15
to elm-dev
Geez, does no one read that this was supposed to be a Google form?

Also, 2 please.

Murphy Randle

unread,
Dec 21, 2015, 4:18:12 AM12/21/15
to elm-dev
I vote for 2 as well. Thanks!

Dobes Vandermeer

unread,
Dec 21, 2015, 1:27:19 PM12/21/15
to elm-dev

I certainly missed the survey link! People if you replied to the thread go back and submit a survey response instead!


On Mon, Dec 21, 2015, 1:18 AM Murphy Randle <murphy...@gmail.com> wrote:
I vote for 2 as well. Thanks!

--
You received this message because you are subscribed to the Google Groups "elm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-dev+u...@googlegroups.com.

Richard Feldman

unread,
Dec 26, 2015, 5:47:33 PM12/26/15
to elm-dev
Just saw this survey of tabs, spaces, and 2 vs 4 in various languages across GitHub: https://ukupat.github.io/tabs-or-spaces/

Points of interest:
  • JS, CSS, and Haskell prefer 2 spaces to 4, but not overwhelmingly so (~60-70%)
  • No clear consensus among other languages
    • Ruby is 100% 2-space
    • Python is 92% 4-space
    • Go is 98% tabs (which is what gofmt outputs)
    • Others are varying degrees of all-over-the-map
  • Almost nobody uses anything but 2-space, 4-space, or tabs

Eric Ellis

unread,
Dec 27, 2015, 6:02:37 AM12/27/15
to elm-dev
Another vote for 2 spaces. The consistency between Javascript and Haskell is a huge win.

Cheers!

Corey Trampe

unread,
Dec 27, 2015, 10:49:12 AM12/27/15
to elm-dev
And Lua prefers 3 spaces :)

Tabs make the most sense to me, but above all I prefer consistency.


--
You received this message because you are subscribed to the Google Groups "elm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-dev+u...@googlegroups.com.

Dennis Reimann

unread,
Dec 28, 2015, 6:02:37 PM12/28/15
to elm-dev
I'd second that, just the other way round. But as you say: the main point is to have this unified. I came to this thread searching for an answer, as the styleguide does not mention indentation and uses 2 and 4 spaces (4 spaces is used most of the time though).

Cheers,
:Dennis

Aaron VonderHaar

unread,
Jan 3, 2016, 12:28:07 PM1/3/16
to elm...@googlegroups.com
Thanks, everyone.  elm-format alpha3 will switch to 2-space indentation.

As Dennis noted, some official docs are using 4-space indentation.  Before making a stable elm-format release, I want to make sure that elm-format matches the official style guide and the style of official examples (including example code in the core library documentation).  Can someone help with making sure those things get updated to have 2-space indentation?

Fedor Nezhivoi

unread,
Jan 3, 2016, 4:17:45 PM1/3/16
to elm...@googlegroups.com
Would it be configurable?

понедельник, 4 января 2016 г. пользователь Aaron VonderHaar написал:
To view this discussion on the web visit https://groups.google.com/d/msgid/elm-dev/CAMZecXk2N-GuqkMA49H_h1PN20EMSEchhWF7t2A_aU0oYQYztw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--
Best regards,
Fedor Nezhivoi.

Richard Feldman

unread,
Jan 3, 2016, 6:13:45 PM1/3/16
to elm...@googlegroups.com

No, nor should it be...a major selling point of a consistent formatting tool is that it can end debates on teams about which style to use.

Having only one available style is a feature!


Fedor Nezhivoi

unread,
Jan 4, 2016, 4:01:20 AM1/4/16
to elm...@googlegroups.com
It seems to me that after using Elm more I've found 4 spaces better :)

понедельник, 4 января 2016 г. пользователь Richard Feldman написал:
To view this discussion on the web visit https://groups.google.com/d/msgid/elm-dev/CAORaYgZe1REU3OLdQYznqqpbiXNxL3YWq14UOHeNy7Rd6CfYbw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Peter Damoc

unread,
Jan 4, 2016, 4:51:33 AM1/4/16
to elm...@googlegroups.com
There will always be preferences one way or the other but the advantages of consistency across multiple libraries far outweigh the small plus in comfort of the familiar tab-size. 
I agree with Richard here, having only one available style is a major feature because in the long run it significantly improves the readability of the source code.
I doubt that it will take anyone more than 2 weeks for their brain to get accustomed to the single style. 





For more options, visit https://groups.google.com/d/optout.



--

Max Goldstein

unread,
Jan 8, 2016, 11:29:09 AM1/8/16
to elm-dev
Here's an argument for two spaces not based on familiarity:

{ particle |
  position = particle.position + particle.velocity,
  velocity = particle.velocity + particle.acceleration }

By indenting the fields two spaces, they line up with the name of the record, which is offset two characters by the brace and the space. Contrast:

{ particle |
    position = particle.position + particle.velocity,
    velocity = particle.velocity + particle.acceleration }

{   particle |
    position = particle.position + particle.velocity,
    velocity = particle.velocity + particle.acceleration }

Janis Voigtländer

unread,
Jan 8, 2016, 11:32:36 AM1/8/16
to elm...@googlegroups.com
I like the second of your three versions best. It visually conveys that the updates happen "inside" the existing particle-record.
--
You received this message because you are subscribed to the Google Groups "elm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elm-dev/efa72e26-8333-4539-ad84-7592b7895e37%40googlegroups.com.

Richard Feldman

unread,
Jan 8, 2016, 11:36:15 AM1/8/16
to elm...@googlegroups.com

Yeah, agree with Janis - record updates are actually part of the reason I like 4-space better. ;)


Max Goldstein

unread,
Jan 8, 2016, 11:56:55 AM1/8/16
to elm-dev
Yeah, I noticed that too. But let's look at a version with trailing commas.

{ particle |

  position = particle.position + particle.velocity,
  velocity = particle.velocity + particle.acceleration,
}
 
This helps to distinguish the updated fields a bit better. With four spaces, it isn't bad, but it feels like overkill.

{ particle |
    position = particle.position + particle.velocity,
    velocity = particle.velocity + particle.acceleration,
}

d...@pisys.eu

unread,
Jan 12, 2016, 3:29:43 AM1/12/16
to elm-dev

To me this format conveys records updates even better (2 spaces):


{ particle
  |
position = particle.position + particle.velocity
  , velocity = particle.velocity + particle.acceleration
}

There are no trailing commas.

Esad Hajdarevic

unread,
Jan 12, 2016, 7:42:22 PM1/12/16
to elm-dev

{ particle
  |
position = particle.position + particle.velocity
  , velocity = particle.velocity + particle.acceleration
}

There are no trailing commas.

This is pretty cool, I think I'll adapt this style! It always bothered me that the current styleguide uses trailing commas for records.

Regarding the 2 vs 4 spaces, I think in Elm there's lot of nesting going in (I regularly have let .. in inside a case statement etc.) and with 4 spaces lot of lines don't fit in 80 (or even 120) columns.



Gábor Varga

unread,
Mar 2, 2016, 5:24:15 AM3/2/16
to elm-dev
I guess, I am somewhat late to the game. But I think it is the game's fault that it started too early :D

I am personally quite passionate about the 4 spaces indentation, I think long lines are not really an issue on the usual modern dev machines (assuming two 23-24" fullHD screens, fitting in 80 columns sounds a little bit 80s to me).

Even though I would generally agree with Richard's comment that "Having only one available style is a feature!", in this case I think we are a little too early to draw a final conclusion on such a detail about the formatting style.
Most of the people around here are (very) early adopters. 
We are still to see what formatting would work better for bigger teams, bigger apps, where people generally spend more time reading code then writing it.

Having completely different formatting styles would of course be a grave mistake. Having both 2 and 4 spaces on the other hand would not result in conceptually different formatting. 
So, I would, at least at this point leave this question open and make this configurable to see which approach prevails in the longer term.


Fedor Nezhivoi

unread,
Mar 2, 2016, 5:58:07 AM3/2/16
to Gábor Varga, elm...@googlegroups.com
After some time working with Elm I do also think 4 spaces is better decision according to the goal of increased core readability.

-- 
Fedor Nezhivoi
Sent with Airmail
--
You received this message because you are subscribed to the Google Groups "elm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-dev+u...@googlegroups.com.

Simon Hampton

unread,
Mar 15, 2016, 5:52:47 AM3/15/16
to elm-dev
I'm for 4 spaces
Reply all
Reply to author
Forward
0 new messages