inaka / erlang_guidelines

Inaka's Erlang Coding Guidelines
Apache License 2.0
620 stars 122 forks source link

Spaces per indentation #52

Closed jpuigm closed 9 years ago

jpuigm commented 9 years ago

Hi,

I just want to make an observation about your suggested guidelines. I want to make clear that I am very well aware this repo only contains guidelines, and not rules. I also understand that inaka can develop code following whatever you guys consider the best. That said,

Aproximately 90% of the Erlang open source code out there is indented with 4 spaces (even Erlang itself):

... to name a few. The only trending project that I know of, using 2-space indentation is cowboy (and all ninenines repos, of course).

There is a clear agreement when it comes to use spaces over tabs, but it would be ideal if we all agree on a number of spaces per indented line, to make our lifes easier when it comes to contributing to the open source community.

Some references:

My two cents.

elbrujohalcon commented 9 years ago

@jpuigm I understand your idea, but keep in mind that even just choosing a number for the amount of indentation spaces will not be enough. For instance, how should you indent the following code: Is it…

MyFun =
    fun({this, This}) -> do_something_with(This);
       ({that, That}) -> do_something_with(That)
    end.

…or…

MyFun =
    fun ({this, This}) -> do_something_with(This);
        ({that, That}) -> do_something_with(That)
    end.

…maybe…

MyFun =
    fun ({this, This}) -> do_something_with(This)
      ; ({that, That}) -> do_something_with(That)
    end.

…or what about…

MyFun =
    fun
        ({this, This}) -> do_something_with(This);
        ({that, That}) -> do_something_with(That)
    end.

…you can even argue that it should be…

MyFun =
    fun({this, This}) ->
        do_something_with(This);
       ({that, That}) ->
        do_something_with(That)
    end.

?

elbrujohalcon commented 9 years ago

In the end you'll most likely never get to a shared community standard on this subject. I would not aim for such thing. Instead, I would be very happy to get to a per-project standard, i.e. within a single project, all modules should be indentend in the same way.

jpuigm commented 9 years ago

To respond to your first question, I think "that behavior" is determined by erlang-mode indentation rules in emacs (haven't used other editors with Erlang). I would personally format it as the first option, but again that's personal.

I think the logic emacs-mode follows is to use as many spaces per indentation defined for new lines after ->, commas, or semicollons,.. but in this case, it would indent it to the position of the left parenthesis. Again, I don't know what the default behavior is in other IDEs, editors, or modes.

When it comes to the second comment you posted, I agree with what you said, there's a definite need within a single project to follow the same standards, but the more we all align with the rest of the open source projects, the better for the community. I was just simply dropping my observation out there.