roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.22k stars 307 forks source link

Why are tabs illegal? #2288

Open JanCVanB opened 2 years ago

JanCVanB commented 2 years ago

I'm personally ambivalent on tabs vs. spaces for indentation, but I'm surprised that Roc takes such a strong stance against tabs. It seems that tabs are illegal anywhere except string literals and application names:

Is this an intentional choice (to enforce consistency between developers? to enable the editor to use the tab key for features?) or is tab support on the roadmap?

dullbananas commented 2 years ago

Probably intentional. Roc is influenced by Elm, which is designed to make it easy to get started with a codebase that is new to you. It's why they banned custom infix operators, and maybe it's a reason to ban tabs.

Also, spaces are required by some disgusting code styles.

I think that Roc should require 4-space indentation because it's the default in many text editors. Roc should make it easy to get started without changing settings. For custom visual tab width, you will be able to use the Roc editor.

rvcas commented 2 years ago

https://github.com/ziglang/zig/issues/544

JanCVanB commented 2 years ago

ziglang/zig#544

Is the Roc team's approach to tabs identical to the Zig team's approach? It sounds like the Zig team plans to support tabs but doesn't at the moment. The accessibility advantages of tabs mentioned in that thread are very compelling, I've never considered them before.

rvcas commented 2 years ago

I just linked it because it was a very lengthy discussion with some cool information.

JanCVanB commented 2 years ago

I agree, very useful stuff!

booniepepper commented 2 years ago

The un-answerable question is: How many spaces is a tab?

(Your editor says 4, my editor says 2, a browser says 8)

I think there are some sane ways to solve it:

  1. A single source file must either use only spaces or use only tabs
    • Only an indentation rule. This would mean a source file could match ^\t+ or ^ + but never both.
  2. Only spaces
    • A formatter can expand tabs (maybe with a flag)
    • The editor can translate a press of the tab key to spaces
    • Any future IDE plugins do the same in a .roc file