New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing tabs for indentation #1370

Closed
drathier opened this Issue May 12, 2016 · 14 comments

Comments

Projects
None yet
4 participants
@drathier

drathier commented May 12, 2016

I think it's time to look at the tabs vs spaces debate. I currently do not see any reason to not allow tabs, as long as each file is consistent. The compiler could error out if a file mixes tabs and spaces.

The main argument for using tabs would be that some people prefer 2-space indentation, while others prefer 4 (or 8, 6 or 3). There's no reason to force everyone else to use the same indentation level as you are using. Setting the tab width in your editor of choice should be easy enough.

I'm assuming that the influence Haskell has on Elm is the reason Elm forces spaces for indentation. Haskell requires column alignment in the syntax, so varying tab width is dangerous to a haskell program. Elm does not.

The main benefit of using spaces is column alignment, but that's against the style guide anyway.

@jvoigtlaender

This comment has been minimized.

Contributor

jvoigtlaender commented May 12, 2016

What makes you believe that Elm does not require column alignment?

@jvoigtlaender

This comment has been minimized.

Contributor

jvoigtlaender commented May 12, 2016

The following program is legal Elm:

import Html

main = let a = "a"
           b = "b"
       in Html.text (a ++ b)

The following program is not legal Elm:

import Html

main = let a = "a"
            b = "b"
       in Html.text (a ++ b)

Doesn't that destroy your argument?

(Edited the two programs slightly to make the point even clearer.)

@drathier

This comment has been minimized.

drathier commented May 12, 2016

Sorry, I was unclear. What I ment was, you don't have to align by column like in Haskell:

type Boolean = Literal Bool
             | Not Boolean
             | And Boolean Boolean
             | Or Boolean Boolean

It is more like indentation in Python. Thus, tabs work as indentation.

@jvoigtlaender

This comment has been minimized.

Contributor

jvoigtlaender commented May 12, 2016

Thus, tabs work as indentation.

No, they don't, as my example shows:

import Html

main = let a = "a"
tab-tab-tab b = "b"
       in Html.text (a ++ b)

Depending on what the tab-size is, this program might or might not be correct Elm.

@drathier

This comment has been minimized.

drathier commented May 12, 2016

Sure, but

type Boolean
    = Literal Bool
    | Not Boolean
    | And Boolean Boolean
    | Or Boolean Boolean

is valid with tabs, and follows the style guide

@jvoigtlaender

This comment has been minimized.

Contributor

jvoigtlaender commented May 12, 2016

And how does that help? The following is valid Haskell:

data Boolean = Literal Bool
           | Not Boolean
                | And Boolean Boolean
             | Or Boolean Boolean

Does that mean Haskell has reason to eschew tab characters?

@jvoigtlaender

This comment has been minimized.

Contributor

jvoigtlaender commented May 12, 2016

Sorry, meant "Does that mean Haskell has no reason to eschew tab characters?" in the previous comment.

@LiamGoodacre

This comment has been minimized.

LiamGoodacre commented May 12, 2016

@drathier your latest example is the only one so far which is actually using indentation, the rest are using spacing - which is a different thing and shouldn't use tabs.

@jvoigtlaender

This comment has been minimized.

Contributor

jvoigtlaender commented May 12, 2016

Anyway, I'll defer to @evancz. I'm pretty sure the fact that

import Html

main = let a = "a"
           b = "b"
       in Html.text (a ++ b)

is a legal Elm program, while

import Html

main = let a = "a"
            b = "b"
       in Html.text (a ++ b)

is not a legal Elm program means that the compiler should not accept tabs (because what might look like a legal Elm program in some editor with some set tab size might not anymore look like a legal Elm program in some editor with another set tab size).

@drathier

This comment has been minimized.

drathier commented May 12, 2016

But you can just add a line break, which makes tabs ok again:

import Html

main = 
    let 
        a = "a"
        b = "b"
    in Html.text (a ++ b)
main = 
    let 
        a = "a"
        b = "b"
    in 
        Html.text (a ++ b)
main =  let 
        a = "a"
        b = "b"
    in Html.text (a ++ b)
@jvoigtlaender

This comment has been minimized.

Contributor

jvoigtlaender commented May 12, 2016

I've said what I have to say. 😄

@drathier

This comment has been minimized.

drathier commented May 12, 2016

This style guide uses C-like (Go-like) syntax formatting that works great with tabs.

I'm not forcing you to change, I just don't want to be forced myself, or forced to force others :)

@drathier

This comment has been minimized.

drathier commented May 12, 2016

Pretty sure that could be one limitation when using tabs; it should be valid regardless of tab width. Shouldn't be too hard for the compiler/lexer to check.

@evancz

This comment has been minimized.

Member

evancz commented May 12, 2016

I'm aware of this idea. This repo is for tracking bugs with the compiler. If you have changes, it's best to discuss them in one of the community forums and build support. I follow this stuff.

@evancz evancz closed this May 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment