Skip to content
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
Closed

Allowing tabs for indentation #1370

drathier opened this issue May 12, 2016 · 14 comments

Comments

@drathier
Copy link

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
Copy link
Contributor

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

@jvoigtlaender
Copy link
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
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

Sure, but

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

is valid with tabs, and follows the style guide

@jvoigtlaender
Copy link
Contributor

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
Copy link
Contributor

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

@LiamGoodacre
Copy link

@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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

I've said what I have to say. 😄

@drathier
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants